mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
When there isn't a active file it defaults to the default settings
This commit is contained in:
parent
81d7236a1e
commit
b1e03cd36b
2 changed files with 15 additions and 23 deletions
|
|
@ -464,8 +464,9 @@ export function getCodeBlockEndLine(text: string, startLine: number, count = 1)
|
|||
return line;
|
||||
}
|
||||
|
||||
export async function getOverviews(plugin: FolderNotesPlugin, file: TFile) {
|
||||
export async function getOverviews(plugin: FolderNotesPlugin, file: TFile | null) {
|
||||
// is an object with unkown keys
|
||||
if (!file) return [];
|
||||
const overviews: { [key: string]: string }[] = [];
|
||||
const content = await plugin.app.vault.read(file);
|
||||
if (!content) return overviews;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export class FolderOverviewView extends ItemView {
|
|||
ctx?: MarkdownPostProcessorContext,
|
||||
file?: TFile | null
|
||||
) {
|
||||
|
||||
|
||||
this.contentEl = contentEl;
|
||||
this.yaml = yaml;
|
||||
this.defaultSettings = defaultSettings;
|
||||
|
|
@ -67,17 +67,6 @@ export class FolderOverviewView extends ItemView {
|
|||
}
|
||||
|
||||
const activeFile = plugin.app.workspace.getActiveFile();
|
||||
if (!activeFile) {
|
||||
let msg = contentEl.querySelector('.fn-no-file-msg');
|
||||
if (!msg) {
|
||||
msg = contentEl.createEl('p', { cls: 'fn-no-file-msg' });
|
||||
}
|
||||
msg.textContent = 'No active file found';
|
||||
return;
|
||||
} else {
|
||||
const msg = contentEl.querySelector('.fn-no-file-msg');
|
||||
if (msg) msg.remove();
|
||||
}
|
||||
|
||||
const overviews = await getOverviews(plugin, activeFile);
|
||||
|
||||
|
|
@ -93,16 +82,18 @@ export class FolderOverviewView extends ItemView {
|
|||
.setName('Select overview')
|
||||
.setClass('fn-select-overview-setting')
|
||||
.addDropdown((cb) => {
|
||||
const options = overviews.reduce((acc, overview) => {
|
||||
acc[overview.id] = parseOverviewTitle(
|
||||
overview as any as yamlSettings,
|
||||
plugin,
|
||||
activeFile.parent
|
||||
);
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
|
||||
cb.addOptions(options);
|
||||
if (activeFile) {
|
||||
const options = overviews.reduce((acc, overview) => {
|
||||
acc[overview.id] = parseOverviewTitle(
|
||||
overview as any as yamlSettings,
|
||||
plugin,
|
||||
activeFile.parent
|
||||
);
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
cb.addOptions(options);
|
||||
}
|
||||
|
||||
cb.addOption('default', 'Default');
|
||||
cb.setValue(yaml?.id ?? 'default');
|
||||
console.log(yaml);
|
||||
|
|
|
|||
Loading…
Reference in a new issue