@real1ty-obsidian-plugins/utils 2.19.2 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/indexer.d.ts +5 -0
- package/dist/core/indexer.d.ts.map +1 -1
- package/dist/core/indexer.js +6 -2
- package/dist/core/indexer.js.map +1 -1
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +1 -0
- package/dist/file/index.js.map +1 -1
- package/dist/file/templater-service.d.ts +18 -0
- package/dist/file/templater-service.d.ts.map +1 -0
- package/dist/file/templater-service.js +70 -0
- package/dist/file/templater-service.js.map +1 -0
- package/package.json +1 -1
- package/src/core/indexer.ts +12 -3
- package/src/file/index.ts +1 -0
- package/src/file/templater-service.ts +93 -0
package/dist/core/indexer.d.ts
CHANGED
|
@@ -51,6 +51,11 @@ export interface IndexerEvent {
|
|
|
51
51
|
source?: FileSource;
|
|
52
52
|
oldFrontmatter?: IndexerFrontmatter;
|
|
53
53
|
frontmatterDiff?: FrontmatterDiff;
|
|
54
|
+
/**
|
|
55
|
+
* True if this deletion event is part of a rename operation.
|
|
56
|
+
* Only present on "file-deleted" events.
|
|
57
|
+
*/
|
|
58
|
+
isRename?: boolean;
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
61
|
* Generic indexer that listens to Obsidian vault events and emits
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../src/core/indexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAA6D,MAAM,UAAU,CAAC;AAC/F,OAAO,EACN,KAAK,eAAe,EAKpB,KAAK,UAAU,EAKf,MAAM,MAAM,CAAC;AAEd,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEpF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,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eAAe;IASjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B,IAAI,IAAI,IAAI;IAQZ,MAAM,IAAI,IAAI;IAMd;;OAEG;YACW,YAAY;IA+B1B;;OAEG;IACH,OAAO,CAAC,cAAc;IA6BtB,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B;;OAEG;IACH,OAAO,CAAC,eAAe;IAQvB;;OAEG;IACH,OAAO,CAAC,cAAc;IAQtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAgD9B;;OAEG;YACW,UAAU;CA8BxB"}
|
package/dist/core/indexer.js
CHANGED
|
@@ -133,14 +133,18 @@ export class Indexer {
|
|
|
133
133
|
const changedIntents$ = merge(created$, modified$).pipe(this.debounceByPath(this.config.debounceMs, (f) => f.path), map((file) => ({ kind: "changed", file, path: file.path })));
|
|
134
134
|
const deletedIntents$ = deleted$.pipe(map((file) => ({ kind: "deleted", path: file.path })));
|
|
135
135
|
const renamedIntents$ = renamed$.pipe(map(([f, oldPath]) => [f, oldPath]), filter(([f]) => Indexer.isMarkdownFile(f) && this.config.includeFile(f.path)), mergeMap(([f, oldPath]) => [
|
|
136
|
-
{ kind: "deleted", path: oldPath },
|
|
136
|
+
{ kind: "deleted", path: oldPath, isRename: true },
|
|
137
137
|
{ kind: "changed", file: f, path: f.path, oldPath },
|
|
138
138
|
]));
|
|
139
139
|
const intents$ = merge(changedIntents$, deletedIntents$, renamedIntents$);
|
|
140
140
|
return intents$.pipe(switchMap((intent) => {
|
|
141
141
|
if (intent.kind === "deleted") {
|
|
142
142
|
this.frontmatterCache.delete(intent.path);
|
|
143
|
-
return of({
|
|
143
|
+
return of({
|
|
144
|
+
type: "file-deleted",
|
|
145
|
+
filePath: intent.path,
|
|
146
|
+
isRename: intent.isRename,
|
|
147
|
+
});
|
|
144
148
|
}
|
|
145
149
|
return from(this.buildEvent(intent.file, intent.oldPath)).pipe(filter((e) => e !== null));
|
|
146
150
|
}));
|
package/dist/core/indexer.js.map
CHANGED
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AAM,GAAe;gBAC1B,QAAQ,EAAE,IAAI,CAAC,IAAI;gBACnB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;gBACtB,WAAW;gBACX,MAAM,EAAE,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,IAAI,KAAI,EAAE;aAC/B,CAAC;YAEF,MAAM,KAAK,GAAiB;gBAC3B,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,IAAI,CAAC,IAAI;gBACnB,OAAO;gBACP,MAAM;gBACN,cAAc;gBACd,eAAe,EAAE,cAAc;oBAC9B,CAAC,CAAC,kBAAkB,CAAC,cAAc,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;oBAChF,CAAC,CAAC,SAAS;aACZ,CAAC;YAEF,eAAe;YACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,oBAAO,WAAW,EAAG,CAAC;YAEzD,OAAO,KAAK,CAAC;QACd,CAAC;KAAA;CACD","sourcesContent":["import { type App, type MetadataCache, type TAbstractFile, TFile, type Vault } from \"obsidian\";\nimport {\n\ttype BehaviorSubject,\n\tfrom,\n\tfromEventPattern,\n\tlastValueFrom,\n\tmerge,\n\ttype Observable,\n\tof,\n\tBehaviorSubject as RxBehaviorSubject,\n\tSubject,\n\ttype Subscription,\n} from \"rxjs\";\nimport { debounceTime, filter, groupBy, map, mergeMap, switchMap, toArray } from \"rxjs/operators\";\nimport { compareFrontmatter, type FrontmatterDiff } from \"../file/frontmatter-diff\";\n\n/**\n * Generic frontmatter object type for indexer\n */\nexport type IndexerFrontmatter = Record<string, unknown>;\n\n/**\n * Configuration for the generic indexer\n */\nexport interface IndexerConfig {\n\t/**\n\t * Function that determines whether a file should be included in the indexer.\n\t * Returns true if the file should be indexed, false otherwise.\n\t * If not provided, all files are included.\n\t */\n\tincludeFile?: (path: string) => boolean;\n\n\t/**\n\t * Properties to exclude when comparing frontmatter diffs\n\t */\n\texcludedDiffProps?: Set<string>;\n\n\t/**\n\t * Concurrency limit for file scanning operations\n\t */\n\tscanConcurrency?: number;\n\n\t/**\n\t * Debounce time in milliseconds for file change events\n\t */\n\tdebounceMs?: number;\n}\n\n/**\n * Raw file source with frontmatter and metadata\n */\nexport interface FileSource {\n\tfilePath: string;\n\tmtime: number;\n\tfrontmatter: IndexerFrontmatter;\n\tfolder: string;\n}\n\n/**\n * Types of indexer events\n */\nexport type IndexerEventType = \"file-changed\" | \"file-deleted\";\n\n/**\n * Generic indexer event\n */\nexport interface IndexerEvent {\n\ttype: IndexerEventType;\n\tfilePath: string;\n\toldPath?: string;\n\tsource?: FileSource;\n\toldFrontmatter?: IndexerFrontmatter;\n\tfrontmatterDiff?: FrontmatterDiff;\n}\n\ntype VaultEvent = \"create\" | \"modify\" | \"delete\" | \"rename\";\n\ntype FileIntent =\n\t| { kind: \"changed\"; file: TFile; path: string; oldPath?: string }\n\t| { kind: \"deleted\"; path: string };\n\n/**\n * Generic indexer that listens to Obsidian vault events and emits\n * RxJS observables with frontmatter diffs and metadata.\n *\n * This indexer is framework-agnostic and can be used by any plugin\n * that needs to track file changes with frontmatter.\n */\nexport class Indexer {\n\tprivate config: Required<IndexerConfig>;\n\tprivate fileSub: Subscription | null = null;\n\tprivate configSubscription: Subscription | null = null;\n\tprivate vault: Vault;\n\tprivate metadataCache: MetadataCache;\n\tprivate scanEventsSubject = new Subject<IndexerEvent>();\n\tprivate indexingCompleteSubject = new RxBehaviorSubject<boolean>(false);\n\tprivate frontmatterCache: Map<string, IndexerFrontmatter> = new Map();\n\n\tpublic readonly events$: Observable<IndexerEvent>;\n\tpublic readonly indexingComplete$: Observable<boolean>;\n\n\tconstructor(app: App, configStore: BehaviorSubject<IndexerConfig>) {\n\t\tthis.vault = app.vault;\n\t\tthis.metadataCache = app.metadataCache;\n\t\tthis.config = this.normalizeConfig(configStore.value);\n\n\t\tthis.configSubscription = configStore.subscribe((newConfig) => {\n\t\t\tconst includeFileChanged =\n\t\t\t\tthis.config.includeFile !== this.normalizeConfig(newConfig).includeFile;\n\t\t\tthis.config = this.normalizeConfig(newConfig);\n\n\t\t\tif (includeFileChanged) {\n\t\t\t\tthis.indexingCompleteSubject.next(false);\n\t\t\t\tvoid this.scanAllFiles();\n\t\t\t}\n\t\t});\n\n\t\tthis.events$ = this.scanEventsSubject.asObservable();\n\t\tthis.indexingComplete$ = this.indexingCompleteSubject.asObservable();\n\t}\n\n\tprivate normalizeConfig(config: IndexerConfig): Required<IndexerConfig> {\n\t\treturn {\n\t\t\tincludeFile: config.includeFile || (() => true),\n\t\t\texcludedDiffProps: config.excludedDiffProps || new Set(),\n\t\t\tscanConcurrency: config.scanConcurrency || 10,\n\t\t\tdebounceMs: config.debounceMs || 100,\n\t\t};\n\t}\n\n\tasync start(): Promise<void> {\n\t\tthis.indexingCompleteSubject.next(false);\n\n\t\tconst fileSystemEvents$ = this.buildFileSystemEvents$();\n\n\t\tthis.fileSub = fileSystemEvents$.subscribe((event) => {\n\t\t\tthis.scanEventsSubject.next(event);\n\t\t});\n\n\t\tawait this.scanAllFiles();\n\t}\n\n\tstop(): void {\n\t\tthis.fileSub?.unsubscribe();\n\t\tthis.fileSub = null;\n\t\tthis.configSubscription?.unsubscribe();\n\t\tthis.configSubscription = null;\n\t\tthis.indexingCompleteSubject.complete();\n\t}\n\n\tresync(): void {\n\t\tthis.frontmatterCache.clear();\n\t\tthis.indexingCompleteSubject.next(false);\n\t\tvoid this.scanAllFiles();\n\t}\n\n\t/**\n\t * Scan all markdown files in the configured directory\n\t */\n\tprivate async scanAllFiles(): Promise<void> {\n\t\tconst allFiles = this.vault.getMarkdownFiles();\n\t\tconst relevantFiles = allFiles.filter((file) => this.config.includeFile(file.path));\n\n\t\tconst events$ = from(relevantFiles).pipe(\n\t\t\tmergeMap(async (file) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await this.buildEvent(file);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(`Error processing file ${file.path}:`, error);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}, this.config.scanConcurrency),\n\t\t\tfilter((event): event is IndexerEvent => event !== null),\n\t\t\ttoArray()\n\t\t);\n\n\t\ttry {\n\t\t\tconst allEvents = await lastValueFrom(events$);\n\n\t\t\tfor (const event of allEvents) {\n\t\t\t\tthis.scanEventsSubject.next(event);\n\t\t\t}\n\n\t\t\tthis.indexingCompleteSubject.next(true);\n\t\t} catch (error) {\n\t\t\tconsole.error(\"❌ Error during file scanning:\", error);\n\t\t\tthis.indexingCompleteSubject.next(true);\n\t\t}\n\t}\n\n\t/**\n\t * Create an observable from a vault event\n\t */\n\tprivate fromVaultEvent(eventName: VaultEvent): Observable<TAbstractFile> {\n\t\tif (eventName === \"create\") {\n\t\t\treturn fromEventPattern<TAbstractFile>(\n\t\t\t\t(handler) => this.vault.on(\"create\", handler),\n\t\t\t\t(handler) => this.vault.off(\"create\", handler)\n\t\t\t);\n\t\t}\n\n\t\tif (eventName === \"modify\") {\n\t\t\treturn fromEventPattern<TAbstractFile>(\n\t\t\t\t(handler) => this.vault.on(\"modify\", handler),\n\t\t\t\t(handler) => this.vault.off(\"modify\", handler)\n\t\t\t);\n\t\t}\n\n\t\tif (eventName === \"delete\") {\n\t\t\treturn fromEventPattern<TAbstractFile>(\n\t\t\t\t(handler) => this.vault.on(\"delete\", handler),\n\t\t\t\t(handler) => this.vault.off(\"delete\", handler)\n\t\t\t);\n\t\t}\n\n\t\t// eventName === \"rename\"\n\t\treturn fromEventPattern<[TAbstractFile, string]>(\n\t\t\t(handler) => this.vault.on(\"rename\", handler),\n\t\t\t(handler) => this.vault.off(\"rename\", handler)\n\t\t).pipe(map(([file]) => file));\n\t}\n\n\tprivate static isMarkdownFile(f: TAbstractFile): f is TFile {\n\t\treturn f instanceof TFile && f.extension === \"md\";\n\t}\n\n\t/**\n\t * Filter to only relevant markdown files in configured directory\n\t */\n\tprivate toRelevantFiles<T extends TAbstractFile>() {\n\t\treturn (source: Observable<T>) =>\n\t\t\tsource.pipe(\n\t\t\t\tfilter((f: TAbstractFile): f is TFile => Indexer.isMarkdownFile(f)),\n\t\t\t\tfilter((f) => this.config.includeFile(f.path))\n\t\t\t);\n\t}\n\n\t/**\n\t * Debounce events by file path\n\t */\n\tprivate debounceByPath<T>(ms: number, key: (x: T) => string) {\n\t\treturn (source: Observable<T>) =>\n\t\t\tsource.pipe(\n\t\t\t\tgroupBy(key),\n\t\t\t\tmergeMap((g$) => g$.pipe(debounceTime(ms)))\n\t\t\t);\n\t}\n\n\t/**\n\t * Build the file system events observable stream\n\t */\n\tprivate buildFileSystemEvents$(): Observable<IndexerEvent> {\n\t\tconst created$ = this.fromVaultEvent(\"create\").pipe(this.toRelevantFiles());\n\t\tconst modified$ = this.fromVaultEvent(\"modify\").pipe(this.toRelevantFiles());\n\t\tconst deleted$ = this.fromVaultEvent(\"delete\").pipe(this.toRelevantFiles());\n\n\t\tconst renamed$ = fromEventPattern<[TAbstractFile, string]>(\n\t\t\t(handler) => this.vault.on(\"rename\", handler),\n\t\t\t(handler) => this.vault.off(\"rename\", handler)\n\t\t);\n\n\t\tconst changedIntents$ = merge(created$, modified$).pipe(\n\t\t\tthis.debounceByPath(this.config.debounceMs, (f) => f.path),\n\t\t\tmap((file): FileIntent => ({ kind: \"changed\", file, path: file.path }))\n\t\t);\n\n\t\tconst deletedIntents$ = deleted$.pipe(\n\t\t\tmap((file): FileIntent => ({ kind: \"deleted\", path: file.path }))\n\t\t);\n\n\t\tconst renamedIntents$ = renamed$.pipe(\n\t\t\tmap(([f, oldPath]) => [f, oldPath] as const),\n\t\t\tfilter(([f]) => Indexer.isMarkdownFile(f) && this.config.includeFile(f.path)),\n\t\t\tmergeMap(([f, oldPath]) => [\n\t\t\t\t{ kind: \"deleted\", path: oldPath } as FileIntent,\n\t\t\t\t{ kind: \"changed\", file: f, path: f.path, oldPath } as FileIntent,\n\t\t\t])\n\t\t);\n\n\t\tconst intents$ = merge(changedIntents$, deletedIntents$, renamedIntents$);\n\n\t\treturn intents$.pipe(\n\t\t\tswitchMap((intent) => {\n\t\t\t\tif (intent.kind === \"deleted\") {\n\t\t\t\t\tthis.frontmatterCache.delete(intent.path);\n\t\t\t\t\treturn of<IndexerEvent>({ type: \"file-deleted\", filePath: intent.path });\n\t\t\t\t}\n\n\t\t\t\treturn from(this.buildEvent(intent.file, intent.oldPath)).pipe(\n\t\t\t\t\tfilter((e): e is IndexerEvent => e !== null)\n\t\t\t\t);\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Build an indexer event from a file\n\t */\n\tprivate async buildEvent(file: TFile, oldPath?: string): Promise<IndexerEvent | null> {\n\t\tconst cache = this.metadataCache.getFileCache(file);\n\t\tif (!cache || !cache.frontmatter) return null;\n\n\t\tconst { frontmatter } = cache;\n\t\tconst oldFrontmatter = this.frontmatterCache.get(file.path);\n\n\t\tconst source: FileSource = {\n\t\t\tfilePath: file.path,\n\t\t\tmtime: file.stat.mtime,\n\t\t\tfrontmatter,\n\t\t\tfolder: file.parent?.path || \"\",\n\t\t};\n\n\t\tconst event: IndexerEvent = {\n\t\t\ttype: \"file-changed\",\n\t\t\tfilePath: file.path,\n\t\t\toldPath,\n\t\t\tsource,\n\t\t\toldFrontmatter,\n\t\t\tfrontmatterDiff: oldFrontmatter\n\t\t\t\t? compareFrontmatter(oldFrontmatter, frontmatter, this.config.excludedDiffProps)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\t// Update cache\n\t\tthis.frontmatterCache.set(file.path, { ...frontmatter });\n\n\t\treturn event;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"indexer.js","sourceRoot":"","sources":["../../src/core/indexer.ts"],"names":[],"mappings":";AAAA,OAAO,EAAoD,KAAK,EAAc,MAAM,UAAU,CAAC;AAC/F,OAAO,EAEN,IAAI,EACJ,gBAAgB,EAChB,aAAa,EACb,KAAK,EAEL,EAAE,EACF,eAAe,IAAI,iBAAiB,EACpC,OAAO,GAEP,MAAM,MAAM,CAAC;AACd,OAAO,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gBAC3B,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,IAAI,CAAC,IAAI;gBACnB,OAAO;gBACP,MAAM;gBACN,cAAc;gBACd,eAAe,EAAE,cAAc;oBAC9B,CAAC,CAAC,kBAAkB,CAAC,cAAc,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;oBAChF,CAAC,CAAC,SAAS;aACZ,CAAC;YAEF,eAAe;YACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,oBAAO,WAAW,EAAG,CAAC;YAEzD,OAAO,KAAK,CAAC;QACd,CAAC;KAAA;CACD","sourcesContent":["import { type App, type MetadataCache, type TAbstractFile, TFile, type Vault } from \"obsidian\";\nimport {\n\ttype BehaviorSubject,\n\tfrom,\n\tfromEventPattern,\n\tlastValueFrom,\n\tmerge,\n\ttype Observable,\n\tof,\n\tBehaviorSubject as RxBehaviorSubject,\n\tSubject,\n\ttype Subscription,\n} from \"rxjs\";\nimport { debounceTime, filter, groupBy, map, mergeMap, switchMap, toArray } from \"rxjs/operators\";\nimport { compareFrontmatter, type FrontmatterDiff } from \"../file/frontmatter-diff\";\n\n/**\n * Generic frontmatter object type for indexer\n */\nexport type IndexerFrontmatter = Record<string, unknown>;\n\n/**\n * Configuration for the generic indexer\n */\nexport interface IndexerConfig {\n\t/**\n\t * Function that determines whether a file should be included in the indexer.\n\t * Returns true if the file should be indexed, false otherwise.\n\t * If not provided, all files are included.\n\t */\n\tincludeFile?: (path: string) => boolean;\n\n\t/**\n\t * Properties to exclude when comparing frontmatter diffs\n\t */\n\texcludedDiffProps?: Set<string>;\n\n\t/**\n\t * Concurrency limit for file scanning operations\n\t */\n\tscanConcurrency?: number;\n\n\t/**\n\t * Debounce time in milliseconds for file change events\n\t */\n\tdebounceMs?: number;\n}\n\n/**\n * Raw file source with frontmatter and metadata\n */\nexport interface FileSource {\n\tfilePath: string;\n\tmtime: number;\n\tfrontmatter: IndexerFrontmatter;\n\tfolder: string;\n}\n\n/**\n * Types of indexer events\n */\nexport type IndexerEventType = \"file-changed\" | \"file-deleted\";\n\n/**\n * Generic indexer event\n */\nexport interface IndexerEvent {\n\ttype: IndexerEventType;\n\tfilePath: string;\n\toldPath?: string;\n\tsource?: FileSource;\n\toldFrontmatter?: IndexerFrontmatter;\n\tfrontmatterDiff?: FrontmatterDiff;\n\t/**\n\t * True if this deletion event is part of a rename operation.\n\t * Only present on \"file-deleted\" events.\n\t */\n\tisRename?: boolean;\n}\n\ntype VaultEvent = \"create\" | \"modify\" | \"delete\" | \"rename\";\n\ntype FileIntent =\n\t| { kind: \"changed\"; file: TFile; path: string; oldPath?: string }\n\t| { kind: \"deleted\"; path: string; isRename?: boolean };\n\n/**\n * Generic indexer that listens to Obsidian vault events and emits\n * RxJS observables with frontmatter diffs and metadata.\n *\n * This indexer is framework-agnostic and can be used by any plugin\n * that needs to track file changes with frontmatter.\n */\nexport class Indexer {\n\tprivate config: Required<IndexerConfig>;\n\tprivate fileSub: Subscription | null = null;\n\tprivate configSubscription: Subscription | null = null;\n\tprivate vault: Vault;\n\tprivate metadataCache: MetadataCache;\n\tprivate scanEventsSubject = new Subject<IndexerEvent>();\n\tprivate indexingCompleteSubject = new RxBehaviorSubject<boolean>(false);\n\tprivate frontmatterCache: Map<string, IndexerFrontmatter> = new Map();\n\n\tpublic readonly events$: Observable<IndexerEvent>;\n\tpublic readonly indexingComplete$: Observable<boolean>;\n\n\tconstructor(app: App, configStore: BehaviorSubject<IndexerConfig>) {\n\t\tthis.vault = app.vault;\n\t\tthis.metadataCache = app.metadataCache;\n\t\tthis.config = this.normalizeConfig(configStore.value);\n\n\t\tthis.configSubscription = configStore.subscribe((newConfig) => {\n\t\t\tconst includeFileChanged =\n\t\t\t\tthis.config.includeFile !== this.normalizeConfig(newConfig).includeFile;\n\t\t\tthis.config = this.normalizeConfig(newConfig);\n\n\t\t\tif (includeFileChanged) {\n\t\t\t\tthis.indexingCompleteSubject.next(false);\n\t\t\t\tvoid this.scanAllFiles();\n\t\t\t}\n\t\t});\n\n\t\tthis.events$ = this.scanEventsSubject.asObservable();\n\t\tthis.indexingComplete$ = this.indexingCompleteSubject.asObservable();\n\t}\n\n\tprivate normalizeConfig(config: IndexerConfig): Required<IndexerConfig> {\n\t\treturn {\n\t\t\tincludeFile: config.includeFile || (() => true),\n\t\t\texcludedDiffProps: config.excludedDiffProps || new Set(),\n\t\t\tscanConcurrency: config.scanConcurrency || 10,\n\t\t\tdebounceMs: config.debounceMs || 100,\n\t\t};\n\t}\n\n\tasync start(): Promise<void> {\n\t\tthis.indexingCompleteSubject.next(false);\n\n\t\tconst fileSystemEvents$ = this.buildFileSystemEvents$();\n\n\t\tthis.fileSub = fileSystemEvents$.subscribe((event) => {\n\t\t\tthis.scanEventsSubject.next(event);\n\t\t});\n\n\t\tawait this.scanAllFiles();\n\t}\n\n\tstop(): void {\n\t\tthis.fileSub?.unsubscribe();\n\t\tthis.fileSub = null;\n\t\tthis.configSubscription?.unsubscribe();\n\t\tthis.configSubscription = null;\n\t\tthis.indexingCompleteSubject.complete();\n\t}\n\n\tresync(): void {\n\t\tthis.frontmatterCache.clear();\n\t\tthis.indexingCompleteSubject.next(false);\n\t\tvoid this.scanAllFiles();\n\t}\n\n\t/**\n\t * Scan all markdown files in the configured directory\n\t */\n\tprivate async scanAllFiles(): Promise<void> {\n\t\tconst allFiles = this.vault.getMarkdownFiles();\n\t\tconst relevantFiles = allFiles.filter((file) => this.config.includeFile(file.path));\n\n\t\tconst events$ = from(relevantFiles).pipe(\n\t\t\tmergeMap(async (file) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await this.buildEvent(file);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(`Error processing file ${file.path}:`, error);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}, this.config.scanConcurrency),\n\t\t\tfilter((event): event is IndexerEvent => event !== null),\n\t\t\ttoArray()\n\t\t);\n\n\t\ttry {\n\t\t\tconst allEvents = await lastValueFrom(events$);\n\n\t\t\tfor (const event of allEvents) {\n\t\t\t\tthis.scanEventsSubject.next(event);\n\t\t\t}\n\n\t\t\tthis.indexingCompleteSubject.next(true);\n\t\t} catch (error) {\n\t\t\tconsole.error(\"❌ Error during file scanning:\", error);\n\t\t\tthis.indexingCompleteSubject.next(true);\n\t\t}\n\t}\n\n\t/**\n\t * Create an observable from a vault event\n\t */\n\tprivate fromVaultEvent(eventName: VaultEvent): Observable<TAbstractFile> {\n\t\tif (eventName === \"create\") {\n\t\t\treturn fromEventPattern<TAbstractFile>(\n\t\t\t\t(handler) => this.vault.on(\"create\", handler),\n\t\t\t\t(handler) => this.vault.off(\"create\", handler)\n\t\t\t);\n\t\t}\n\n\t\tif (eventName === \"modify\") {\n\t\t\treturn fromEventPattern<TAbstractFile>(\n\t\t\t\t(handler) => this.vault.on(\"modify\", handler),\n\t\t\t\t(handler) => this.vault.off(\"modify\", handler)\n\t\t\t);\n\t\t}\n\n\t\tif (eventName === \"delete\") {\n\t\t\treturn fromEventPattern<TAbstractFile>(\n\t\t\t\t(handler) => this.vault.on(\"delete\", handler),\n\t\t\t\t(handler) => this.vault.off(\"delete\", handler)\n\t\t\t);\n\t\t}\n\n\t\t// eventName === \"rename\"\n\t\treturn fromEventPattern<[TAbstractFile, string]>(\n\t\t\t(handler) => this.vault.on(\"rename\", handler),\n\t\t\t(handler) => this.vault.off(\"rename\", handler)\n\t\t).pipe(map(([file]) => file));\n\t}\n\n\tprivate static isMarkdownFile(f: TAbstractFile): f is TFile {\n\t\treturn f instanceof TFile && f.extension === \"md\";\n\t}\n\n\t/**\n\t * Filter to only relevant markdown files in configured directory\n\t */\n\tprivate toRelevantFiles<T extends TAbstractFile>() {\n\t\treturn (source: Observable<T>) =>\n\t\t\tsource.pipe(\n\t\t\t\tfilter((f: TAbstractFile): f is TFile => Indexer.isMarkdownFile(f)),\n\t\t\t\tfilter((f) => this.config.includeFile(f.path))\n\t\t\t);\n\t}\n\n\t/**\n\t * Debounce events by file path\n\t */\n\tprivate debounceByPath<T>(ms: number, key: (x: T) => string) {\n\t\treturn (source: Observable<T>) =>\n\t\t\tsource.pipe(\n\t\t\t\tgroupBy(key),\n\t\t\t\tmergeMap((g$) => g$.pipe(debounceTime(ms)))\n\t\t\t);\n\t}\n\n\t/**\n\t * Build the file system events observable stream\n\t */\n\tprivate buildFileSystemEvents$(): Observable<IndexerEvent> {\n\t\tconst created$ = this.fromVaultEvent(\"create\").pipe(this.toRelevantFiles());\n\t\tconst modified$ = this.fromVaultEvent(\"modify\").pipe(this.toRelevantFiles());\n\t\tconst deleted$ = this.fromVaultEvent(\"delete\").pipe(this.toRelevantFiles());\n\n\t\tconst renamed$ = fromEventPattern<[TAbstractFile, string]>(\n\t\t\t(handler) => this.vault.on(\"rename\", handler),\n\t\t\t(handler) => this.vault.off(\"rename\", handler)\n\t\t);\n\n\t\tconst changedIntents$ = merge(created$, modified$).pipe(\n\t\t\tthis.debounceByPath(this.config.debounceMs, (f) => f.path),\n\t\t\tmap((file): FileIntent => ({ kind: \"changed\", file, path: file.path }))\n\t\t);\n\n\t\tconst deletedIntents$ = deleted$.pipe(\n\t\t\tmap((file): FileIntent => ({ kind: \"deleted\", path: file.path }))\n\t\t);\n\n\t\tconst renamedIntents$ = renamed$.pipe(\n\t\t\tmap(([f, oldPath]) => [f, oldPath] as const),\n\t\t\tfilter(([f]) => Indexer.isMarkdownFile(f) && this.config.includeFile(f.path)),\n\t\t\tmergeMap(([f, oldPath]) => [\n\t\t\t\t{ kind: \"deleted\", path: oldPath, isRename: true } as FileIntent,\n\t\t\t\t{ kind: \"changed\", file: f, path: f.path, oldPath } as FileIntent,\n\t\t\t])\n\t\t);\n\n\t\tconst intents$ = merge(changedIntents$, deletedIntents$, renamedIntents$);\n\n\t\treturn intents$.pipe(\n\t\t\tswitchMap((intent) => {\n\t\t\t\tif (intent.kind === \"deleted\") {\n\t\t\t\t\tthis.frontmatterCache.delete(intent.path);\n\t\t\t\t\treturn of<IndexerEvent>({\n\t\t\t\t\t\ttype: \"file-deleted\",\n\t\t\t\t\t\tfilePath: intent.path,\n\t\t\t\t\t\tisRename: intent.isRename,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn from(this.buildEvent(intent.file, intent.oldPath)).pipe(\n\t\t\t\t\tfilter((e): e is IndexerEvent => e !== null)\n\t\t\t\t);\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Build an indexer event from a file\n\t */\n\tprivate async buildEvent(file: TFile, oldPath?: string): Promise<IndexerEvent | null> {\n\t\tconst cache = this.metadataCache.getFileCache(file);\n\t\tif (!cache || !cache.frontmatter) return null;\n\n\t\tconst { frontmatter } = cache;\n\t\tconst oldFrontmatter = this.frontmatterCache.get(file.path);\n\n\t\tconst source: FileSource = {\n\t\t\tfilePath: file.path,\n\t\t\tmtime: file.stat.mtime,\n\t\t\tfrontmatter,\n\t\t\tfolder: file.parent?.path || \"\",\n\t\t};\n\n\t\tconst event: IndexerEvent = {\n\t\t\ttype: \"file-changed\",\n\t\t\tfilePath: file.path,\n\t\t\toldPath,\n\t\t\tsource,\n\t\t\toldFrontmatter,\n\t\t\tfrontmatterDiff: oldFrontmatter\n\t\t\t\t? compareFrontmatter(oldFrontmatter, frontmatter, this.config.excludedDiffProps)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\t// Update cache\n\t\tthis.frontmatterCache.set(file.path, { ...frontmatter });\n\n\t\treturn event;\n\t}\n}\n"]}
|
package/dist/file/index.d.ts
CHANGED
package/dist/file/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
package/dist/file/index.js
CHANGED
package/dist/file/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./child-reference\";\nexport * from \"./file\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./frontmatter\";\nexport * from \"./frontmatter-diff\";\nexport * from \"./frontmatter-propagation\";\nexport * from \"./link-parser\";\nexport * from \"./property-utils\";\nexport * from \"./templater\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./child-reference\";\nexport * from \"./file\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./frontmatter\";\nexport * from \"./frontmatter-diff\";\nexport * from \"./frontmatter-propagation\";\nexport * from \"./link-parser\";\nexport * from \"./property-utils\";\nexport * from \"./templater\";\nexport * from \"./templater-service\";\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type App, TFile } from "obsidian";
|
|
2
|
+
import type { FileCreationOptions } from "./templater";
|
|
3
|
+
export type { FileCreationOptions };
|
|
4
|
+
export declare class TemplaterService {
|
|
5
|
+
private app;
|
|
6
|
+
constructor(app: App);
|
|
7
|
+
/**
|
|
8
|
+
* Checks if Templater plugin is installed and enabled.
|
|
9
|
+
*/
|
|
10
|
+
isAvailable(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a file using Templater or falls back to manual creation.
|
|
13
|
+
*/
|
|
14
|
+
createFile(options: FileCreationOptions): Promise<TFile>;
|
|
15
|
+
private shouldUseTemplate;
|
|
16
|
+
private createManually;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=templater-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templater-service.d.ts","sourceRoot":"","sources":["../../src/file/templater-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,YAAY,EAAE,mBAAmB,EAAE,CAAC;AAMpC,qBAAa,gBAAgB;IAChB,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG;IAE5B;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC;IAmC9D,OAAO,CAAC,iBAAiB;YAIX,cAAc;CA8B5B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { TFile } from "obsidian";
|
|
3
|
+
import { createFromTemplate, isTemplaterAvailable } from "./templater";
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Templater Service (Class-based wrapper)
|
|
6
|
+
// ============================================================================
|
|
7
|
+
export class TemplaterService {
|
|
8
|
+
constructor(app) {
|
|
9
|
+
this.app = app;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Checks if Templater plugin is installed and enabled.
|
|
13
|
+
*/
|
|
14
|
+
isAvailable() {
|
|
15
|
+
return isTemplaterAvailable(this.app);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a file using Templater or falls back to manual creation.
|
|
19
|
+
*/
|
|
20
|
+
createFile(options) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const { title, targetDirectory, filename, content, frontmatter, templatePath, useTemplater } = options;
|
|
23
|
+
const finalFilename = filename || title;
|
|
24
|
+
// If content is provided, use manual creation to preserve the content
|
|
25
|
+
if (content) {
|
|
26
|
+
return this.createManually(title, targetDirectory, finalFilename, content, frontmatter);
|
|
27
|
+
}
|
|
28
|
+
// Try to use Templater if requested and available
|
|
29
|
+
if (useTemplater && templatePath && this.shouldUseTemplate(templatePath)) {
|
|
30
|
+
const templateFile = yield createFromTemplate(this.app, templatePath, targetDirectory, finalFilename);
|
|
31
|
+
if (templateFile) {
|
|
32
|
+
// Apply frontmatter if provided
|
|
33
|
+
if (frontmatter && Object.keys(frontmatter).length > 0) {
|
|
34
|
+
yield this.app.fileManager.processFrontMatter(templateFile, (fm) => {
|
|
35
|
+
Object.assign(fm, frontmatter);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return templateFile;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Fallback to manual creation
|
|
42
|
+
return this.createManually(title, targetDirectory, finalFilename, content, frontmatter);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
shouldUseTemplate(templatePath) {
|
|
46
|
+
return !!(templatePath && this.isAvailable() && this.app.vault.getFileByPath(templatePath));
|
|
47
|
+
}
|
|
48
|
+
createManually(title, targetDirectory, filename, customContent, frontmatter) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const baseName = filename.replace(/\.md$/, "");
|
|
51
|
+
const filePath = `${targetDirectory}/${baseName}.md`;
|
|
52
|
+
// Check if file already exists
|
|
53
|
+
const existingFile = this.app.vault.getAbstractFileByPath(filePath);
|
|
54
|
+
if (existingFile instanceof TFile) {
|
|
55
|
+
return existingFile;
|
|
56
|
+
}
|
|
57
|
+
// Use custom content or default
|
|
58
|
+
const content = customContent || `# ${title}\n\n`;
|
|
59
|
+
const file = yield this.app.vault.create(filePath, content);
|
|
60
|
+
// Apply frontmatter if provided
|
|
61
|
+
if (frontmatter && Object.keys(frontmatter).length > 0) {
|
|
62
|
+
yield this.app.fileManager.processFrontMatter(file, (fm) => {
|
|
63
|
+
Object.assign(fm, frontmatter);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return file;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=templater-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templater-service.js","sourceRoot":"","sources":["../../src/file/templater-service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAY,KAAK,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAIvE,+EAA+E;AAC/E,0CAA0C;AAC1C,+EAA+E;AAE/E,M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ptions } from \"./templater\";\nimport { createFromTemplate, isTemplaterAvailable } from \"./templater\";\n\nexport type { FileCreationOptions };\n\n// ============================================================================\n// Templater Service (Class-based wrapper)\n// ============================================================================\n\nexport class TemplaterService {\n\tconstructor(private app: App) {}\n\n\t/**\n\t * Checks if Templater plugin is installed and enabled.\n\t */\n\tisAvailable(): boolean {\n\t\treturn isTemplaterAvailable(this.app);\n\t}\n\n\t/**\n\t * Creates a file using Templater or falls back to manual creation.\n\t */\n\tasync createFile(options: FileCreationOptions): Promise<TFile> {\n\t\tconst { title, targetDirectory, filename, content, frontmatter, templatePath, useTemplater } =\n\t\t\toptions;\n\n\t\tconst finalFilename = filename || title;\n\n\t\t// If content is provided, use manual creation to preserve the content\n\t\tif (content) {\n\t\t\treturn this.createManually(title, targetDirectory, finalFilename, content, frontmatter);\n\t\t}\n\n\t\t// Try to use Templater if requested and available\n\t\tif (useTemplater && templatePath && this.shouldUseTemplate(templatePath)) {\n\t\t\tconst templateFile = await createFromTemplate(\n\t\t\t\tthis.app,\n\t\t\t\ttemplatePath,\n\t\t\t\ttargetDirectory,\n\t\t\t\tfinalFilename\n\t\t\t);\n\n\t\t\tif (templateFile) {\n\t\t\t\t// Apply frontmatter if provided\n\t\t\t\tif (frontmatter && Object.keys(frontmatter).length > 0) {\n\t\t\t\t\tawait this.app.fileManager.processFrontMatter(templateFile, (fm) => {\n\t\t\t\t\t\tObject.assign(fm, frontmatter);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn templateFile;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to manual creation\n\t\treturn this.createManually(title, targetDirectory, finalFilename, content, frontmatter);\n\t}\n\n\tprivate shouldUseTemplate(templatePath: string): boolean {\n\t\treturn !!(templatePath && this.isAvailable() && this.app.vault.getFileByPath(templatePath));\n\t}\n\n\tprivate async createManually(\n\t\ttitle: string,\n\t\ttargetDirectory: string,\n\t\tfilename: string,\n\t\tcustomContent?: string,\n\t\tfrontmatter?: Record<string, unknown>\n\t): Promise<TFile> {\n\t\tconst baseName = filename.replace(/\\.md$/, \"\");\n\t\tconst filePath = `${targetDirectory}/${baseName}.md`;\n\n\t\t// Check if file already exists\n\t\tconst existingFile = this.app.vault.getAbstractFileByPath(filePath);\n\t\tif (existingFile instanceof TFile) {\n\t\t\treturn existingFile;\n\t\t}\n\n\t\t// Use custom content or default\n\t\tconst content = customContent || `# ${title}\\n\\n`;\n\n\t\tconst file = await this.app.vault.create(filePath, content);\n\n\t\t// Apply frontmatter if provided\n\t\tif (frontmatter && Object.keys(frontmatter).length > 0) {\n\t\t\tawait this.app.fileManager.processFrontMatter(file, (fm) => {\n\t\t\t\tObject.assign(fm, frontmatter);\n\t\t\t});\n\t\t}\n\n\t\treturn file;\n\t}\n}\n"]}
|
package/package.json
CHANGED
package/src/core/indexer.ts
CHANGED
|
@@ -71,13 +71,18 @@ export interface IndexerEvent {
|
|
|
71
71
|
source?: FileSource;
|
|
72
72
|
oldFrontmatter?: IndexerFrontmatter;
|
|
73
73
|
frontmatterDiff?: FrontmatterDiff;
|
|
74
|
+
/**
|
|
75
|
+
* True if this deletion event is part of a rename operation.
|
|
76
|
+
* Only present on "file-deleted" events.
|
|
77
|
+
*/
|
|
78
|
+
isRename?: boolean;
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
type VaultEvent = "create" | "modify" | "delete" | "rename";
|
|
77
82
|
|
|
78
83
|
type FileIntent =
|
|
79
84
|
| { kind: "changed"; file: TFile; path: string; oldPath?: string }
|
|
80
|
-
| { kind: "deleted"; path: string };
|
|
85
|
+
| { kind: "deleted"; path: string; isRename?: boolean };
|
|
81
86
|
|
|
82
87
|
/**
|
|
83
88
|
* Generic indexer that listens to Obsidian vault events and emits
|
|
@@ -272,7 +277,7 @@ export class Indexer {
|
|
|
272
277
|
map(([f, oldPath]) => [f, oldPath] as const),
|
|
273
278
|
filter(([f]) => Indexer.isMarkdownFile(f) && this.config.includeFile(f.path)),
|
|
274
279
|
mergeMap(([f, oldPath]) => [
|
|
275
|
-
{ kind: "deleted", path: oldPath } as FileIntent,
|
|
280
|
+
{ kind: "deleted", path: oldPath, isRename: true } as FileIntent,
|
|
276
281
|
{ kind: "changed", file: f, path: f.path, oldPath } as FileIntent,
|
|
277
282
|
])
|
|
278
283
|
);
|
|
@@ -283,7 +288,11 @@ export class Indexer {
|
|
|
283
288
|
switchMap((intent) => {
|
|
284
289
|
if (intent.kind === "deleted") {
|
|
285
290
|
this.frontmatterCache.delete(intent.path);
|
|
286
|
-
return of<IndexerEvent>({
|
|
291
|
+
return of<IndexerEvent>({
|
|
292
|
+
type: "file-deleted",
|
|
293
|
+
filePath: intent.path,
|
|
294
|
+
isRename: intent.isRename,
|
|
295
|
+
});
|
|
287
296
|
}
|
|
288
297
|
|
|
289
298
|
return from(this.buildEvent(intent.file, intent.oldPath)).pipe(
|
package/src/file/index.ts
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type App, TFile } from "obsidian";
|
|
2
|
+
import type { FileCreationOptions } from "./templater";
|
|
3
|
+
import { createFromTemplate, isTemplaterAvailable } from "./templater";
|
|
4
|
+
|
|
5
|
+
export type { FileCreationOptions };
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Templater Service (Class-based wrapper)
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
export class TemplaterService {
|
|
12
|
+
constructor(private app: App) {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if Templater plugin is installed and enabled.
|
|
16
|
+
*/
|
|
17
|
+
isAvailable(): boolean {
|
|
18
|
+
return isTemplaterAvailable(this.app);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a file using Templater or falls back to manual creation.
|
|
23
|
+
*/
|
|
24
|
+
async createFile(options: FileCreationOptions): Promise<TFile> {
|
|
25
|
+
const { title, targetDirectory, filename, content, frontmatter, templatePath, useTemplater } =
|
|
26
|
+
options;
|
|
27
|
+
|
|
28
|
+
const finalFilename = filename || title;
|
|
29
|
+
|
|
30
|
+
// If content is provided, use manual creation to preserve the content
|
|
31
|
+
if (content) {
|
|
32
|
+
return this.createManually(title, targetDirectory, finalFilename, content, frontmatter);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Try to use Templater if requested and available
|
|
36
|
+
if (useTemplater && templatePath && this.shouldUseTemplate(templatePath)) {
|
|
37
|
+
const templateFile = await createFromTemplate(
|
|
38
|
+
this.app,
|
|
39
|
+
templatePath,
|
|
40
|
+
targetDirectory,
|
|
41
|
+
finalFilename
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (templateFile) {
|
|
45
|
+
// Apply frontmatter if provided
|
|
46
|
+
if (frontmatter && Object.keys(frontmatter).length > 0) {
|
|
47
|
+
await this.app.fileManager.processFrontMatter(templateFile, (fm) => {
|
|
48
|
+
Object.assign(fm, frontmatter);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return templateFile;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Fallback to manual creation
|
|
56
|
+
return this.createManually(title, targetDirectory, finalFilename, content, frontmatter);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private shouldUseTemplate(templatePath: string): boolean {
|
|
60
|
+
return !!(templatePath && this.isAvailable() && this.app.vault.getFileByPath(templatePath));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private async createManually(
|
|
64
|
+
title: string,
|
|
65
|
+
targetDirectory: string,
|
|
66
|
+
filename: string,
|
|
67
|
+
customContent?: string,
|
|
68
|
+
frontmatter?: Record<string, unknown>
|
|
69
|
+
): Promise<TFile> {
|
|
70
|
+
const baseName = filename.replace(/\.md$/, "");
|
|
71
|
+
const filePath = `${targetDirectory}/${baseName}.md`;
|
|
72
|
+
|
|
73
|
+
// Check if file already exists
|
|
74
|
+
const existingFile = this.app.vault.getAbstractFileByPath(filePath);
|
|
75
|
+
if (existingFile instanceof TFile) {
|
|
76
|
+
return existingFile;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Use custom content or default
|
|
80
|
+
const content = customContent || `# ${title}\n\n`;
|
|
81
|
+
|
|
82
|
+
const file = await this.app.vault.create(filePath, content);
|
|
83
|
+
|
|
84
|
+
// Apply frontmatter if provided
|
|
85
|
+
if (frontmatter && Object.keys(frontmatter).length > 0) {
|
|
86
|
+
await this.app.fileManager.processFrontMatter(file, (fm) => {
|
|
87
|
+
Object.assign(fm, frontmatter);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return file;
|
|
92
|
+
}
|
|
93
|
+
}
|