diff --git a/src/custom-sort/custom-sort-types.ts b/src/custom-sort/custom-sort-types.ts index 05d86e7..0612b00 100644 --- a/src/custom-sort/custom-sort-types.ts +++ b/src/custom-sort/custom-sort-types.ts @@ -9,7 +9,7 @@ export enum CustomSortGroupType { ExactHeadAndTail, // Like W...n or Un...ed, which is shorter variant of typing the entire title HasMetadataField, // Notes (or folder's notes) containing a specific metadata field StarredOnly, - IconFolderPlugin + HasIcon } export enum CustomSortOrder { @@ -60,7 +60,7 @@ export interface CustomSortGroup { matchFilenameWithExt?: boolean foldersOnly?: boolean withMetadataFieldName?: string // for 'with-metadata:' grouping - folderIconName?: string // for integration with obsidian-folder-icon community plugin + iconName?: string // for integration with obsidian-folder-icon community plugin priority?: number combineWithIdx?: number } diff --git a/src/custom-sort/custom-sort.spec.ts b/src/custom-sort/custom-sort.spec.ts index fa89b25..8b93d23 100644 --- a/src/custom-sort/custom-sort.spec.ts +++ b/src/custom-sort/custom-sort.spec.ts @@ -1071,14 +1071,14 @@ describe('determineSortingGroup', () => { expect(starredPluginInstance.findStarredFile).toHaveBeenCalledTimes(2) }) }) - describe('CustomSortGroupType.IconFolderPlugin', () => { + describe('CustomSortGroupType.HasIcon', () => { it('should not match file w/o icon', () => { // given const file: TFile = mockTFile('References', 'md', 111, MOCK_TIMESTAMP + 222, MOCK_TIMESTAMP + 333); const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin + type: CustomSortGroupType.HasIcon }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1110,8 +1110,8 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin, - folderIconName: 'IncorrectIconName' + type: CustomSortGroupType.HasIcon, + iconName: 'IncorrectIconName' }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1146,7 +1146,7 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin + type: CustomSortGroupType.HasIcon }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1181,8 +1181,8 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin, - folderIconName: 'CorrectIconName' + type: CustomSortGroupType.HasIcon, + iconName: 'CorrectIconName' }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1217,7 +1217,7 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin + type: CustomSortGroupType.HasIcon }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1257,7 +1257,7 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin + type: CustomSortGroupType.HasIcon }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1300,7 +1300,7 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin + type: CustomSortGroupType.HasIcon }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1346,8 +1346,8 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin, - folderIconName: 'ConfiguredIcon-by-string' + type: CustomSortGroupType.HasIcon, + iconName: 'ConfiguredIcon-by-string' }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1390,8 +1390,8 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin, - folderIconName: 'ConfiguredIcon' + type: CustomSortGroupType.HasIcon, + iconName: 'ConfiguredIcon' }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1437,8 +1437,8 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin, - folderIconName: 'ConfiguredIcon-by-string' + type: CustomSortGroupType.HasIcon, + iconName: 'ConfiguredIcon-by-string' }] } const obsidianIconFolderPluginInstance: Partial = { @@ -1481,8 +1481,8 @@ describe('determineSortingGroup', () => { const sortSpec: CustomSortSpec = { targetFoldersPaths: ['/'], groups: [{ - type: CustomSortGroupType.IconFolderPlugin, - folderIconName: 'ConfiguredIcon' + type: CustomSortGroupType.HasIcon, + iconName: 'ConfiguredIcon' }] } const obsidianIconFolderPluginInstance: Partial = { diff --git a/src/custom-sort/custom-sort.ts b/src/custom-sort/custom-sort.ts index 3e38730..0f3d04b 100644 --- a/src/custom-sort/custom-sort.ts +++ b/src/custom-sort/custom-sort.ts @@ -271,12 +271,12 @@ export const determineSortingGroup = function (entry: TFile | TFolder, spec: Cus } } break - case CustomSortGroupType.IconFolderPlugin: + case CustomSortGroupType.HasIcon: if(ctx?.iconFolderPluginInstance) { let iconName: string | undefined = determineIconOf(entry, ctx.iconFolderPluginInstance) if (iconName) { - if (group.folderIconName) { - determined = iconName === group.folderIconName + if (group.iconName) { + determined = iconName === group.iconName } else { determined = true } diff --git a/src/custom-sort/sorting-spec-processor.spec.ts b/src/custom-sort/sorting-spec-processor.spec.ts index 623f4e0..e181b36 100644 --- a/src/custom-sort/sorting-spec-processor.spec.ts +++ b/src/custom-sort/sorting-spec-processor.spec.ts @@ -1,7 +1,9 @@ import { CompoundDashNumberNormalizerFn, CompoundDashRomanNumberNormalizerFn, - CompoundDotNumberNormalizerFn, ConsumedFolderMatchingRegexp, consumeFolderByRegexpExpression, + CompoundDotNumberNormalizerFn, + ConsumedFolderMatchingRegexp, + consumeFolderByRegexpExpression, convertPlainStringToRegex, detectNumericSortingSymbols, escapeRegexUnsafeCharacters, @@ -29,6 +31,8 @@ target-folder: tricky folder < a-z by-metadata: Some-dedicated-field with-metadata: Pages > a-z by-metadata: +/: with-icon: +with-icon: RiClock24 starred: /:files starred: /folders starred: @@ -85,6 +89,8 @@ target-folder: tricky folder 2 < a-z by-metadata: Some-dedicated-field % with-metadata: Pages > a-z by-metadata: +/:files with-icon: +/folders:files with-icon: RiClock24 /folders:files starred: /:files starred: /folders starred: @@ -171,6 +177,14 @@ const expectedSortSpecsExampleA: { [key: string]: CustomSortSpec } = { type: CustomSortGroupType.HasMetadataField, withMetadataFieldName: 'Pages', order: CustomSortOrder.byMetadataFieldAlphabeticalReverse + }, { + type: CustomSortGroupType.HasIcon, + order: CustomSortOrder.alphabetical, + filesOnly: true + }, { + type: CustomSortGroupType.HasIcon, + order: CustomSortOrder.alphabetical, + iconName: 'RiClock24' }, { type: CustomSortGroupType.StarredOnly, order: CustomSortOrder.alphabetical @@ -186,7 +200,7 @@ const expectedSortSpecsExampleA: { [key: string]: CustomSortSpec } = { order: CustomSortOrder.alphabetical, type: CustomSortGroupType.Outsiders }], - outsidersGroupIdx: 5, + outsidersGroupIdx: 7, targetFoldersPaths: [ 'tricky folder 2' ] diff --git a/src/custom-sort/sorting-spec-processor.ts b/src/custom-sort/sorting-spec-processor.ts index 6a5e335..e6c31f0 100644 --- a/src/custom-sort/sorting-spec-processor.ts +++ b/src/custom-sort/sorting-spec-processor.ts @@ -207,6 +207,8 @@ const MetadataFieldIndicatorLexeme: string = 'with-metadata:' const StarredItemsIndicatorLexeme: string = 'starred:' +const IconIndicatorLexeme: string = 'with-icon:' + const CommentPrefix: string = '//' const PriorityModifierPrio1Lexeme: string = '/!' @@ -1489,6 +1491,15 @@ export class SortingSpecProcessor { foldersOnly: spec.foldersOnly, matchFilenameWithExt: spec.matchFilenameWithExt } + } else if (theOnly.startsWith(IconIndicatorLexeme)) { + const iconName: string | undefined = extractIdentifier(theOnly.substring(IconIndicatorLexeme.length)) + return { + type: CustomSortGroupType.HasIcon, + iconName: iconName, + filesOnly: spec.filesOnly, + foldersOnly: spec.foldersOnly, + matchFilenameWithExt: spec.matchFilenameWithExt + } } else if (theOnly.startsWith(StarredItemsIndicatorLexeme)) { return { type: CustomSortGroupType.StarredOnly,