Skip to content

Commit

Permalink
Merge pull request #4 from matthewturk/default-file
Browse files Browse the repository at this point in the history
Add default-file settings.
  • Loading branch information
matthewturk authored Mar 3, 2024
2 parents fcb83f0 + 8c8b97d commit ce543d0
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ file.

- [ ] Add support for [metadatamenu](https://github.com/mdelobelle/metadatamenu) `fileClass`es to apply `sidecar-panel` attributes across queries.
- [x] Add per-tag support, so that not all files have to have their properties modified to benefit.
- [x] Add a default sidecar file and allow it to always be used even if others are to be applied.
- [ ] Better support changes in properties and sidecar files for open files.

## Version History

- 0.2.3 -- First release in the plugin list!
- 0.2.4 -- Add a default panel file and a toggle to always apply it.

## License

This template is available under the [MIT License](LICENSE). Feel free to modify
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Add a context-dependent sidecar panel.",
"author": "Matthew Turk",
"authorUrl": "https://matthewturk.github.io/",
"version": "0.2.3",
"version": "0.2.4",
"minAppVersion": "0.15.0",
"isDesktopOnly": false
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sidecar-panel",
"private": true,
"version": "0.2.3",
"version": "0.2.4",
"main": "main.js",
"type": "module",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion public/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"0.2.0": "0.15.0",
"0.2.1": "0.15.0",
"0.2.2": "0.15.0",
"0.2.3": "0.15.0"
"0.2.3": "0.15.0",
"0.2.4": "0.15.0"
}
14 changes: 14 additions & 0 deletions src/components/ContextualSidecarPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
if (cache) {
const fileTags = getAllTags(cache) || [];
let sidecarPanelMarkdown: string[] = [];
// If the default panel is set, and the file doesn't have a sidecar-panel, or the alwaysUseDefaultPanel is set, then use the default panel.
if ($contextualSidecarPanelSetting.defaultPanel !== "") {
if (
$contextualSidecarPanelSetting.alwaysUseDefaultPanel ||
!(cache.frontmatter && cache.frontmatter["sidecar-panel"])
) {
sidecarPanelMarkdown.push(
await readSidecarPanel(
$contextualSidecarPanelSetting.defaultPanel,
"/"
)
);
}
}
for (const { tag, panel } of $contextualSidecarPanelSetting.tagMaps) {
// I don't like that this is quadratic. But, it shouldn't be called that often. Right?
const normalizedTag = tag.startsWith("#") ? tag.slice(1) : tag;
Expand Down
27 changes: 27 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@ class ContextualSidecarPanelSettingTab extends PluginSettingTab {

// Some of this logic was inspired by the bwydoogh/obsidian-force-view-mode-of-note plugin.

new Setting(this.containerEl)
.setName("Default Panel")
.setDesc(
"Specify a default sidebar panel file, if none is set in the frontmatter."
)
.addSearch((cb) => {
cb.setPlaceholder("Example: daily-note-panel")
.setValue(this.plugin.settings.defaultPanel)
.onChange(async (newPanel) => {
this.plugin.settings.defaultPanel = newPanel;
await this.plugin.saveSettings();
});
});
new Setting(this.containerEl)
.setName("Always use default panel?")
.setDesc(
"If checked, the default panel will be used for all files, even if one is specified in the frontmatter."
)
.addToggle((cb) => {
cb.setValue(this.plugin.settings.alwaysUseDefaultPanel).onChange(
async (value) => {
this.plugin.settings.alwaysUseDefaultPanel = value;
await this.plugin.saveSettings();
}
);
});

new Setting(this.containerEl).setDesc(
"Specify a sidecar panel for all files with a given tag. These will be applied in order."
);
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export interface ContextualSidecarPanelSettings {
defaultPanel: string;
alwaysUseDefaultPanel: boolean;
tagMaps: { tag: string; panel: string }[];
}
export const DEFAULT_SETTINGS: ContextualSidecarPanelSettings = {
defaultPanel: "",
alwaysUseDefaultPanel: false,
tagMaps: [],
};

0 comments on commit ce543d0

Please sign in to comment.