#156 - improved support for index-note-based folder notes: PUT ON HOLD
- turned out to be not so trivial with one challenging place - PUT ON HOLD - added inline annotations with !!! (intentionally breaking the TS syntax)
This commit is contained in:
parent
e66d7be9d3
commit
605d5026a6
|
@ -466,12 +466,18 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
|
|||
case CustomSortGroupType.HasMetadataField:
|
||||
if (group.withMetadataFieldName) {
|
||||
if (ctx?._mCache) {
|
||||
// For folders - scan metadata of 'folder note'
|
||||
// For folders - scan metadata of 'folder note' in same-name-as-folder mode
|
||||
const notePathToScan: string = aFile ? entry.path : `${entry.path}/${entry.name}.md`
|
||||
const frontMatterCache: FrontMatterCache | undefined = ctx._mCache.getCache(notePathToScan)?.frontmatter
|
||||
const hasMetadata: boolean | undefined = frontMatterCache?.hasOwnProperty(group.withMetadataFieldName)
|
||||
// For folders, if index-based folder note mode, scan the index file, giving it the priority
|
||||
!!! Non trivial part: - need to know the folder-index name, this is hidden
|
||||
!!! in plugin settings, not exposed - refactoring is a must.
|
||||
if (aFolder && ctx?.plugin?.s) {
|
||||
|
||||
if (hasMetadata) {
|
||||
}
|
||||
|
||||
if (hasMetadata || folderIndexNoteHasMetadata) {
|
||||
determined = true
|
||||
}
|
||||
}
|
||||
|
@ -554,6 +560,12 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus
|
|||
if (isPrimaryOrderByMetadata || isSecondaryOrderByMetadata || isDerivedPrimaryByMetadata || isDerivedSecondaryByMetadata) {
|
||||
if (ctx?._mCache) {
|
||||
// For folders - scan metadata of 'folder note'
|
||||
// and if index-based folder note mode, scan the index file, giving it the priority
|
||||
!!! Non trivial part: - need to know the folder-index-note name, this is hidden
|
||||
!!! in plugin settings, not exposed - refactoring is a must.
|
||||
!!!
|
||||
!!! Then challenging part - how to easily rewrite the below code to handle scanning
|
||||
!!! of two frontMatterCaches for folders and give the priority to folder-index-note based cache, if configured
|
||||
const notePathToScan: string = aFile ? entry.path : `${entry.path}/${entry.name}.md`
|
||||
const frontMatterCache: FrontMatterCache | undefined = ctx._mCache.getCache(notePathToScan)?.frontmatter
|
||||
if (isPrimaryOrderByMetadata) metadataValueToSortBy = frontMatterCache?.[group?.byMetadataField || group?.withMetadataFieldName || DEFAULT_METADATA_FIELD_FOR_SORTING]
|
||||
|
|
|
@ -125,10 +125,14 @@ export default class CustomSortPlugin extends Plugin {
|
|||
if (aFile.name === SORTSPEC_FILE_NAME || // file name == sortspec.md ?
|
||||
aFile.name === `${SORTSPEC_FILE_NAME}.md` || // file name == sortspec.md.md ?
|
||||
aFile.basename === parent.name || // Folder Note mode: inside folder, same name
|
||||
|
||||
aFile.basename === this.settings.additionalSortspecFile || // when user configured _about_
|
||||
aFile.name === this.settings.additionalSortspecFile || // when user configured _about_.md
|
||||
aFile.path === this.settings.additionalSortspecFile || // when user configured Inbox/sort.md
|
||||
aFile.path === `${this.settings.additionalSortspecFile}.md` // when user configured Inbox/sort
|
||||
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
|
||||
) {
|
||||
const sortingSpecTxt: string = mCache.getCache(aFile.path)?.frontmatter?.[SORTINGSPEC_YAML_KEY]
|
||||
// Warning: newer Obsidian versions can return objects as well, hence the explicit check for string value
|
||||
|
@ -713,7 +717,7 @@ export default class CustomSortPlugin extends Plugin {
|
|||
const data: any = await this.loadData() || {}
|
||||
const isFreshInstall: boolean = Object.keys(data).length === 0
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, data);
|
||||
if (requireApiVersion('1.2.0')) {
|
||||
if (requireApiVersion('1.2.0') && isFreshInstall) {
|
||||
this.settings = Object.assign(this.settings, DEFAULT_SETTING_FOR_1_2_0_UP)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import CustomSortPlugin from "./main";
|
|||
|
||||
export interface CustomSortPluginSettings {
|
||||
additionalSortspecFile: string
|
||||
indexNoteNameForFolderNotes: string
|
||||
suspended: boolean
|
||||
statusBarEntryEnabled: boolean
|
||||
notificationsEnabled: boolean
|
||||
|
@ -16,6 +17,7 @@ export interface CustomSortPluginSettings {
|
|||
|
||||
export const DEFAULT_SETTINGS: CustomSortPluginSettings = {
|
||||
additionalSortspecFile: '',
|
||||
indexNoteNameForFolderNotes: '',
|
||||
suspended: true, // if false by default, it would be hard to handle the auto-parse after plugin install
|
||||
statusBarEntryEnabled: true,
|
||||
notificationsEnabled: true,
|
||||
|
@ -52,16 +54,10 @@ export class CustomSortSettingTab extends PluginSettingTab {
|
|||
// containerEl.createEl('h2', {text: 'Settings for Custom File Explorer Sorting Plugin'});
|
||||
|
||||
const additionalSortspecFileDescr: DocumentFragment = sanitizeHTMLToDom(
|
||||
'A note name or note path to scan (YAML frontmatter) for sorting specification in addition to the `sortspec` notes and Folder Notes<sup><b>*</b></sup>.'
|
||||
'A note name or note path to scan (YAML frontmatter) for sorting specification in addition to the `sortspec` notes and Folder Notes.'
|
||||
+ '<br>'
|
||||
+ ' The `.md` filename suffix is optional.'
|
||||
+ '<p><b>(*)</b> if you employ the <i>Index-File based</i> approach to folder notes (as documented in '
|
||||
+ '<a href="https://github.com/aidenlx/alx-folder-note/wiki/folder-note-pref"'
|
||||
+ '>Aidenlx Folder Note preferences</a>'
|
||||
+ ') you can enter here the index note name, e.g. <b>_about_</b>'
|
||||
+ '<br>'
|
||||
+ 'The <i>Inside Folder, with Same Name Recommended</i> mode of Folder Notes is handled automatically, no additional configuration needed.'
|
||||
+ '</p>'
|
||||
+ '<p>NOTE: After updating this setting remember to refresh the custom sorting via clicking on the ribbon icon or via the <b>sort-on</b> command'
|
||||
+ ' or by restarting Obsidian or reloading the vault</p>'
|
||||
)
|
||||
|
@ -70,13 +66,40 @@ export class CustomSortSettingTab extends PluginSettingTab {
|
|||
.setName('Path or name of additional note(s) containing sorting specification')
|
||||
.setDesc(additionalSortspecFileDescr)
|
||||
.addText(text => text
|
||||
.setPlaceholder('e.g. _about_')
|
||||
.setPlaceholder('e.g. sorting-configuration')
|
||||
.setValue(this.plugin.settings.additionalSortspecFile)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.additionalSortspecFile = value.trim() ? normalizePath(value) : '';
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
const indexNoteNameDescr: DocumentFragment = sanitizeHTMLToDom(
|
||||
'If you employ the <i>Index-File based</i> approach to folder notes (as documented in '
|
||||
+ '<a href="https://github.com/aidenlx/alx-folder-note/wiki/folder-note-pref"'
|
||||
+ '>Aidenlx Folder Note preferences</a>'
|
||||
+ ') enter here the index note name, e.g. <b>_about_</b> or <b>index</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.'
|
||||
+ '<br></br>'
|
||||
+ 'The <i>Inside Folder, with Same Name Recommended</i> mode of Folder Notes is handled automatically, no additional configuration needed.'
|
||||
+ '</p>'
|
||||
+ '<p>NOTE: After updating this setting remember to refresh the custom sorting via clicking on the ribbon icon or via the <b>sort-on</b> command'
|
||||
+ ' or by restarting Obsidian or reloading the vault</p>'
|
||||
)
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Name of index note (Folder Notes support)')
|
||||
.setDesc(indexNoteNameDescr)
|
||||
.addText(text => text
|
||||
.setPlaceholder('e.g. _about_ or index')
|
||||
.setValue(this.plugin.settings.indexNoteNameForFolderNotes)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.indexNoteNameForFolderNotes = value.trim() ? normalizePath(value) : '';
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Enable the status bar entry')
|
||||
.setDesc('The status bar entry shows the label `Custom sort:ON` or `Custom sort:OFF`, representing the current state of the plugin.')
|
||||
|
|
Loading…
Reference in New Issue