Fix remarkMdxish performance issue on huge sites (#3572)

This commit is contained in:
hippotastic 2022-06-11 00:32:23 +02:00 committed by GitHub
parent 43dda86ce2
commit 5c73f614e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': patch
---
Fix remarkMdxish performance issue on huge sites

View file

@ -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] = []);