mirror of
https://github.com/quartz-community/description.git
synced 2026-07-22 02:50:28 +00:00
fix: remove frontmatter from vfile augmentation to prevent type conflict
This commit is contained in:
parent
76f07f24de
commit
84a4e4da48
3 changed files with 2 additions and 10 deletions
4
dist/index.d.ts
vendored
4
dist/index.d.ts
vendored
|
|
@ -9,10 +9,6 @@ interface DescriptionOptions {
|
|||
declare const Description: QuartzTransformerPlugin<Partial<DescriptionOptions>>;
|
||||
declare module "vfile" {
|
||||
interface DataMap {
|
||||
frontmatter?: {
|
||||
description?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
description: string;
|
||||
text: string;
|
||||
}
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
|
|
@ -1 +1 @@
|
|||
{"version":3,"sources":["../src/transformer.ts"],"names":[],"mappings":";;;;AAYA,IAAM,cAAA,GAAqC;AAAA,EACzC,iBAAA,EAAmB,GAAA;AAAA,EACnB,oBAAA,EAAsB,GAAA;AAAA,EACtB,oBAAA,EAAsB;AACxB,CAAA;AAEA,IAAM,WAAW,IAAI,MAAA;AAAA,EACnB,8FAAA;AAAA,EACA;AACF,CAAA;AAEO,IAAM,WAAA,GAAoE,CAAC,QAAA,KAAa;AAC7F,EAAA,MAAM,IAAA,GAAO,EAAE,GAAG,cAAA,EAAgB,GAAG,QAAA,EAAS;AAC9C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IACN,WAAA,GAAc;AACZ,MAAA,OAAO;AAAA,QACL,MAAM;AACJ,UAAA,OAAO,OAAO,MAAgB,IAAA,KAAgB;AAC5C,YAAA,IAAI,sBAAA,GAAyB,IAAA,CAAK,IAAA,CAAK,WAAA,EAAa,WAAA;AACpD,YAAA,IAAI,IAAA,GAAO,UAAA,CAAW,QAAA,CAAS,IAAI,CAAC,CAAA;AAEpC,YAAA,IAAI,KAAK,oBAAA,EAAsB;AAC7B,cAAA,sBAAA,GAAyB,sBAAA,EAAwB,OAAA;AAAA,gBAC/C,QAA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K,KAAK,IAAA,GAAO,IAAA;AAAA,UACnB,CAAA;AAAA,QACF;AAAA,OACF;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { Root as HTMLRoot } from \"hast\";\nimport { toString } from \"hast-util-to-string\";\nimport type { QuartzTransformerPlugin } from \"@quartz-community/types\";\nimport { escapeHTML } from \"@quartz-community/utils\";\nimport type { VFile } from \"vfile\";\n\nexport interface DescriptionOptions {\n descriptionLength: number;\n maxDescriptionLength: number;\n replaceExternalLinks: boolean;\n}\n\nconst defaultOptions: DescriptionOptions = {\n descriptionLength: 150,\n maxDescriptionLength: 300,\n replaceExternalLinks: true,\n};\n\nconst urlRegex = new RegExp(\n /(https?:\\/\\/)?(?<domain>([\\da-z.-]+)\\.([a-z.]{2,6})(:\\d+)?)(?<path>[/\\w.-]*)(\\?[/\\w.=&;-]*)?/,\n \"g\",\n);\n\nexport const Description: QuartzTransformerPlugin<Partial<DescriptionOptions>> = (userOpts) => {\n const opts = { ...defaultOptions, ...userOpts };\n return {\n name: \"Description\",\n htmlPlugins() {\n return [\n () => {\n return async (tree: HTMLRoot, file: VFile) => {\n let frontMatterDescription = file.data.frontmatter?.description;\n let text = escapeHTML(toString(tree));\n\n if (opts.replaceExternalLinks) {\n frontMatterDescription = frontMatterDescription?.replace(\n urlRegex,\n \"$<domain>\" + \"$<path>\",\n );\n text = text.replace(urlRegex, \"$<domain>\" + \"$<path>\");\n }\n\n if (frontMatterDescription) {\n file.data.description = frontMatterDescription;\n file.data.text = text;\n return;\n }\n\n const desc = text;\n const sentences = desc.replace(/\\s+/g, \" \").split(/\\.\\s/);\n let finalDesc = \"\";\n let sentenceIdx = 0;\n\n while (sentenceIdx < sentences.length) {\n const sentence = sentences[sentenceIdx];\n if (!sentence) break;\n\n const currentSentence = sentence.endsWith(\".\") ? sentence : sentence + \".\";\n const nextLength = finalDesc.length + currentSentence.length + (finalDesc ? 1 : 0);\n\n if (nextLength <= opts.descriptionLength || sentenceIdx === 0) {\n finalDesc += (finalDesc ? \" \" : \"\") + currentSentence;\n sentenceIdx++;\n } else {\n break;\n }\n }\n\n file.data.description =\n finalDesc.length > opts.maxDescriptionLength\n ? finalDesc.slice(0, opts.maxDescriptionLength) + \"...\"\n : finalDesc;\n file.data.text = text;\n };\n },\n ];\n },\n };\n};\n\ndeclare module \"vfile\" {\n interface DataMap {\n frontmatter?: {\n description?: string;\n [key: string]: unknown;\n };\n description: string;\n text: string;\n }\n}\n"]}
|
||||
{"version":3,"sources":["../src/transformer.ts"],"names":[],"mappings":";;;;AAYA,IAAM,cAAA,GAAqC;AAAA,EACzC,iBAAA,EAAmB,GAAA;AAAA,EACnB,oBAAA,EAAsB,GAAA;AAAA,EACtB,oBAAA,EAAsB;AACxB,CAAA;AAEA,IAAM,WAAW,IAAI,MAAA;AAAA,EACnB,8FAAA;AAAA,EACA;AACF,CAAA;AAEO,IAAM,WAAA,GAAoE,CAAC,QAAA,KAAa;AAC7F,EAAA,MAAM,IAAA,GAAO,EAAE,GAAG,cAAA,EAAgB,GAAG,QAAA,EAAS;AAC9C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IACN,WAAA,GAAc;AACZ,MAAA,OAAO;AAAA,QACL,MAAM;AACJ,UAAA,OAAO,OAAO,MAAgB,IAAA,KAAgB;AAC5C,YAAA,IAAI,sBAAA,GAA0B,IAAA,CAAK,IAAA,CAAK,WAAA,EAAqD,WAAA;AAC7F,YAAA,IAAI,IAAA,GAAO,UAAA,CAAW,QAAA,CAAS,IAAI,CAAC,CAAA;AAEpC,YAAA,IAAI,KAAK,oBAAA,EAAsB;AAC7B,cAAA,sBAAA,GAAyB,sBAAA,EAAwB,OAAA;AAAA,gBAC/C,QAAA;AAAA,gBACA;AAAA,eACF;AACA,cAAA,IAAA,GAAO,IAAA,CAAK,OAAA,CAAQ,QAAA,EAAU,kBAAuB,CAAA;AAAA,YACvD;AAEA,YAAA,IAAI,sBAAA,EAAwB;AAC1B,cAAA,IAAA,CAAK,KAAK,WAAA,GAAc,sBAAA;AACxB,cAAA,IAAA,CAAK,KAAK,IAAA,GAAO,IAAA;AACjB,cAAA;AAAA,YACF;AAEA,YAAA,MAAM,IAAA,GAAO,IAAA;AACb,YAAA,MAAM,YAAY,IAAA,CAAK,OAAA,CAAQ,QAAQ,GAAG,CAAA,CAAE,MAAM,MAAM,CAAA;AACxD,YAAA,IAAI,SAAA,GAAY,EAAA;AAChB,YAAA,IAAI,WAAA,GAAc,CAAA;AAElB,YAAA,OAAO,WAAA,GAAc,UAAU,MAAA,EAAQ;AACrC,cAAA,MAAM,QAAA,GAAW,UAAU,WAAW,CAAA;AACtC,cAAA,IAAI,CAAC,QAAA,EAAU;AAEf,cAAA,MAAM,kBAAkB,QAAA,CAAS,QAAA,CAAS,GAAG,CAAA,GAAI,WAAW,QAAA,GAAW,GAAA;AACvE,cAAA,MAAM,aAAa,SAAA,CAAU,MAAA,GAAS,eAAA,CAAgB,MAAA,IAAU,YAAY,CAAA,GAAI,CAAA,CAAA;AAEhF,cAAA,IAAI,UAAA,IAAc,IAAA,CAAK,iBAAA,IAAqB,WAAA,KAAgB,CAAA,EAAG;AAC7D,gBAAA,SAAA,IAAA,CAAc,SAAA,GAAY,MAAM,EAAA,IAAM,eAAA;AACtC,gBAAA,WAAA,EAAA;AAAA,cACF,CAAA,MAAO;AACL,gBAAA;AAAA,cACF;AAAA,YACF;AAEA,YAAA,IAAA,CAAK,IAAA,CAAK,WAAA,GACR,SAAA,CAAU,MAAA,GAAS,IAAA,CAAK,oBAAA,GACpB,SAAA,CAAU,KAAA,CAAM,CAAA,EAAG,IAAA,CAAK,oBAAoB,CAAA,GAAI,KAAA,GAChD,SAAA;AACN,YAAA,IAAA,CAAK,KAAK,IAAA,GAAO,IAAA;AAAA,UACnB,CAAA;AAAA,QACF;AAAA,OACF;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { Root as HTMLRoot } from \"hast\";\nimport { toString } from \"hast-util-to-string\";\nimport type { QuartzTransformerPlugin } from \"@quartz-community/types\";\nimport { escapeHTML } from \"@quartz-community/utils\";\nimport type { VFile } from \"vfile\";\n\nexport interface DescriptionOptions {\n descriptionLength: number;\n maxDescriptionLength: number;\n replaceExternalLinks: boolean;\n}\n\nconst defaultOptions: DescriptionOptions = {\n descriptionLength: 150,\n maxDescriptionLength: 300,\n replaceExternalLinks: true,\n};\n\nconst urlRegex = new RegExp(\n /(https?:\\/\\/)?(?<domain>([\\da-z.-]+)\\.([a-z.]{2,6})(:\\d+)?)(?<path>[/\\w.-]*)(\\?[/\\w.=&;-]*)?/,\n \"g\",\n);\n\nexport const Description: QuartzTransformerPlugin<Partial<DescriptionOptions>> = (userOpts) => {\n const opts = { ...defaultOptions, ...userOpts };\n return {\n name: \"Description\",\n htmlPlugins() {\n return [\n () => {\n return async (tree: HTMLRoot, file: VFile) => {\n let frontMatterDescription = (file.data.frontmatter as Record<string, unknown> | undefined)?.description as string | undefined;\n let text = escapeHTML(toString(tree));\n\n if (opts.replaceExternalLinks) {\n frontMatterDescription = frontMatterDescription?.replace(\n urlRegex,\n \"$<domain>\" + \"$<path>\",\n );\n text = text.replace(urlRegex, \"$<domain>\" + \"$<path>\");\n }\n\n if (frontMatterDescription) {\n file.data.description = frontMatterDescription;\n file.data.text = text;\n return;\n }\n\n const desc = text;\n const sentences = desc.replace(/\\s+/g, \" \").split(/\\.\\s/);\n let finalDesc = \"\";\n let sentenceIdx = 0;\n\n while (sentenceIdx < sentences.length) {\n const sentence = sentences[sentenceIdx];\n if (!sentence) break;\n\n const currentSentence = sentence.endsWith(\".\") ? sentence : sentence + \".\";\n const nextLength = finalDesc.length + currentSentence.length + (finalDesc ? 1 : 0);\n\n if (nextLength <= opts.descriptionLength || sentenceIdx === 0) {\n finalDesc += (finalDesc ? \" \" : \"\") + currentSentence;\n sentenceIdx++;\n } else {\n break;\n }\n }\n\n file.data.description =\n finalDesc.length > opts.maxDescriptionLength\n ? finalDesc.slice(0, opts.maxDescriptionLength) + \"...\"\n : finalDesc;\n file.data.text = text;\n };\n },\n ];\n },\n };\n};\n\ndeclare module \"vfile\" {\n interface DataMap {\n description: string;\n text: string;\n }\n}\n"]}
|
||||
|
|
@ -29,7 +29,7 @@ export const Description: QuartzTransformerPlugin<Partial<DescriptionOptions>> =
|
|||
return [
|
||||
() => {
|
||||
return async (tree: HTMLRoot, file: VFile) => {
|
||||
let frontMatterDescription = file.data.frontmatter?.description;
|
||||
let frontMatterDescription = (file.data.frontmatter as Record<string, unknown> | undefined)?.description as string | undefined;
|
||||
let text = escapeHTML(toString(tree));
|
||||
|
||||
if (opts.replaceExternalLinks) {
|
||||
|
|
@ -80,10 +80,6 @@ export const Description: QuartzTransformerPlugin<Partial<DescriptionOptions>> =
|
|||
|
||||
declare module "vfile" {
|
||||
interface DataMap {
|
||||
frontmatter?: {
|
||||
description?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
description: string;
|
||||
text: string;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue