#60 - Simplified integration with obsidian-icon-folder plugin
- extended the parser with support of new lexeme with-icon:, with or w/o parameter - unit tests
This commit is contained in:
parent
01af14b174
commit
bd875fa804
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1110,8 +1110,8 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin,
|
||||
folderIconName: 'IncorrectIconName'
|
||||
type: CustomSortGroupType.HasIcon,
|
||||
iconName: 'IncorrectIconName'
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1146,7 +1146,7 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin
|
||||
type: CustomSortGroupType.HasIcon
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1181,8 +1181,8 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin,
|
||||
folderIconName: 'CorrectIconName'
|
||||
type: CustomSortGroupType.HasIcon,
|
||||
iconName: 'CorrectIconName'
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1217,7 +1217,7 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin
|
||||
type: CustomSortGroupType.HasIcon
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1257,7 +1257,7 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin
|
||||
type: CustomSortGroupType.HasIcon
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1300,7 +1300,7 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin
|
||||
type: CustomSortGroupType.HasIcon
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -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<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1390,8 +1390,8 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin,
|
||||
folderIconName: 'ConfiguredIcon'
|
||||
type: CustomSortGroupType.HasIcon,
|
||||
iconName: 'ConfiguredIcon'
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -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<ObsidianIconFolder_PluginInstance> = {
|
||||
|
@ -1481,8 +1481,8 @@ describe('determineSortingGroup', () => {
|
|||
const sortSpec: CustomSortSpec = {
|
||||
targetFoldersPaths: ['/'],
|
||||
groups: [{
|
||||
type: CustomSortGroupType.IconFolderPlugin,
|
||||
folderIconName: 'ConfiguredIcon'
|
||||
type: CustomSortGroupType.HasIcon,
|
||||
iconName: 'ConfiguredIcon'
|
||||
}]
|
||||
}
|
||||
const obsidianIconFolderPluginInstance: Partial<ObsidianIconFolder_PluginInstance> = {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
]
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue