fuma-content 1.1.5 → 1.2.1
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/{async-cache-Cce8lc9D.js → async-cache-C47yxLCv.js} +3 -4
- package/dist/{async-cache-Cce8lc9D.js.map → async-cache-C47yxLCv.js.map} +1 -1
- package/dist/bin.js +2 -3
- package/dist/bin.js.map +1 -1
- package/dist/build-mdx-C8u32vDa.js +158 -0
- package/dist/build-mdx-C8u32vDa.js.map +1 -0
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +2 -3
- package/dist/bun/index.js.map +1 -1
- package/dist/{bun-DsjsbVrx.js → bun-NahDFkhR.js} +3 -4
- package/dist/{bun-DsjsbVrx.js.map → bun-NahDFkhR.js.map} +1 -1
- package/dist/{code-generator-CHcOrCeM.js → code-generator-pLUE7Rk7.js} +2 -3
- package/dist/{code-generator-CHcOrCeM.js.map → code-generator-pLUE7Rk7.js.map} +1 -1
- package/dist/collections/data/runtime.d.ts +2 -3
- package/dist/collections/data/runtime.d.ts.map +1 -1
- package/dist/collections/data/runtime.js +1 -2
- package/dist/collections/data/runtime.js.map +1 -1
- package/dist/collections/data.d.ts +3 -4
- package/dist/collections/data.d.ts.map +1 -1
- package/dist/collections/data.js +5 -6
- package/dist/collections/data.js.map +1 -1
- package/dist/collections/fs.d.ts +2 -45
- package/dist/collections/fs.js +3 -4
- package/dist/collections/fs.js.map +1 -1
- package/dist/collections/index.d.ts +2 -37
- package/dist/collections/index.js +1 -37
- package/dist/collections/json/loader-webpack.d.ts +1 -3
- package/dist/collections/json/loader-webpack.js +4 -5
- package/dist/collections/json/loader-webpack.js.map +1 -1
- package/dist/collections/mdx/loader-webpack.d.ts +1 -3
- package/dist/collections/mdx/loader-webpack.js +4 -5
- package/dist/collections/mdx/loader-webpack.js.map +1 -1
- package/dist/collections/mdx/react.d.ts +2 -4
- package/dist/collections/mdx/react.d.ts.map +1 -1
- package/dist/collections/mdx/react.js +2 -3
- package/dist/collections/mdx/react.js.map +1 -1
- package/dist/collections/mdx/runtime-browser.d.ts +3 -25
- package/dist/collections/mdx/runtime-browser.js +2 -4
- package/dist/collections/mdx/runtime-browser.js.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.d.ts +4 -5
- package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.js +6 -7
- package/dist/collections/mdx/runtime-dynamic.js.map +1 -1
- package/dist/collections/mdx/runtime.d.ts +2 -26
- package/dist/collections/mdx/runtime.js +1 -2
- package/dist/collections/mdx/runtime.js.map +1 -1
- package/dist/collections/mdx/vue.d.ts +27 -0
- package/dist/collections/mdx/vue.d.ts.map +1 -0
- package/dist/collections/mdx/vue.js +34 -0
- package/dist/collections/mdx/vue.js.map +1 -0
- package/dist/collections/mdx.d.ts +2 -59
- package/dist/collections/mdx.js +6 -7
- package/dist/collections/mdx.js.map +1 -1
- package/dist/collections/obsidian.d.ts +1 -3
- package/dist/collections/obsidian.d.ts.map +1 -1
- package/dist/collections/obsidian.js +164 -127
- package/dist/collections/obsidian.js.map +1 -1
- package/dist/collections/runtime/file-store.d.ts +2 -21
- package/dist/collections/runtime/file-store.js +1 -2
- package/dist/collections/runtime/file-store.js.map +1 -1
- package/dist/collections/runtime/store.d.ts +2 -31
- package/dist/collections/runtime/store.js +1 -1
- package/dist/collections/runtime/store.js.map +1 -1
- package/dist/collections/yaml/loader-webpack.d.ts +1 -3
- package/dist/collections/yaml/loader-webpack.js +4 -5
- package/dist/collections/yaml/loader-webpack.js.map +1 -1
- package/dist/{pipe-CvCqOpXX.js → collections-BuskUhft.js} +36 -4
- package/dist/collections-BuskUhft.js.map +1 -0
- package/dist/config/index.d.ts +2 -35
- package/dist/config/index.js +1 -1
- package/dist/{core-FjA_Xoho.d.ts → core-15rgY8JW.d.ts} +69 -4
- package/dist/core-15rgY8JW.d.ts.map +1 -0
- package/dist/{core-BuUsOElL.js → core-BfIQeHzH.js} +18 -15
- package/dist/core-BfIQeHzH.js.map +1 -0
- package/dist/dynamic-CwBRfhBm.d.ts +32 -0
- package/dist/dynamic-CwBRfhBm.d.ts.map +1 -0
- package/dist/dynamic.d.ts +2 -25
- package/dist/dynamic.js +2 -3
- package/dist/dynamic.js.map +1 -1
- package/dist/file-store-270Y4Sx7.d.ts +20 -0
- package/dist/file-store-270Y4Sx7.d.ts.map +1 -0
- package/dist/flatten-m0wfHxLH.js +10 -0
- package/dist/flatten-m0wfHxLH.js.map +1 -0
- package/dist/fs-DDVhjRBi.d.ts +44 -0
- package/dist/fs-DDVhjRBi.d.ts.map +1 -0
- package/dist/{fuma-matter-CCYGfgju.js → fuma-matter-E30PU53R.js} +2 -3
- package/dist/{fuma-matter-CCYGfgju.js.map → fuma-matter-E30PU53R.js.map} +1 -1
- package/dist/git-Ce7r2zfM.d.ts +37 -0
- package/dist/git-Ce7r2zfM.d.ts.map +1 -0
- package/dist/index-B9DAFF8c.d.ts +84 -0
- package/dist/index-B9DAFF8c.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -5
- package/dist/{is-promise-like-pBUIbRFy.js → is-promise-like-C04ERo2r.js} +2 -2
- package/dist/{is-promise-like-pBUIbRFy.js.map → is-promise-like-C04ERo2r.js.map} +1 -1
- package/dist/{load-from-file-B9ho46XM.js → load-from-file-C3CnD8mJ.js} +3 -4
- package/dist/{load-from-file-B9ho46XM.js.map → load-from-file-C3CnD8mJ.js.map} +1 -1
- package/dist/{loader-B3hZ0R4a.js → loader-CyhM9SLt.js} +5 -6
- package/dist/{loader-B3hZ0R4a.js.map → loader-CyhM9SLt.js.map} +1 -1
- package/dist/{loader-D2BD3e0R.js → loader-D_sKOzDc.js} +4 -5
- package/dist/{loader-D2BD3e0R.js.map → loader-D_sKOzDc.js.map} +1 -1
- package/dist/{loader-C5w-u-h2.js → loader-e2SkeDfY.js} +4 -5
- package/dist/{loader-C5w-u-h2.js.map → loader-e2SkeDfY.js.map} +1 -1
- package/dist/{loader-BFfzKD3u.js → loader-ol04zeoP.js} +3 -4
- package/dist/{loader-BFfzKD3u.js.map → loader-ol04zeoP.js.map} +1 -1
- package/dist/mdx-BfaapI6d.d.ts +138 -0
- package/dist/mdx-BfaapI6d.d.ts.map +1 -0
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +3 -4
- package/dist/next/index.js.map +1 -1
- package/dist/node/index.d.ts +0 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -2
- package/dist/node/index.js.map +1 -1
- package/dist/node/loader.d.ts +1 -1
- package/dist/node/loader.js +3 -4
- package/dist/node/loader.js.map +1 -1
- package/dist/{node-Cu5Pqxxo.js → node-Du4i4XDg.js} +2 -3
- package/dist/{node-Cu5Pqxxo.js.map → node-Du4i4XDg.js.map} +1 -1
- package/dist/plugins/git.d.ts +2 -38
- package/dist/plugins/git.js +3 -5
- package/dist/plugins/git.js.map +1 -1
- package/dist/plugins/json-schema.d.ts +1 -2
- package/dist/plugins/json-schema.d.ts.map +1 -1
- package/dist/plugins/json-schema.js +2 -3
- package/dist/plugins/json-schema.js.map +1 -1
- package/dist/plugins/loader/index.d.ts +2 -72
- package/dist/plugins/loader/index.js +6 -7
- package/dist/plugins/loader/index.js.map +1 -1
- package/dist/plugins/loader/webpack.d.ts +2 -21
- package/dist/plugins/loader/webpack.js +3 -4
- package/dist/plugins/loader/webpack.js.map +1 -1
- package/dist/plugins/remark/include.d.ts +23 -0
- package/dist/plugins/remark/include.d.ts.map +1 -0
- package/dist/{build-mdx-C210zpJN.js → plugins/remark/include.js} +5 -166
- package/dist/plugins/remark/include.js.map +1 -0
- package/dist/rolldown-runtime-CiIaOW0V.js +13 -0
- package/dist/runtime-bpro4VYw.d.ts +25 -0
- package/dist/runtime-bpro4VYw.d.ts.map +1 -0
- package/dist/runtime-browser-BT3GpIH7.d.ts +29 -0
- package/dist/runtime-browser-BT3GpIH7.d.ts.map +1 -0
- package/dist/store-Cc6y2CDE.d.ts +31 -0
- package/dist/store-Cc6y2CDE.d.ts.map +1 -0
- package/dist/{validation-C3kXuveD.js → validation-Bf_v2L3p.js} +2 -2
- package/dist/{validation-C3kXuveD.js.map → validation-Bf_v2L3p.js.map} +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +3 -4
- package/dist/vite/index.js.map +1 -1
- package/dist/{vite-CoJIMNWk.js → vite-DVIOnBqW.js} +2 -3
- package/dist/{vite-CoJIMNWk.js.map → vite-DVIOnBqW.js.map} +1 -1
- package/package.json +42 -61
- package/dist/async-cache-Ca5oMQss.d.ts +0 -11
- package/dist/async-cache-Ca5oMQss.d.ts.map +0 -1
- package/dist/build-mdx-C210zpJN.js.map +0 -1
- package/dist/build-mdx-DhXGp7I9.d.ts +0 -101
- package/dist/build-mdx-DhXGp7I9.d.ts.map +0 -1
- package/dist/collections/fs.d.ts.map +0 -1
- package/dist/collections/index.d.ts.map +0 -1
- package/dist/collections/index.js.map +0 -1
- package/dist/collections/mdx/runtime-browser.d.ts.map +0 -1
- package/dist/collections/mdx/runtime.d.ts.map +0 -1
- package/dist/collections/mdx.d.ts.map +0 -1
- package/dist/collections/runtime/file-store.d.ts.map +0 -1
- package/dist/collections/runtime/store.d.ts.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/core-BuUsOElL.js.map +0 -1
- package/dist/core-FjA_Xoho.d.ts.map +0 -1
- package/dist/dynamic.d.ts.map +0 -1
- package/dist/load-from-file-CIYdu-B5.d.ts +0 -10
- package/dist/load-from-file-CIYdu-B5.d.ts.map +0 -1
- package/dist/pipe-CvCqOpXX.js.map +0 -1
- package/dist/plugins/git.d.ts.map +0 -1
- package/dist/plugins/loader/index.d.ts.map +0 -1
- package/dist/plugins/loader/webpack.d.ts.map +0 -1
- package/dist/rolldown-runtime-CjeV3_4I.js +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx.js","names":["#mdxOptions","#mdxOptionsCache","#onFrontmatter","#onServerHandler","#onEmitHandler","#onGitHandler"],"sources":["../../src/collections/mdx.ts"],"sourcesContent":["import type { Collection } from \"@/collections\";\nimport type { PostprocessOptions } from \"@/collections/mdx/remark-postprocess\";\nimport type { Core, CoreOptions } from \"@/core\";\nimport type { VFile } from \"vfile\";\nimport type { TurbopackLoaderOptions } from \"next/dist/server/config-shared\";\nimport type { Configuration } from \"webpack\";\nimport { LoaderConfig, loaderHook } from \"@/plugins/loader\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { CodeGenerator, slash } from \"@/utils/code-generator\";\nimport { validate } from \"@/utils/validation\";\nimport type { Awaitable } from \"@/types\";\nimport { asyncPipe, pipe } from \"@/utils/pipe\";\nimport { FileSystemCollection, FileSystemCollectionConfig } from \"./fs\";\nimport { GitHook, gitHook } from \"@/plugins/git\";\nimport path from \"node:path\";\nimport type { FumaContentProcessorOptions } from \"@/collections/mdx/build-mdx\";\nimport { type AsyncCache, createCache } from \"@/utils/async-cache\";\n\ninterface CompilationContext {\n collection: Collection;\n filePath: string;\n source: string;\n}\n\nexport interface MDXCollectionConfig<\n FrontmatterSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined,\n> extends Omit<FileSystemCollectionConfig, \"supportedFormats\"> {\n postprocess?: Partial<PostprocessOptions>;\n frontmatter?: FrontmatterSchema;\n options?:\n | FumaContentProcessorOptions\n | ((environment: \"bundler\" | \"runtime\") => Awaitable<FumaContentProcessorOptions>);\n lazy?: boolean;\n dynamic?: boolean;\n}\n\nconst RuntimePaths = {\n browser: \"fuma-content/collections/mdx/runtime-browser\",\n dynamic: \"fuma-content/collections/mdx/runtime-dynamic\",\n server: \"fuma-content/collections/mdx/runtime\",\n};\n\ninterface InitializerCode {\n fn: string;\n typeParams: [config: string, name: string, attached: string];\n params: string[];\n}\n\nfunction formatInitializer(code: InitializerCode) {\n return `${code.fn}<${code.typeParams.join()}>(${code.params.join()})`;\n}\n\nexport class MDXCollection<\n FrontmatterSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined,\n> extends FileSystemCollection {\n readonly dynamic: boolean;\n readonly lazy: boolean;\n readonly postprocess?: Partial<PostprocessOptions>;\n\n #mdxOptions?: MDXCollectionConfig[\"options\"];\n #mdxOptionsCache?: AsyncCache<FumaContentProcessorOptions>;\n async getMDXOptions(environment: \"bundler\" | \"runtime\"): Promise<FumaContentProcessorOptions> {\n const options = this.#mdxOptions;\n if (!options) return {};\n if (typeof options !== \"function\") return options;\n\n this.#mdxOptionsCache ??= createCache();\n return this.#mdxOptionsCache.cached(environment, () => options(environment));\n }\n /**\n * Frontmatter schema\n */\n frontmatterSchema?: FrontmatterSchema;\n /**\n * Transform & validate frontmatter\n */\n frontmatter = asyncPipe<Record<string, unknown> | undefined, CompilationContext>();\n /**\n * Transform `vfile` on compilation stage\n */\n vfile = asyncPipe<VFile, CompilationContext>();\n /**\n * Transform the generated initializer code (TypeScript) for collection store\n */\n storeInitializer = pipe<\n InitializerCode,\n {\n codegen: CodeGenerator;\n environment: \"browser\" | \"server\" | \"dynamic\";\n }\n >();\n\n $inferFrontmatter: FrontmatterSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<FrontmatterSchema>\n : Record<string, unknown> = undefined as never;\n\n constructor(config: MDXCollectionConfig<FrontmatterSchema>) {\n super({\n dir: config.dir,\n files: config.files,\n supportedFormats: [\"md\", \"mdx\"],\n });\n this.postprocess = config.postprocess;\n this.#mdxOptions = config.options;\n this.dynamic = config.dynamic ?? false;\n this.lazy = config.lazy ?? false;\n this.frontmatterSchema = config.frontmatter;\n this.frontmatter.pipe(this.#onFrontmatter.bind(this));\n this.onServer.hook(this.#onServerHandler.bind(this));\n this.onEmit.pipe(this.#onEmitHandler.bind(this));\n this.pluginHook(loaderHook).loaders.push(mdxLoader());\n this.pluginHook(gitHook).onClient.hook(this.#onGitHandler.bind(this));\n\n const { processedMarkdown, linkReferences, mdast } = this.postprocess ?? {};\n\n if (processedMarkdown) {\n const { as = \"_markdown\" } = processedMarkdown === true ? {} : processedMarkdown;\n\n this.storeInitializer.pipe((code) => {\n code.typeParams[2] += ` & { /** Processed Markdown */ ${as}: string; }`;\n return code;\n });\n }\n\n if (mdast) {\n const { as = \"_mdast\" } = mdast === true ? {} : mdast;\n\n this.storeInitializer.pipe((code) => {\n code.typeParams[2] += ` & { /** MDAST (as JSON string) */ ${as}: string; }`;\n return code;\n });\n }\n\n if (linkReferences) {\n const { as = \"_linkReferences\" } = linkReferences === true ? {} : linkReferences;\n\n this.storeInitializer.pipe((code, { codegen }) => {\n codegen.addNamedImport([\"LinkReference\"], \"fuma-content/collections/mdx\", true);\n code.typeParams[2] += ` & { /** extracted link references (e.g. hrefs, paths), useful for analyzing relationships between pages. */ ${as}: LinkReference[] }`;\n return code;\n });\n }\n }\n\n #onFrontmatter: (typeof this.frontmatter)[\"$inferHandler\"] = (data, { filePath }) => {\n if (!this.frontmatterSchema) return data;\n\n return validate(\n this.frontmatterSchema,\n data,\n undefined,\n `invalid frontmatter in ${filePath}`,\n ) as Promise<Record<string, unknown>>;\n };\n\n #onServerHandler: (typeof this.onServer)[\"$inferHandler\"] = ({ server, core }) => {\n if (!server.watcher) return;\n\n server.watcher.on(\"all\", async (event, file) => {\n if (event === \"change\" && !this.dynamic) return;\n if (!this.hasFile(file)) return;\n\n await core.emit({\n filterCollection: (item) => item === this,\n filterWorkspace: () => false,\n write: true,\n });\n });\n };\n\n #onEmitHandler: (typeof this.onEmit)[\"$inferHandler\"] = async (\n entries,\n { core, createCodeGenerator },\n ) => {\n entries.push(\n await createCodeGenerator(`${this.name}.ts`, async ({ codegen }) => {\n const runtimePath = RuntimePaths.server;\n const base = slash(core._toRuntimePath(this.dir));\n let code: InitializerCode;\n codegen.addNamespaceImport(\n \"Config\",\n codegen.formatImportPath(core.getOptions().configPath),\n true,\n );\n\n if (this.lazy) {\n codegen.addNamedImport([\"mdxStoreLazy\"], runtimePath);\n const headGlob = await this.generateDocCollectionFrontmatterGlob(core, codegen, true);\n const bodyGlob = await this.generateDocCollectionGlob(core, codegen);\n\n code = {\n fn: \"mdxStoreLazy\",\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [`\"${this.name}\"`, `\"${base}\"`, `{ head: ${headGlob}, body: ${bodyGlob} }`],\n };\n } else {\n codegen.addNamedImport([\"mdxStore\"], runtimePath);\n code = {\n fn: \"mdxStore\",\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [\n `\"${this.name}\"`,\n `\"${base}\"`,\n await this.generateDocCollectionGlob(core, codegen, true),\n ],\n };\n }\n\n code = this.storeInitializer.run(code, {\n codegen,\n environment: \"server\",\n });\n codegen.push(`export const ${this.name} = ${formatInitializer(code)};`);\n }),\n await createCodeGenerator(`${this.name}.browser.ts`, async ({ codegen }) => {\n const runtimePath = RuntimePaths.browser;\n codegen.addNamedImport([\"mdxStoreBrowser\"], runtimePath);\n codegen.addNamespaceImport(\n \"Config\",\n codegen.formatImportPath(core.getOptions().configPath),\n true,\n );\n\n let code: InitializerCode = {\n fn: `mdxStoreBrowser`,\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [`\"${this.name}\"`, await this.generateDocCollectionGlob(core, codegen)],\n };\n code = this.storeInitializer.run(code, {\n codegen,\n environment: \"browser\",\n });\n codegen.push(`export const ${this.name} = ${formatInitializer(code)};`);\n }),\n );\n if (this.dynamic)\n entries.push(\n await createCodeGenerator(`${this.name}.dynamic.ts`, async ({ codegen }) => {\n const coreOptions = core.getOptions();\n const runtimePath = RuntimePaths.dynamic;\n const base = slash(core._toRuntimePath(this.dir));\n codegen.addNamespaceImport(\"Config\", codegen.formatImportPath(coreOptions.configPath));\n codegen.addNamedImport([\"mdxStoreDynamic\"], runtimePath);\n\n const serializableCoreOptions: CoreOptions = {\n configPath: core._toRuntimePath(coreOptions.configPath),\n outDir: core._toRuntimePath(coreOptions.outDir),\n cwd: core._toRuntimePath(coreOptions.cwd),\n };\n\n const jsxImportSource =\n (await this.getMDXOptions?.(\"runtime\"))?.jsxImportSource ?? \"react\";\n if (!jsxImportSource)\n throw new Error(\n `[Fuma Content] \"jsxImportSource\" is required for dynamic MDX collection \"${this.name}\".`,\n );\n codegen.addNamespaceImport(\"_jsx_runtime\", `${jsxImportSource}/jsx-runtime`);\n\n let code: InitializerCode = {\n fn: \"mdxStoreDynamic\",\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [\n \"Config\",\n JSON.stringify(serializableCoreOptions),\n `\"${this.name}\"`,\n `\"${base}\"`,\n await this.generateDocCollectionFrontmatterGlob(core, codegen, true),\n \"_jsx_runtime\",\n ],\n };\n\n code = this.storeInitializer.run(code, {\n codegen,\n environment: \"dynamic\",\n });\n codegen.push(`export const ${this.name} = ${formatInitializer(code)};`);\n }),\n );\n return entries;\n };\n\n #onGitHandler: GitHook[\"onClient\"][\"$inferHandler\"] = async ({ client }) => {\n this.storeInitializer.pipe((code, { codegen, environment }) => {\n codegen.addNamedImport([\"WithGit\"], RuntimePaths[environment], true);\n code.typeParams[2] += \" & WithGit\";\n return code;\n });\n\n this.vfile.pipe(async (file) => {\n const vcData = await client.getFileData({ filePath: file.path });\n file.data[\"mdx-export\"] ??= [];\n file.data[\"mdx-export\"].push(\n {\n name: \"lastModified\",\n value: vcData.lastModified,\n },\n {\n name: \"creationDate\",\n value: vcData.creationDate,\n },\n );\n return file;\n });\n };\n\n private async generateDocCollectionFrontmatterGlob(\n core: Core,\n codegen: CodeGenerator,\n eager = false,\n ) {\n let s = `{`;\n const files = await this.getFiles();\n const query = codegen.formatQuery({\n collection: this.name,\n only: \"frontmatter\",\n workspace: core.getWorkspace()?.name,\n });\n for (const file of files) {\n const fullPath = path.join(this.dir, file);\n const specifier = `${codegen.formatImportPath(fullPath)}?${query}`;\n if (eager) {\n const name = codegen.generateImportName();\n codegen.addNamedImport([`frontmatter as ${name}`], specifier);\n s += `\"${slash(file)}\": ${name},`;\n } else {\n s += `\"${slash(file)}\": () => ${codegen.formatDynamicImport(specifier, \"frontmatter\")},`;\n }\n }\n s += \"}\";\n return s;\n }\n\n private async generateDocCollectionGlob(core: Core, codegen: CodeGenerator, eager = false) {\n let s = `{`;\n const files = await this.getFiles();\n const query = codegen.formatQuery({\n collection: this.name,\n workspace: core.getWorkspace()?.name,\n });\n for (const file of files) {\n const fullPath = path.join(this.dir, file);\n const specifier = `${codegen.formatImportPath(fullPath)}?${query}`;\n if (eager) {\n const name = codegen.generateImportName();\n codegen.addNamespaceImport(name, specifier);\n s += `\"${slash(file)}\": ${name},`;\n } else {\n s += `\"${slash(file)}\": () => ${codegen.formatDynamicImport(specifier)},`;\n }\n }\n s += \"}\";\n return s;\n }\n}\n\nexport function mdxCollection<FrontmatterSchema extends StandardSchemaV1 | undefined = undefined>(\n config: MDXCollectionConfig<FrontmatterSchema>,\n) {\n return new MDXCollection(config);\n}\n\nfunction mdxLoader(): LoaderConfig {\n const test = /\\.mdx?(\\?.+?)?$/;\n\n return {\n id: \"mdx\",\n test,\n configureNext(nextConfig) {\n const loaderPath = \"fuma-content/collections/mdx/loader-webpack\";\n const loaderOptions = this.getLoaderOptions();\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n \"*.{md,mdx}\": {\n loaders: [\n {\n loader: loaderPath,\n options: loaderOptions as unknown as TurbopackLoaderOptions,\n },\n ],\n as: \"*.js\",\n },\n },\n },\n pageExtensions: [...(nextConfig.pageExtensions ?? [\"js\", \"jsx\", \"tsx\", \"ts\"]), \"mdx\", \"md\"],\n webpack(config: Configuration, options) {\n config.module ||= {};\n config.module.rules ||= [];\n config.module.rules.push({\n test,\n use: [\n options.defaultLoaders.babel,\n {\n loader: loaderPath,\n options: loaderOptions,\n },\n ],\n });\n\n return nextConfig.webpack?.(config, options) ?? config;\n },\n };\n },\n async createLoader() {\n const { createMdxLoader } = await import(\"./mdx/loader\");\n return createMdxLoader({\n getCore: () => this.core,\n });\n },\n };\n}\n\nexport type { LinkReference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,iBAAiB,SAAS,CAAC,GAAG;AAC3D,OAAI,OAAO;IACT,MAAM,OAAO,QAAQ,oBAAoB;AACzC,YAAQ,mBAAmB,MAAM,UAAU;AAC3C,SAAK,IAAI,MAAM,KAAK,CAAC,KAAK,KAAK;SAE/B,MAAK,IAAI,MAAM,KAAK,CAAC,WAAW,QAAQ,oBAAoB,UAAU,CAAC;;AAG3E,OAAK;AACL,SAAO;;;AAIX,SAAgB,cACd,QACA;AACA,QAAO,IAAI,cAAc,OAAO;;AAGlC,SAAS,YAA0B;CACjC,MAAM,OAAO;AAEb,QAAO;EACL,IAAI;EACJ;EACA,cAAc,YAAY;GACxB,MAAM,aAAa;GACnB,MAAM,gBAAgB,KAAK,kBAAkB;AAE7C,UAAO;IACL,GAAG;IACH,WAAW;KACT,GAAG,WAAW;KACd,OAAO;MACL,GAAG,WAAW,WAAW;MACzB,cAAc;OACZ,SAAS,CACP;QACE,QAAQ;QACR,SAAS;QACV,CACF;OACD,IAAI;OACL;MACF;KACF;IACD,gBAAgB;KAAC,GAAI,WAAW,kBAAkB;MAAC;MAAM;MAAO;MAAO;MAAK;KAAG;KAAO;KAAK;IAC3F,QAAQ,QAAuB,SAAS;AACtC,YAAO,WAAW,EAAE;AACpB,YAAO,OAAO,UAAU,EAAE;AAC1B,YAAO,OAAO,MAAM,KAAK;MACvB;MACA,KAAK,CACH,QAAQ,eAAe,OACvB;OACE,QAAQ;OACR,SAAS;OACV,CACF;MACF,CAAC;AAEF,YAAO,WAAW,UAAU,QAAQ,QAAQ,IAAI;;IAEnD;;EAEH,MAAM,eAAe;GACnB,MAAM,EAAE,oBAAoB,MAAM,OAAO;AACzC,UAAO,gBAAgB,EACrB,eAAe,KAAK,MACrB,CAAC;;EAEL"}
|
|
1
|
+
{"version":3,"file":"mdx.js","names":["#mdxOptions","#mdxOptionsCache","#onFrontmatter","#onServerHandler","#onEmitHandler","#onGitHandler"],"sources":["../../src/collections/mdx.ts"],"sourcesContent":["import type { Collection } from \"@/collections\";\nimport type { PostprocessOptions } from \"@/collections/mdx/remark-postprocess\";\nimport type { Core, CoreOptions } from \"@/core\";\nimport type { VFile } from \"vfile\";\nimport type { TurbopackLoaderOptions } from \"next/dist/server/config-shared\";\nimport type { Configuration } from \"webpack\";\nimport { LoaderConfig, loaderHook } from \"@/plugins/loader\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { CodeGenerator, slash } from \"@/utils/code-generator\";\nimport { validate } from \"@/utils/validation\";\nimport type { Awaitable } from \"@/types\";\nimport { asyncPipe, pipe } from \"@/utils/pipe\";\nimport { FileSystemCollection, FileSystemCollectionConfig } from \"./fs\";\nimport { GitHook, gitHook } from \"@/plugins/git\";\nimport path from \"node:path\";\nimport type { FumaContentProcessorOptions } from \"@/collections/mdx/build-mdx\";\nimport { type AsyncCache, createCache } from \"@/utils/async-cache\";\n\ninterface CompilationContext {\n collection: Collection;\n filePath: string;\n source: string;\n}\n\nexport interface MDXCollectionConfig<\n FrontmatterSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined,\n> extends Omit<FileSystemCollectionConfig, \"supportedFormats\"> {\n postprocess?: Partial<PostprocessOptions>;\n frontmatter?: FrontmatterSchema;\n options?:\n | FumaContentProcessorOptions\n | ((environment: \"bundler\" | \"runtime\") => Awaitable<FumaContentProcessorOptions>);\n lazy?: boolean;\n dynamic?: boolean;\n}\n\nconst RuntimePaths = {\n browser: \"fuma-content/collections/mdx/runtime-browser\",\n dynamic: \"fuma-content/collections/mdx/runtime-dynamic\",\n server: \"fuma-content/collections/mdx/runtime\",\n};\n\ninterface InitializerCode {\n fn: string;\n typeParams: [config: string, name: string, attached: string];\n params: string[];\n}\n\nfunction formatInitializer(code: InitializerCode) {\n return `${code.fn}<${code.typeParams.join()}>(${code.params.join()})`;\n}\n\nexport class MDXCollection<\n FrontmatterSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined,\n> extends FileSystemCollection {\n readonly dynamic: boolean;\n readonly lazy: boolean;\n readonly postprocess?: Partial<PostprocessOptions>;\n\n #mdxOptions?: MDXCollectionConfig[\"options\"];\n #mdxOptionsCache?: AsyncCache<FumaContentProcessorOptions>;\n async getMDXOptions(environment: \"bundler\" | \"runtime\"): Promise<FumaContentProcessorOptions> {\n const options = this.#mdxOptions;\n if (!options) return {};\n if (typeof options !== \"function\") return options;\n\n this.#mdxOptionsCache ??= createCache();\n return this.#mdxOptionsCache.cached(environment, () => options(environment));\n }\n /**\n * Frontmatter schema\n */\n frontmatterSchema?: FrontmatterSchema;\n /**\n * Transform & validate frontmatter\n */\n frontmatter = asyncPipe<Record<string, unknown> | undefined, CompilationContext>();\n /**\n * Transform `vfile` on compilation stage\n */\n vfile = asyncPipe<VFile, CompilationContext>();\n /**\n * Transform the generated initializer code (TypeScript) for collection store\n */\n storeInitializer = pipe<\n InitializerCode,\n {\n codegen: CodeGenerator;\n environment: \"browser\" | \"server\" | \"dynamic\";\n }\n >();\n\n $inferFrontmatter: FrontmatterSchema extends StandardSchemaV1\n ? StandardSchemaV1.InferOutput<FrontmatterSchema>\n : Record<string, unknown> = undefined as never;\n\n constructor(config: MDXCollectionConfig<FrontmatterSchema>) {\n super({\n dir: config.dir,\n files: config.files,\n supportedFormats: [\"md\", \"mdx\"],\n });\n this.postprocess = config.postprocess;\n this.#mdxOptions = config.options;\n this.dynamic = config.dynamic ?? false;\n this.lazy = config.lazy ?? false;\n this.frontmatterSchema = config.frontmatter;\n this.frontmatter.pipe(this.#onFrontmatter.bind(this));\n this.onServer.hook(this.#onServerHandler.bind(this));\n this.onEmit.pipe(this.#onEmitHandler.bind(this));\n this.pluginHook(loaderHook).loaders.push(mdxLoader());\n this.pluginHook(gitHook).onClient.hook(this.#onGitHandler.bind(this));\n\n const { processedMarkdown, linkReferences, mdast } = this.postprocess ?? {};\n\n if (processedMarkdown) {\n const { as = \"_markdown\" } = processedMarkdown === true ? {} : processedMarkdown;\n\n this.storeInitializer.pipe((code) => {\n code.typeParams[2] += ` & { /** Processed Markdown */ ${as}: string; }`;\n return code;\n });\n }\n\n if (mdast) {\n const { as = \"_mdast\" } = mdast === true ? {} : mdast;\n\n this.storeInitializer.pipe((code) => {\n code.typeParams[2] += ` & { /** MDAST (as JSON string) */ ${as}: string; }`;\n return code;\n });\n }\n\n if (linkReferences) {\n const { as = \"_linkReferences\" } = linkReferences === true ? {} : linkReferences;\n\n this.storeInitializer.pipe((code, { codegen }) => {\n codegen.addNamedImport([\"LinkReference\"], \"fuma-content/collections/mdx\", true);\n code.typeParams[2] += ` & { /** extracted link references (e.g. hrefs, paths), useful for analyzing relationships between pages. */ ${as}: LinkReference[] }`;\n return code;\n });\n }\n }\n\n #onFrontmatter: (typeof this.frontmatter)[\"$inferHandler\"] = (data, { filePath }) => {\n if (!this.frontmatterSchema) return data;\n\n return validate(\n this.frontmatterSchema,\n data,\n undefined,\n `invalid frontmatter in ${filePath}`,\n ) as Promise<Record<string, unknown>>;\n };\n\n #onServerHandler: (typeof this.onServer)[\"$inferHandler\"] = ({ server, core }) => {\n if (!server.watcher) return;\n\n server.watcher.on(\"all\", async (event, file) => {\n if (event === \"change\" && !this.dynamic) return;\n if (!this.hasFile(file)) return;\n\n await core.emit({\n filterCollection: (item) => item === this,\n filterWorkspace: () => false,\n write: true,\n });\n });\n };\n\n #onEmitHandler: (typeof this.onEmit)[\"$inferHandler\"] = async (\n entries,\n { core, createCodeGenerator },\n ) => {\n entries.push(\n await createCodeGenerator(`${this.name}.ts`, async ({ codegen }) => {\n const runtimePath = RuntimePaths.server;\n const base = slash(core._toRuntimePath(this.dir));\n let code: InitializerCode;\n codegen.addNamespaceImport(\n \"Config\",\n codegen.formatImportPath(core.getOptions().configPath),\n true,\n );\n\n if (this.lazy) {\n codegen.addNamedImport([\"mdxStoreLazy\"], runtimePath);\n const headGlob = await this.generateDocCollectionFrontmatterGlob(core, codegen, true);\n const bodyGlob = await this.generateDocCollectionGlob(core, codegen);\n\n code = {\n fn: \"mdxStoreLazy\",\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [`\"${this.name}\"`, `\"${base}\"`, `{ head: ${headGlob}, body: ${bodyGlob} }`],\n };\n } else {\n codegen.addNamedImport([\"mdxStore\"], runtimePath);\n code = {\n fn: \"mdxStore\",\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [\n `\"${this.name}\"`,\n `\"${base}\"`,\n await this.generateDocCollectionGlob(core, codegen, true),\n ],\n };\n }\n\n code = this.storeInitializer.run(code, {\n codegen,\n environment: \"server\",\n });\n codegen.push(`export const ${this.name} = ${formatInitializer(code)};`);\n }),\n await createCodeGenerator(`${this.name}.browser.ts`, async ({ codegen }) => {\n const runtimePath = RuntimePaths.browser;\n codegen.addNamedImport([\"mdxStoreBrowser\"], runtimePath);\n codegen.addNamespaceImport(\n \"Config\",\n codegen.formatImportPath(core.getOptions().configPath),\n true,\n );\n\n let code: InitializerCode = {\n fn: `mdxStoreBrowser`,\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [`\"${this.name}\"`, await this.generateDocCollectionGlob(core, codegen)],\n };\n code = this.storeInitializer.run(code, {\n codegen,\n environment: \"browser\",\n });\n codegen.push(`export const ${this.name} = ${formatInitializer(code)};`);\n }),\n );\n if (this.dynamic)\n entries.push(\n await createCodeGenerator(`${this.name}.dynamic.ts`, async ({ codegen }) => {\n const coreOptions = core.getOptions();\n const runtimePath = RuntimePaths.dynamic;\n const base = slash(core._toRuntimePath(this.dir));\n codegen.addNamespaceImport(\"Config\", codegen.formatImportPath(coreOptions.configPath));\n codegen.addNamedImport([\"mdxStoreDynamic\"], runtimePath);\n\n const serializableCoreOptions: CoreOptions = {\n configPath: core._toRuntimePath(coreOptions.configPath),\n outDir: core._toRuntimePath(coreOptions.outDir),\n cwd: core._toRuntimePath(coreOptions.cwd),\n };\n\n const jsxImportSource =\n (await this.getMDXOptions?.(\"runtime\"))?.jsxImportSource ?? \"react\";\n if (!jsxImportSource)\n throw new Error(\n `[Fuma Content] \"jsxImportSource\" is required for dynamic MDX collection \"${this.name}\".`,\n );\n codegen.addNamespaceImport(\"_jsx_runtime\", `${jsxImportSource}/jsx-runtime`);\n\n let code: InitializerCode = {\n fn: \"mdxStoreDynamic\",\n typeParams: [\"typeof Config\", `\"${this.name}\"`, \"unknown\"],\n params: [\n \"Config\",\n JSON.stringify(serializableCoreOptions),\n `\"${this.name}\"`,\n `\"${base}\"`,\n await this.generateDocCollectionFrontmatterGlob(core, codegen, true),\n \"_jsx_runtime\",\n ],\n };\n\n code = this.storeInitializer.run(code, {\n codegen,\n environment: \"dynamic\",\n });\n codegen.push(`export const ${this.name} = ${formatInitializer(code)};`);\n }),\n );\n return entries;\n };\n\n #onGitHandler: GitHook[\"onClient\"][\"$inferHandler\"] = async ({ client }) => {\n this.storeInitializer.pipe((code, { codegen, environment }) => {\n codegen.addNamedImport([\"WithGit\"], RuntimePaths[environment], true);\n code.typeParams[2] += \" & WithGit\";\n return code;\n });\n\n this.vfile.pipe(async (file) => {\n const vcData = await client.getFileData({ filePath: file.path });\n file.data[\"mdx-export\"] ??= [];\n file.data[\"mdx-export\"].push(\n {\n name: \"lastModified\",\n value: vcData.lastModified,\n },\n {\n name: \"creationDate\",\n value: vcData.creationDate,\n },\n );\n return file;\n });\n };\n\n private async generateDocCollectionFrontmatterGlob(\n core: Core,\n codegen: CodeGenerator,\n eager = false,\n ) {\n let s = `{`;\n const files = await this.getFiles();\n const query = codegen.formatQuery({\n collection: this.name,\n only: \"frontmatter\",\n workspace: core.getWorkspace()?.name,\n });\n for (const file of files) {\n const fullPath = path.join(this.dir, file);\n const specifier = `${codegen.formatImportPath(fullPath)}?${query}`;\n if (eager) {\n const name = codegen.generateImportName();\n codegen.addNamedImport([`frontmatter as ${name}`], specifier);\n s += `\"${slash(file)}\": ${name},`;\n } else {\n s += `\"${slash(file)}\": () => ${codegen.formatDynamicImport(specifier, \"frontmatter\")},`;\n }\n }\n s += \"}\";\n return s;\n }\n\n private async generateDocCollectionGlob(core: Core, codegen: CodeGenerator, eager = false) {\n let s = `{`;\n const files = await this.getFiles();\n const query = codegen.formatQuery({\n collection: this.name,\n workspace: core.getWorkspace()?.name,\n });\n for (const file of files) {\n const fullPath = path.join(this.dir, file);\n const specifier = `${codegen.formatImportPath(fullPath)}?${query}`;\n if (eager) {\n const name = codegen.generateImportName();\n codegen.addNamespaceImport(name, specifier);\n s += `\"${slash(file)}\": ${name},`;\n } else {\n s += `\"${slash(file)}\": () => ${codegen.formatDynamicImport(specifier)},`;\n }\n }\n s += \"}\";\n return s;\n }\n}\n\nexport function mdxCollection<FrontmatterSchema extends StandardSchemaV1 | undefined = undefined>(\n config: MDXCollectionConfig<FrontmatterSchema>,\n) {\n return new MDXCollection(config);\n}\n\nfunction mdxLoader(): LoaderConfig {\n const test = /\\.mdx?(\\?.+?)?$/;\n\n return {\n id: \"mdx\",\n test,\n configureNext(nextConfig) {\n const loaderPath = \"fuma-content/collections/mdx/loader-webpack\";\n const loaderOptions = this.getLoaderOptions();\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n \"*.{md,mdx}\": {\n loaders: [\n {\n loader: loaderPath,\n options: loaderOptions as unknown as TurbopackLoaderOptions,\n },\n ],\n as: \"*.js\",\n },\n },\n },\n pageExtensions: [...(nextConfig.pageExtensions ?? [\"js\", \"jsx\", \"tsx\", \"ts\"]), \"mdx\", \"md\"],\n webpack(config: Configuration, options) {\n config.module ||= {};\n config.module.rules ||= [];\n config.module.rules.push({\n test,\n use: [\n options.defaultLoaders.babel,\n {\n loader: loaderPath,\n options: loaderOptions,\n },\n ],\n });\n\n return nextConfig.webpack?.(config, options) ?? config;\n },\n };\n },\n async createLoader() {\n const { createMdxLoader } = await import(\"./mdx/loader\");\n return createMdxLoader({\n getCore: () => this.core,\n });\n },\n };\n}\n\nexport type { LinkReference } from \"@/collections/mdx/remark-postprocess\";\nexport type { CompiledMDX } from \"@/collections/mdx/build-mdx\";\n"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AACzC,YAAQ,mBAAmB,MAAM,UAAU;AAC3C,SAAK,IAAI,MAAM,KAAK,CAAC,KAAK,KAAK;SAE/B,MAAK,IAAI,MAAM,KAAK,CAAC,WAAW,QAAQ,oBAAoB,UAAU,CAAC;;AAG3E,OAAK;AACL,SAAO;;;AAIX,SAAgB,cACd,QACA;AACA,QAAO,IAAI,cAAc,OAAO;;AAGlC,SAAS,YAA0B;CACjC,MAAM,OAAO;AAEb,QAAO;EACL,IAAI;EACJ;EACA,cAAc,YAAY;GACxB,MAAM,aAAa;GACnB,MAAM,gBAAgB,KAAK,kBAAkB;AAE7C,UAAO;IACL,GAAG;IACH,WAAW;KACT,GAAG,WAAW;KACd,OAAO;MACL,GAAG,WAAW,WAAW;MACzB,cAAc;OACZ,SAAS,CACP;QACE,QAAQ;QACR,SAAS;QACV,CACF;OACD,IAAI;OACL;MACF;KACF;IACD,gBAAgB;KAAC,GAAI,WAAW,kBAAkB;MAAC;MAAM;MAAO;MAAO;MAAK;KAAG;KAAO;KAAK;IAC3F,QAAQ,QAAuB,SAAS;AACtC,YAAO,WAAW,EAAE;AACpB,YAAO,OAAO,UAAU,EAAE;AAC1B,YAAO,OAAO,MAAM,KAAK;MACvB;MACA,KAAK,CACH,QAAQ,eAAe,OACvB;OACE,QAAQ;OACR,SAAS;OACV,CACF;MACF,CAAC;AAEF,YAAO,WAAW,UAAU,QAAQ,QAAQ,IAAI;;IAEnD;;EAEH,MAAM,eAAe;GACnB,MAAM,EAAE,oBAAoB,MAAM,OAAO,yBAAA,MAAA,MAAA,EAAA,EAAA;AACzC,UAAO,gBAAgB,EACrB,eAAe,KAAK,MACrB,CAAC;;EAEL"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../build-mdx-DhXGp7I9.js";
|
|
3
|
-
import { MDXCollection, MDXCollectionConfig } from "./mdx.js";
|
|
1
|
+
import { n as MDXCollectionConfig, t as MDXCollection } from "../mdx-BfaapI6d.js";
|
|
4
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
3
|
|
|
6
4
|
//#region src/collections/obsidian.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obsidian.d.ts","names":[],"sources":["../../src/collections/obsidian.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"obsidian.d.ts","names":[],"sources":["../../src/collections/obsidian.ts"],"mappings":";;;;KAKY,2BAAA,2BACgB,gBAAA,4BACxB,mBAAA,CAAoB,iBAAA;AAAA,iBAER,qBAAA,2BACY,gBAAA,yBAAA,CAC1B,MAAA,EAAQ,2BAAA,CAA4B,iBAAA,IAAkB,aAAA,CAAA,iBAAA"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { n as slash } from "../code-generator-
|
|
2
|
-
import "../validation-
|
|
1
|
+
import { n as slash } from "../code-generator-pLUE7Rk7.js";
|
|
2
|
+
import "../validation-Bf_v2L3p.js";
|
|
3
3
|
import { MDXCollection, mdxCollection } from "./mdx.js";
|
|
4
|
-
import { t as fumaMatter } from "../fuma-matter-
|
|
4
|
+
import { t as fumaMatter } from "../fuma-matter-E30PU53R.js";
|
|
5
|
+
import { t as flattenNode } from "../flatten-m0wfHxLH.js";
|
|
6
|
+
import { remarkInclude } from "../plugins/remark/include.js";
|
|
5
7
|
import { readFile } from "node:fs/promises";
|
|
6
8
|
import path from "node:path";
|
|
7
9
|
import { z } from "zod";
|
|
8
10
|
import { slug } from "github-slugger";
|
|
9
11
|
import { visit } from "unist-util-visit";
|
|
10
|
-
|
|
11
12
|
//#region src/collections/obsidian/schema.ts
|
|
12
13
|
const frontmatterSchema = z.object({ aliases: z.array(z.string()).optional() }).loose().optional();
|
|
13
|
-
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/collections/obsidian/build-storage.ts
|
|
16
16
|
/**
|
|
@@ -91,7 +91,6 @@ function normalize(filePath) {
|
|
|
91
91
|
if (filePath.startsWith("../")) throw new Error(`${filePath} points outside of vault folder`);
|
|
92
92
|
return filePath.startsWith("./") ? filePath.slice(2) : filePath;
|
|
93
93
|
}
|
|
94
|
-
|
|
95
94
|
//#endregion
|
|
96
95
|
//#region src/collections/obsidian/build-resolver.ts
|
|
97
96
|
function buildResolver(storage) {
|
|
@@ -123,48 +122,6 @@ function resolveInternalHref(href, sourceFile, resolver) {
|
|
|
123
122
|
const [name, hash] = href.split("#", 2);
|
|
124
123
|
return [resolver.resolveAny(name, sourceFile.path), hash];
|
|
125
124
|
}
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/utils/mdast/replace.ts
|
|
129
|
-
function replace(node, withObj) {
|
|
130
|
-
for (const k in node) delete node[k];
|
|
131
|
-
Object.assign(node, withObj);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/collections/obsidian/remark-block-id.ts
|
|
136
|
-
const Regex = /(?<!\\)\^(?<block_id>\w+)$/m;
|
|
137
|
-
function transformBlocks(tree) {
|
|
138
|
-
visit(tree, "paragraph", (node) => {
|
|
139
|
-
let id;
|
|
140
|
-
visit(node, [
|
|
141
|
-
"link",
|
|
142
|
-
"text",
|
|
143
|
-
"mdxJsxFlowElement"
|
|
144
|
-
], (textNode) => {
|
|
145
|
-
if (textNode.type !== "text") return "skip";
|
|
146
|
-
const value = textNode.value;
|
|
147
|
-
const match = Regex.exec(value);
|
|
148
|
-
if (!match) return false;
|
|
149
|
-
id = match[1];
|
|
150
|
-
textNode.value = value.slice(0, match.index).trimEnd() + value.slice(match.index + match[0].length);
|
|
151
|
-
return false;
|
|
152
|
-
}, true);
|
|
153
|
-
if (id) replace(node, {
|
|
154
|
-
type: "mdxJsxFlowElement",
|
|
155
|
-
name: "section",
|
|
156
|
-
attributes: [{
|
|
157
|
-
type: "mdxJsxAttribute",
|
|
158
|
-
name: "id",
|
|
159
|
-
value: `^${id}`
|
|
160
|
-
}],
|
|
161
|
-
children: [{ ...node }]
|
|
162
|
-
});
|
|
163
|
-
return "skip";
|
|
164
|
-
});
|
|
165
|
-
return tree;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
125
|
//#endregion
|
|
169
126
|
//#region src/utils/mdast/separate.ts
|
|
170
127
|
function separate(splitter, nodes) {
|
|
@@ -202,7 +159,6 @@ function separate(splitter, nodes) {
|
|
|
202
159
|
}
|
|
203
160
|
}
|
|
204
161
|
}
|
|
205
|
-
|
|
206
162
|
//#endregion
|
|
207
163
|
//#region src/utils/mdast/create.ts
|
|
208
164
|
function createCallout(type, title, children) {
|
|
@@ -227,7 +183,12 @@ function createCallout(type, title, children) {
|
|
|
227
183
|
}]
|
|
228
184
|
};
|
|
229
185
|
}
|
|
230
|
-
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/utils/mdast/replace.ts
|
|
188
|
+
function replace(node, withObj) {
|
|
189
|
+
for (const k in node) delete node[k];
|
|
190
|
+
Object.assign(node, withObj);
|
|
191
|
+
}
|
|
231
192
|
//#endregion
|
|
232
193
|
//#region src/collections/obsidian/get-refs.ts
|
|
233
194
|
function getFileHref(ref, sourceFile, heading) {
|
|
@@ -241,73 +202,8 @@ function getFileHref(ref, sourceFile, heading) {
|
|
|
241
202
|
function getHeadingHash(heading) {
|
|
242
203
|
return heading.startsWith("^") ? heading : slug(heading);
|
|
243
204
|
}
|
|
244
|
-
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/collections/obsidian/remark-convert.ts
|
|
247
|
-
const RegexCalloutHead = /^\[!(?<type>\w+)](?<collapsible>\+)?/;
|
|
248
|
-
function resolveCallout(node) {
|
|
249
|
-
const head = node.children[0];
|
|
250
|
-
if (!head || head.type !== "paragraph") return;
|
|
251
|
-
const textNode = head.children[0];
|
|
252
|
-
if (!textNode || textNode.type !== "text") return;
|
|
253
|
-
const match = RegexCalloutHead.exec(textNode.value);
|
|
254
|
-
if (!match) return;
|
|
255
|
-
textNode.value = textNode.value.slice(match[0].length).trimStart();
|
|
256
|
-
const [title, rest] = separate(/\r?\n/, head.children) ?? [head.children];
|
|
257
|
-
const body = node.children.slice(1);
|
|
258
|
-
if (rest) body.unshift({
|
|
259
|
-
type: "paragraph",
|
|
260
|
-
children: rest
|
|
261
|
-
});
|
|
262
|
-
return createCallout(match[1], [{
|
|
263
|
-
type: "paragraph",
|
|
264
|
-
children: title
|
|
265
|
-
}], body);
|
|
266
|
-
}
|
|
267
|
-
function transform(tree, sourceFile, resolver) {
|
|
268
|
-
visit(tree, [
|
|
269
|
-
"blockquote",
|
|
270
|
-
"link",
|
|
271
|
-
"image"
|
|
272
|
-
], (node) => {
|
|
273
|
-
if (node.type === "blockquote") {
|
|
274
|
-
const callout = resolveCallout(node);
|
|
275
|
-
if (callout) replace(node, callout);
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (node.type === "link" || node.type === "image") {
|
|
279
|
-
if (node.type === "link" && node.data?.isWikiLink) return "skip";
|
|
280
|
-
const url = decodeURI(node.url);
|
|
281
|
-
if (node.type === "link" && url.startsWith("#")) node.url = `#${getHeadingHash(url.slice(1))}`;
|
|
282
|
-
else {
|
|
283
|
-
const [ref, heading] = resolveInternalHref(url, sourceFile, resolver);
|
|
284
|
-
if (!ref) return "skip";
|
|
285
|
-
node.url = getFileHref(ref, sourceFile, heading);
|
|
286
|
-
}
|
|
287
|
-
return "skip";
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
return tree;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
205
|
//#endregion
|
|
294
|
-
//#region src/collections/obsidian/
|
|
295
|
-
const RegexDelimiter = /(?<!\\)%%/;
|
|
296
|
-
function removeComment(tree) {
|
|
297
|
-
function remove(nodes) {
|
|
298
|
-
const start = separate(RegexDelimiter, nodes);
|
|
299
|
-
if (!start) return nodes;
|
|
300
|
-
const [before, rest] = start;
|
|
301
|
-
const end = separate(RegexDelimiter, rest);
|
|
302
|
-
if (!end) return nodes;
|
|
303
|
-
return [...before, ...remove(end[1])];
|
|
304
|
-
}
|
|
305
|
-
tree.children = remove(tree.children);
|
|
306
|
-
return tree;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
//#endregion
|
|
310
|
-
//#region src/collections/obsidian/remark-wikilinks.ts
|
|
206
|
+
//#region src/collections/obsidian/utils/wikilinks.ts
|
|
311
207
|
const RegexWikilink = /!?\[\[(?<content>([^\]]|\\])+)]]/g;
|
|
312
208
|
const RegexContent = /^(?<name>(?:\\#|\\\||[^#|])*)(?:#(?<heading>(?:\\\||[^|])+))?(?:\|(?<alias>.+))?$/;
|
|
313
209
|
function transformWikilinks(tree, sourceFile, resolver) {
|
|
@@ -433,11 +329,151 @@ function resolveWikilink(isEmbed, content, sourceFile, resolver) {
|
|
|
433
329
|
}]
|
|
434
330
|
};
|
|
435
331
|
}
|
|
436
|
-
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/collections/obsidian/utils/blocks.ts
|
|
334
|
+
const Regex = /(?<!\\)\^(?<block_id>\w+)$/m;
|
|
335
|
+
function transformBlocks(tree) {
|
|
336
|
+
visit(tree, "paragraph", (node) => {
|
|
337
|
+
let id;
|
|
338
|
+
visit(node, [
|
|
339
|
+
"link",
|
|
340
|
+
"text",
|
|
341
|
+
"mdxJsxFlowElement"
|
|
342
|
+
], (textNode) => {
|
|
343
|
+
if (textNode.type !== "text") return "skip";
|
|
344
|
+
const value = textNode.value;
|
|
345
|
+
const match = Regex.exec(value);
|
|
346
|
+
if (!match) return false;
|
|
347
|
+
id = match[1];
|
|
348
|
+
textNode.value = value.slice(0, match.index).trimEnd() + value.slice(match.index + match[0].length);
|
|
349
|
+
return false;
|
|
350
|
+
}, true);
|
|
351
|
+
if (id) replace(node, {
|
|
352
|
+
type: "mdxJsxFlowElement",
|
|
353
|
+
name: "section",
|
|
354
|
+
attributes: [{
|
|
355
|
+
type: "mdxJsxAttribute",
|
|
356
|
+
name: "id",
|
|
357
|
+
value: `^${id}`
|
|
358
|
+
}],
|
|
359
|
+
children: [{ ...node }]
|
|
360
|
+
});
|
|
361
|
+
return "skip";
|
|
362
|
+
});
|
|
363
|
+
return tree;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/collections/obsidian/utils/transform.ts
|
|
367
|
+
const RegexCalloutHead = /^\[!(?<type>\w+)](?<collapsible>\+)?/;
|
|
368
|
+
function resolveCallout(node) {
|
|
369
|
+
const head = node.children[0];
|
|
370
|
+
if (!head || head.type !== "paragraph") return;
|
|
371
|
+
const textNode = head.children[0];
|
|
372
|
+
if (!textNode || textNode.type !== "text") return;
|
|
373
|
+
const match = RegexCalloutHead.exec(textNode.value);
|
|
374
|
+
if (!match) return;
|
|
375
|
+
textNode.value = textNode.value.slice(match[0].length).trimStart();
|
|
376
|
+
const [title, rest] = separate(/\r?\n/, head.children) ?? [head.children];
|
|
377
|
+
const body = node.children.slice(1);
|
|
378
|
+
if (rest) body.unshift({
|
|
379
|
+
type: "paragraph",
|
|
380
|
+
children: rest
|
|
381
|
+
});
|
|
382
|
+
return createCallout(match[1], [{
|
|
383
|
+
type: "paragraph",
|
|
384
|
+
children: title
|
|
385
|
+
}], body);
|
|
386
|
+
}
|
|
387
|
+
function transform(tree, sourceFile, resolver) {
|
|
388
|
+
visit(tree, "heading", (node) => {
|
|
389
|
+
node.data ??= {};
|
|
390
|
+
node.data.hProperties ??= {};
|
|
391
|
+
node.data.hProperties.id ??= slug(flattenNode(node));
|
|
392
|
+
return "skip";
|
|
393
|
+
});
|
|
394
|
+
tree = transformWikilinks(tree, sourceFile, resolver);
|
|
395
|
+
visit(tree, [
|
|
396
|
+
"blockquote",
|
|
397
|
+
"link",
|
|
398
|
+
"image"
|
|
399
|
+
], (node) => {
|
|
400
|
+
if (node.type === "blockquote") {
|
|
401
|
+
const callout = resolveCallout(node);
|
|
402
|
+
if (callout) replace(node, callout);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (node.type === "link" || node.type === "image") {
|
|
406
|
+
if (node.type === "link" && node.data?.isWikiLink) return "skip";
|
|
407
|
+
const url = decodeURI(node.url);
|
|
408
|
+
if (node.type === "link" && url.startsWith("#")) node.url = `#${getHeadingHash(url.slice(1))}`;
|
|
409
|
+
else {
|
|
410
|
+
const [ref, heading] = resolveInternalHref(url, sourceFile, resolver);
|
|
411
|
+
if (!ref) return "skip";
|
|
412
|
+
node.url = getFileHref(ref, sourceFile, heading);
|
|
413
|
+
}
|
|
414
|
+
return "skip";
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
tree = transformBlocks(tree);
|
|
418
|
+
return tree;
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/collections/obsidian/utils/micromark-comments.ts
|
|
422
|
+
function percentCommentMicromark() {
|
|
423
|
+
return { text: { [37]: { tokenize: tokenizePercentComment } } };
|
|
424
|
+
}
|
|
425
|
+
const tokenizePercentComment = function(effects, ok, nok) {
|
|
426
|
+
const start = (code) => {
|
|
427
|
+
if (code !== 37) return nok(code);
|
|
428
|
+
if (this.previous === 92) return nok(code);
|
|
429
|
+
effects.enter("percentComment");
|
|
430
|
+
effects.enter("percentCommentMarker");
|
|
431
|
+
effects.consume(code);
|
|
432
|
+
return openSecondPercent;
|
|
433
|
+
};
|
|
434
|
+
function openSecondPercent(code) {
|
|
435
|
+
if (code !== 37) return nok(code);
|
|
436
|
+
effects.consume(code);
|
|
437
|
+
effects.exit("percentCommentMarker");
|
|
438
|
+
return inside;
|
|
439
|
+
}
|
|
440
|
+
function inside(code) {
|
|
441
|
+
if (code === null) return nok(code);
|
|
442
|
+
if (code === 37) {
|
|
443
|
+
effects.enter("percentCommentMarker");
|
|
444
|
+
effects.consume(code);
|
|
445
|
+
return closeSecondPercent;
|
|
446
|
+
}
|
|
447
|
+
effects.consume(code);
|
|
448
|
+
return inside;
|
|
449
|
+
}
|
|
450
|
+
function closeSecondPercent(code) {
|
|
451
|
+
if (code === 37) {
|
|
452
|
+
effects.consume(code);
|
|
453
|
+
effects.exit("percentCommentMarker");
|
|
454
|
+
effects.exit("percentComment");
|
|
455
|
+
return ok;
|
|
456
|
+
}
|
|
457
|
+
effects.exit("percentCommentMarker");
|
|
458
|
+
return inside(code);
|
|
459
|
+
}
|
|
460
|
+
return start;
|
|
461
|
+
};
|
|
462
|
+
function percentCommentFromMarkdown() {
|
|
463
|
+
return {
|
|
464
|
+
enter: { percentComment() {} },
|
|
465
|
+
exit: { percentComment() {} }
|
|
466
|
+
};
|
|
467
|
+
}
|
|
437
468
|
//#endregion
|
|
438
469
|
//#region src/collections/obsidian/remark-obsidian.ts
|
|
439
470
|
function remarkObsidian() {
|
|
440
471
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
472
|
+
const data = this.data();
|
|
473
|
+
const micromarkExtensions = data.micromarkExtensions ??= [];
|
|
474
|
+
const fromMarkdownExtensions = data.fromMarkdownExtensions ??= [];
|
|
475
|
+
micromarkExtensions.push(percentCommentMicromark());
|
|
476
|
+
fromMarkdownExtensions.push(percentCommentFromMarkdown());
|
|
441
477
|
return async (tree, file) => {
|
|
442
478
|
if (file.data._obsidian_transformed) return tree;
|
|
443
479
|
const compiler = file.data._compiler;
|
|
@@ -462,17 +498,13 @@ function remarkObsidian() {
|
|
|
462
498
|
const normalizedPath = normalize(path.relative(collection.dir, file.path));
|
|
463
499
|
const vault = storage.files.get(normalizedPath);
|
|
464
500
|
if (vault?.format === "content") {
|
|
465
|
-
tree = transformWikilinks(tree, vault, resolver);
|
|
466
501
|
tree = transform(tree, vault, resolver);
|
|
467
|
-
tree = removeComment(tree);
|
|
468
|
-
tree = transformBlocks(tree);
|
|
469
502
|
file.data._obsidian_transformed = true;
|
|
470
503
|
return tree;
|
|
471
504
|
}
|
|
472
505
|
return tree;
|
|
473
506
|
};
|
|
474
507
|
}
|
|
475
|
-
|
|
476
508
|
//#endregion
|
|
477
509
|
//#region src/collections/obsidian.ts
|
|
478
510
|
function mdxObsidianCollection(config) {
|
|
@@ -482,20 +514,25 @@ function mdxObsidianCollection(config) {
|
|
|
482
514
|
const base = typeof config.options === "function" ? await config.options?.(environment) : config.options;
|
|
483
515
|
return {
|
|
484
516
|
...base,
|
|
485
|
-
remarkPlugins: ({
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
517
|
+
remarkPlugins: ({ preprocess, postprocess }) => typeof base?.remarkPlugins === "function" ? base.remarkPlugins({
|
|
518
|
+
preprocess: [
|
|
519
|
+
remarkObsidian,
|
|
520
|
+
remarkInclude,
|
|
521
|
+
...preprocess
|
|
522
|
+
],
|
|
523
|
+
postprocess
|
|
524
|
+
}) : [
|
|
489
525
|
remarkObsidian,
|
|
490
526
|
remarkInclude,
|
|
527
|
+
...preprocess,
|
|
491
528
|
...base?.remarkPlugins ?? [],
|
|
492
|
-
|
|
529
|
+
...postprocess
|
|
493
530
|
]
|
|
494
531
|
};
|
|
495
532
|
}
|
|
496
533
|
});
|
|
497
534
|
}
|
|
498
|
-
|
|
499
535
|
//#endregion
|
|
500
536
|
export { mdxObsidianCollection };
|
|
537
|
+
|
|
501
538
|
//# sourceMappingURL=obsidian.js.map
|