diff --git a/README.md b/README.md index 66f10e5..abe8d05 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ Waypoint is an Obsidian plugin that automatically generates tables of contents/M - **Permanent and portable** - Unlike other plugins, Waypoints are generated and saved as real markdown text within your folder notes. If you decide to switch to a different markdown editor that supports [[links]], all of your tables of contents will still be usable. - Note that the Waypoint plugin currently only works with Obsidian, so moving files around in another editor will cause your waypoints to be out-of-date. +- **Support Johnny Decimal Folder Structure** + - [Johnny Decimal](https://johnnydecimal.com/) folder structure depends mainly on numbering your folders. So your folder name could start with numbers. At the same time, you don't like adding this number to the Folder Note name. + - This feature allows to have your Parent folder numbered, while your Folder Note doesn't not. ## How To Use diff --git a/main.ts b/main.ts index def93e6..1f9b790 100644 --- a/main.ts +++ b/main.ts @@ -13,7 +13,8 @@ interface WaypointSettings { debugLogging: boolean, useWikiLinks: boolean, showEnclosingNote: boolean, - folderNoteType: string + folderNoteType: string, + useJohnnyDecimal: boolean } const DEFAULT_SETTINGS: WaypointSettings = { @@ -24,7 +25,8 @@ const DEFAULT_SETTINGS: WaypointSettings = { debugLogging: false, useWikiLinks: true, showEnclosingNote: false, - folderNoteType: FolderNoteType.InsideFolder + folderNoteType: FolderNoteType.InsideFolder, + useJohnnyDecimal: false } export default class Waypoint extends Plugin { @@ -102,7 +104,16 @@ export default class Waypoint extends Plugin { isFolderNote(file: TFile): boolean { if (this.settings.folderNoteType === FolderNoteType.InsideFolder) { - return file.basename == file.parent.name; + var fileParentFolder = file.parent.name; + var fileName = file.basename; + if (fileParentFolder == fileName){ + return true; + } + else { + // Get parent name without Johnny Decimal + fileParentFolder = this.removeJohnnyDecimal(fileParentFolder) + } + return fileName == fileParentFolder; } else if (this.settings.folderNoteType === FolderNoteType.OutsideFolder) { if (file.parent) { return this.app.vault.getAbstractFileByPath(this.getCleanParentPath(file) + file.basename) instanceof TFolder; @@ -242,7 +253,7 @@ export default class Waypoint extends Plugin { }); if (!this.settings.showFolderNotes) { if (this.settings.folderNoteType === FolderNoteType.InsideFolder) { - children = children.filter(child => this.settings.showFolderNotes || child.name !== node.name + ".md"); + children = children.filter((child) => this.settings.showFolderNotes || child.name !== (this.settings.useJohnnyDecimal ? this.removeJohnnyDecimal(node.name) : node.name) + ".md"); } else if (this.settings.folderNoteType === FolderNoteType.OutsideFolder) { const folderNames = new Set(); for (const element of children) { @@ -373,6 +384,14 @@ export default class Waypoint extends Plugin { async saveSettings() { await this.saveData(this.settings); } + removeJohnnyDecimal(fileParentFolder: string) { + if (/^\d\d\.\d\d\s/.test(fileParentFolder)){ + return fileParentFolder.substring(6) + } + else if (/^\d\d\s/.test(fileParentFolder)){ + return fileParentFolder.substring(3) + } + } } class WaypointSettingsTab extends PluginSettingTab {