Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface WaypointSettings {
showNonMarkdownFiles: boolean;
debugLogging: boolean;
useWikiLinks: boolean;
useObsidianLinksInLandmarkSubtree: boolean;
useFrontMatterTitle: boolean;
showEnclosingNote: boolean;
folderNoteType: string;
Expand All @@ -34,6 +35,7 @@ const DEFAULT_SETTINGS: WaypointSettings = {
showNonMarkdownFiles: false,
debugLogging: false,
useWikiLinks: true,
useObsidianLinksInLandmarkSubtree: false,
useFrontMatterTitle: false,
showEnclosingNote: false,
folderNoteType: FolderNoteType.InsideFolder,
Expand Down Expand Up @@ -268,9 +270,10 @@ export default class Waypoint extends Plugin {
* @param node The current node in our recursive descent
* @param indentLevel How many levels of indentation to draw
* @param topLevel Whether this is the top level of the tree or not
* @param landmarkObsidianLink Whether to use Obsidian links for files in Landmark "subtrees"
* @returns The string representation of the tree, or null if the node is not a file or folder
*/
async getFileTreeRepresentation(rootNode: TFolder, node: TAbstractFile, indentLevel: number, topLevel = false): Promise<string> | null {
async getFileTreeRepresentation(rootNode: TFolder, node: TAbstractFile, indentLevel: number, topLevel = false, landmarkObsidianLink = false): Promise<string> | null {
const indent = this.settings.useSpaces ? " ".repeat(this.settings.numSpaces) : " ";
const bullet = indent.repeat(indentLevel) + "-";
if (!(node instanceof TFile) && !(node instanceof TFolder)) {
Expand All @@ -297,6 +300,13 @@ export default class Waypoint extends Plugin {
}
// Print the file name
if (node.extension == "md") {
if(landmarkObsidianLink) { // can only be set true if setting enabled
if (title) {
return `${bullet} [${title}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, node)})`;
} else {
return `${bullet} [${node.basename}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, node)})`;
}
}
if (this.settings.useWikiLinks) {
if (title) {
return `${bullet} [[${node.basename}|${title}]]`;
Expand Down Expand Up @@ -329,7 +339,9 @@ export default class Waypoint extends Plugin {
folderNote = this.app.vault.getAbstractFileByPath(node.parent.path + "/" + node.name + ".md");
}
if (folderNote instanceof TFile) {
if (this.settings.useWikiLinks) {
if (landmarkObsidianLink) {
text = `${bullet} **[${folderNote.basename}](obsidian://open?vault=${this.app.vault.getName()}&file=${this.getEncodedUri(rootNode, folderNote)})**`;
} else if (this.settings.useWikiLinks) {
text = `${bullet} **[[${folderNote.basename}]]**`;
} else {
text = `${bullet} **[${folderNote.basename}](${this.getEncodedUri(rootNode, folderNote)})**`;
Expand All @@ -342,6 +354,9 @@ export default class Waypoint extends Plugin {
if (content.includes(Waypoint.BEGIN_WAYPOINT) || content.includes(this.settings.waypointFlag)) {
return text;
}
if (this.settings.useObsidianLinksInLandmarkSubtree && (content.includes(Waypoint.BEGIN_LANDMARK) || content.includes(this.settings.landmarkFlag))) {
landmarkObsidianLink = true;
}
}
}
}
Expand Down Expand Up @@ -371,7 +386,7 @@ export default class Waypoint extends Plugin {
}
if (children.length > 0) {
const nextIndentLevel = topLevel && !this.settings.showEnclosingNote ? indentLevel : indentLevel + 1;
text += (text === "" ? "" : "\n") + (await Promise.all(children.map((child) => this.getFileTreeRepresentation(rootNode, child, nextIndentLevel)))).filter(Boolean).join("\n");
text += (text === "" ? "" : "\n") + (await Promise.all(children.map((child) => this.getFileTreeRepresentation(rootNode, child, nextIndentLevel, false, landmarkObsidianLink)))).filter(Boolean).join("\n");
}
return text;
}
Expand Down Expand Up @@ -584,6 +599,18 @@ class WaypointSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Generate Obsidian Links for Landmark Subdirectories")
.setDesc(`If enabled, links will be generated like [My Page](obsidian://open?vault=${this.app.vault.getName()}&file=./Folder/My%20Page.md) for files in Landmark Subdirectories.
The file with the Landmark itself will respect the 'Use WikiLinks' Setting.
Access the files the same, but the graph is less cluttered.
`)
.addToggle((toggle) =>
toggle.setValue(this.plugin.settings.useObsidianLinksInLandmarkSubtree).onChange(async (value) => {
this.plugin.settings.useObsidianLinksInLandmarkSubtree = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Use Title Property")
.setDesc("If enabled, links will use the \"title\" frontmatter property for the displayed text (if it exists).")
Expand Down