This commit is contained in:
2026-01-19 19:13:27 +01:00
commit 9d0442e88f
4968 changed files with 1142016 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import { type Root } from 'mdast';
import { type Plugin } from 'unified';
import { define } from 'unist-util-mdx-define';
type FrontmatterParsers = Record<string, (value: string) => unknown>;
export interface RemarkMdxFrontmatterOptions extends define.Options {
/**
* The default value to export if no frontmatter data is found.
*
* @default undefined
*/
default?: unknown;
/**
* If specified, the YAML data is exported using this name. Otherwise, each
* object key will be used as an export name.
*/
name?: string;
/**
* A mapping of node types to parsers.
*
* Each key represents a frontmatter node type. The value is a function that accepts the
* frontmatter data as a string, and returns the parsed data.
*
* By default `yaml` nodes will be parsed using [`yaml`](https://github.com/eemeli/yaml) and
* `toml` nodes using [`toml`](https://github.com/BinaryMuse/toml-node).
*/
parsers?: FrontmatterParsers;
}
/**
* A remark plugin to expose frontmatter data as named exports.
*
* @param options
* Optional options to configure the output.
* @returns
* A unified transformer.
*/
declare const remarkMdxFrontmatter: Plugin<[RemarkMdxFrontmatterOptions?], Root>;
export default remarkMdxFrontmatter;
//# sourceMappingURL=remark-mdx-frontmatter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"remark-mdx-frontmatter.d.ts","sourceRoot":"","sources":["../src/remark-mdx-frontmatter.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,IAAI,EAAE,MAAM,OAAO,CAAA;AAE/C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAG9C,KAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAA;AAEpE,MAAM,WAAW,2BAA4B,SAAQ,MAAM,CAAC,OAAO;IACjE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAA;CAC7B;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,EAAE,MAAM,CAAC,CAAC,2BAA2B,CAAC,CAAC,EAAE,IAAI,CAwBtE,CAAA;AAED,eAAe,oBAAoB,CAAA"}

View File

@@ -0,0 +1,31 @@
import { valueToEstree } from 'estree-util-value-to-estree';
import { parse as parseToml } from 'toml';
import { define } from 'unist-util-mdx-define';
import { parse as parseYaml } from 'yaml';
/**
* A remark plugin to expose frontmatter data as named exports.
*
* @param options
* Optional options to configure the output.
* @returns
* A unified transformer.
*/
const remarkMdxFrontmatter = ({ name = 'frontmatter', parsers, ...options } = {}) => {
const allParsers = {
yaml: parseYaml,
toml: parseToml,
...parsers
};
return (ast, file) => {
let data = options.default;
const node = ast.children.find((child) => Object.hasOwn(allParsers, child.type));
if (node) {
const parser = allParsers[node.type];
const { value } = node;
data = parser(value);
}
define(ast, file, { [name]: valueToEstree(data, { preserveReferences: true }) }, options);
};
};
export default remarkMdxFrontmatter;
//# sourceMappingURL=remark-mdx-frontmatter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"remark-mdx-frontmatter.js","sourceRoot":"","sources":["../src/remark-mdx-frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAA;AA8BzC;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAiD,CAAC,EAC1E,IAAI,GAAG,aAAa,EACpB,OAAO,EACP,GAAG,OAAO,EACX,GAAG,EAAE,EAAE,EAAE;IACR,MAAM,UAAU,GAAuB;QACrC,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,SAAS;QACf,GAAG,OAAO;KACX,CAAA;IAED,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACnB,IAAI,IAAI,GAAG,OAAO,CAAC,OAAO,CAAA;QAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;QAEhF,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAEpC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAe,CAAA;YACjC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;QAED,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,IAAI,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC3F,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,oBAAoB,CAAA"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=remark-mdx-frontmatter.test.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"remark-mdx-frontmatter.test.d.ts","sourceRoot":"","sources":["../src/remark-mdx-frontmatter.test.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,21 @@
import { compile } from '@mdx-js/mdx';
import remarkFrontmatter from 'remark-frontmatter';
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
import { testFixturesDirectory } from 'snapshot-fixtures';
testFixturesDirectory({
directory: new URL('../fixtures', import.meta.url),
prettier: true,
write: true,
tests: {
'expected.jsx'(file, options) {
return compile(file, {
remarkPlugins: [
[remarkFrontmatter, ['yaml', 'toml']],
[remarkMdxFrontmatter, options]
],
jsx: true
});
}
}
});
//# sourceMappingURL=remark-mdx-frontmatter.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"remark-mdx-frontmatter.test.js","sourceRoot":"","sources":["../src/remark-mdx-frontmatter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAClD,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,qBAAqB,CAAC;IACpB,SAAS,EAAE,IAAI,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IAClD,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;IACX,KAAK,EAAE;QACL,cAAc,CAAC,IAAI,EAAE,OAAO;YAC1B,OAAO,OAAO,CAAC,IAAI,EAAE;gBACnB,aAAa,EAAE;oBACb,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;oBACrC,CAAC,oBAAoB,EAAE,OAAO,CAAC;iBAChC;gBACD,GAAG,EAAE,IAAI;aACV,CAAC,CAAA;QACJ,CAAC;KACF;CACF,CAAC,CAAA"}