Fix remarkMdxish performance issue on huge sites (#3572)
This commit is contained in:
parent
43dda86ce2
commit
5c73f614e8
2 changed files with 14 additions and 4 deletions
5
.changeset/proud-forks-hammer.md
Normal file
5
.changeset/proud-forks-hammer.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/markdown-remark': patch
|
||||
---
|
||||
|
||||
Fix remarkMdxish performance issue on huge sites
|
|
@ -3,12 +3,17 @@ import type { Tag } from 'mdast-util-mdx-jsx';
|
|||
import { mdxFromMarkdown, mdxToMarkdown } from './mdast-util-mdxish.js';
|
||||
import { mdxjs } from './mdxjs.js';
|
||||
|
||||
export default function remarkMdxish(this: any, options = {}) {
|
||||
// Prepare markdown extensions once to prevent performance issues
|
||||
const extMdxJs = mdxjs({});
|
||||
const extMdxFromMarkdown = makeFromMarkdownLessStrict(mdxFromMarkdown());
|
||||
const extMdxToMarkdown = mdxToMarkdown();
|
||||
|
||||
export default function remarkMdxish(this: any) {
|
||||
const data = this.data();
|
||||
|
||||
add('micromarkExtensions', mdxjs(options));
|
||||
add('fromMarkdownExtensions', makeFromMarkdownLessStrict(mdxFromMarkdown()));
|
||||
add('toMarkdownExtensions', mdxToMarkdown());
|
||||
add('micromarkExtensions', extMdxJs);
|
||||
add('fromMarkdownExtensions', extMdxFromMarkdown);
|
||||
add('toMarkdownExtensions', extMdxToMarkdown);
|
||||
|
||||
function add(field: string, value: unknown) {
|
||||
const list = data[field] ? data[field] : (data[field] = []);
|
||||
|
|
Loading…
Reference in a new issue