Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/custom-sort/custom-sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
RegExpSpec
} from "./custom-sort-types";
import {
isDefined
isDefined, resolveIndexFileName
} from "../utils/utils";
import {
expandMacros
Expand Down Expand Up @@ -480,7 +480,8 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
if (aFolder) {
const indexNoteBasename = ctx?.plugin?.indexNoteBasename()
if (indexNoteBasename) {
frontMatterCache = ctx._mCache.getCache(`${entry.path}/${indexNoteBasename}.md`)?.frontmatter
let resolvedIndexNoteBasename = resolveIndexFileName(indexNoteBasename, entry.parent?.name||'')
frontMatterCache = ctx._mCache.getCache(`${entry.path}/${resolvedIndexNoteBasename}.md`)?.frontmatter
hasMetadata = hasMetadata || frontMatterCache?.hasOwnProperty(group.withMetadataFieldName)
}
}
Expand Down Expand Up @@ -567,7 +568,8 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
if (aFolder) {
const indexNoteBasename = ctx?.plugin?.indexNoteBasename()
if (indexNoteBasename) {
prioFrontMatterCache = ctx._mCache.getCache(`${entry.path}/${indexNoteBasename}.md`)?.frontmatter
let resolvedIndexNoteBasename = resolveIndexFileName(indexNoteBasename, entry.parent?.name||'')
prioFrontMatterCache = ctx._mCache.getCache(`${entry.path}/${resolvedIndexNoteBasename}.md`)?.frontmatter
}
}
if (isPrimaryOrderByMetadata) metadataValueToSortBy =
Expand Down
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
} from "./utils/ObsidianIconFolderPluginSignature";
import {
extractBasename,
lastPathComponent,
lastPathComponent, resolveIndexFileName,
ValueOrError,
} from "./utils/utils";
import {
Expand Down Expand Up @@ -133,6 +133,11 @@ export default class CustomSortPlugin
if (file instanceof TFile) {
const aFile: TFile = file as TFile
const parent: TFolder = aFile.parent!
let resolvedIndexNoteNameForFolderNotes = ''
if (this.settings.indexNoteNameForFolderNotes) {
resolvedIndexNoteNameForFolderNotes = resolveIndexFileName(this.settings.indexNoteNameForFolderNotes, parent.name)
}

// Read sorting spec from three sources of equal priority:
// - files with designated predefined name
// - files with the same name as parent folders (aka folder notes), e.g.: References/References.md
Expand All @@ -148,8 +153,10 @@ export default class CustomSortPlugin
aFile.path === this.settings.additionalSortspecFile || // when user configured Inbox/sort.md
aFile.path === `${this.settings.additionalSortspecFile}.md` || // when user configured Inbox/sort

aFile.basename === this.settings.indexNoteNameForFolderNotes || // when user configured as index
aFile.name === this.settings.indexNoteNameForFolderNotes // when user configured as index.md
(resolvedIndexNoteNameForFolderNotes && (
aFile.basename === resolvedIndexNoteNameForFolderNotes || // when user configured as index
aFile.name === resolvedIndexNoteNameForFolderNotes // when user configured as index.md
))
) {
const sortingSpecTxt: string|undefined = mCache.getCache(aFile.path)?.frontmatter?.[SORTINGSPEC_YAML_KEY]
// Warning: newer Obsidian versions can return objects as well, hence the explicit check for string value
Expand Down
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export class CustomSortSettingTab extends PluginSettingTab {
+ '>Aidenlx Folder Note preferences</a>'
+ ') enter here the index note name, e.g. <b>_about_</b> or <b>index</b>'
+ '<br>'
+ ' The template {{parent-folder-name}} is supported, e.g. <b>_{{parent-folder-name}}</b>'
+ '<br>'
+ ' The `.md` filename suffix is optional.'
+ '<br>'
+ 'This will tell the plugin to read sorting specs and also folders metadata from these files.'
Expand All @@ -125,7 +127,7 @@ export class CustomSortSettingTab extends PluginSettingTab {
.setName('Name of index note (Folder Notes support)')
.setDesc(indexNoteNameDescr)
.addText(text => text
.setPlaceholder('e.g. _about_ or index')
.setPlaceholder('e.g. _about_ or index or _{{parent-folder-name}}')
.setValue(this.plugin.settings.indexNoteNameForFolderNotes)
.onChange(async (value) => {
this.plugin.settings.indexNoteNameForFolderNotes = value.trim() ? normalizePath(value) : '';
Expand Down
8 changes: 8 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export function extractBasename (configEntry: string | undefined): string | unde
}
}

export function resolveIndexFileName(indexFileName: string, parentFolderName: string): string {
if (parentFolderName && parentFolderName !== '/') {
return indexFileName.replace('{{parent-folder-name}}', parentFolderName)
} else {
return indexFileName
}
}

export class ValueOrError<V,E> {
constructor(private value?: V, private error?: E) {
if (value) this.error = undefined
Expand Down
Loading