Skip to content

Commit bbe468a

Browse files
author
福晋
committed
feat: add metadata ids as unique identifies
1 parent 05fc4ab commit bbe468a

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/context.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ export class Context {
6868

6969
const doc = await loader.load(filePath);
7070
const relativePath = path.relative(this.options.basePath!, filePath);
71+
// Prefer frontmatter `id` field as doc ID for deterministic, human-readable IDs.
72+
// Falls back to pathToId (hash-based) when frontmatter has no `id`.
73+
const metaId = typeof doc.meta?.id === 'string' ? doc.meta.id : undefined;
7174
return {
7275
...doc,
73-
id: pathToId(relativePath),
76+
id: metaId || pathToId(relativePath),
7477
contentHash: computeContentHash(doc.content),
7578
path: relativePath,
7679
};

‎src/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { Context } from './context';
2-
export * from './types';
2+
export * from './types';
3+
export { isCJK } from './utils/tokenizer';
4+
export { expand } from './expander/expand';

0 commit comments

Comments
 (0)