diff --git a/.cspell.json b/.cspell.json index f55f6265d1..efddcf2a00 100644 --- a/.cspell.json +++ b/.cspell.json @@ -23,6 +23,7 @@ "CHANGELOG.md", "patches", "packages/docusaurus-theme-translations/locales", + "packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy", "package.json", "yarn.lock", "project-words.txt", diff --git a/.eslintignore b/.eslintignore index 6273a95b15..6aa6a0b9f8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -22,3 +22,6 @@ packages/create-docusaurus/templates/facebook website/_dogfooding/_swizzle_theme_tests website/_dogfooding/_asset-tests/badSyntax.js + + +packages/docusaurus-plugin-ideal-image/src/theme/IdealImageLegacy diff --git a/.eslintrc.js b/.eslintrc.js index 17eff79121..502c615068 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -298,7 +298,7 @@ module.exports = { 'jest/expect-expect': OFF, 'jest/no-large-snapshots': [ WARNING, - {maxSize: Infinity, inlineMaxSize: 10}, + {maxSize: Infinity, inlineMaxSize: 50}, ], 'jest/no-test-return-statement': ERROR, 'jest/prefer-expect-resolves': WARNING, diff --git a/.github/workflows/argos.yml b/.github/workflows/argos.yml index 4493405645..f075231358 100644 --- a/.github/workflows/argos.yml +++ b/.github/workflows/argos.yml @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* diff --git a/.github/workflows/build-blog-only.yml b/.github/workflows/build-blog-only.yml index 71ae7a80b2..afc9ba0fba 100644 --- a/.github/workflows/build-blog-only.yml +++ b/.github/workflows/build-blog-only.yml @@ -24,7 +24,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/build-hash-router.yml b/.github/workflows/build-hash-router.yml index 7ac7d8b148..3c4fd35aca 100644 --- a/.github/workflows/build-hash-router.yml +++ b/.github/workflows/build-hash-router.yml @@ -27,7 +27,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/build-perf.yml b/.github/workflows/build-perf.yml index 4c98263b91..933de79985 100644 --- a/.github/workflows/build-perf.yml +++ b/.github/workflows/build-perf.yml @@ -43,7 +43,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn @@ -75,7 +75,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/canary-release.yml b/.github/workflows/canary-release.yml index 37d935ef5d..e29dfcd332 100644 --- a/.github/workflows/canary-release.yml +++ b/.github/workflows/canary-release.yml @@ -24,7 +24,7 @@ jobs: with: fetch-depth: 0 # Needed to get the commit number with "git rev-list --count HEAD" - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/continuous-releases.yml b/.github/workflows/continuous-releases.yml index c6510df788..cb892c445a 100644 --- a/.github/workflows/continuous-releases.yml +++ b/.github/workflows/continuous-releases.yml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index c25f347e7d..872531af0a 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -15,4 +15,4 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Dependency Review - uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # 4.5.0 + uses: actions/dependency-review-action@ce3cf9537a52e8119d91fd484ab5b8a807627bf8 # 4.6.0 diff --git a/.github/workflows/lighthouse-report.yml b/.github/workflows/lighthouse-report.yml index 0f30f8e391..3e268ccafa 100644 --- a/.github/workflows/lighthouse-report.yml +++ b/.github/workflows/lighthouse-report.yml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d7891556f4..1a7d6abded 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,7 +22,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/showcase-test.yml b/.github/workflows/showcase-test.yml index e2deffb053..fa852b42c7 100644 --- a/.github/workflows/showcase-test.yml +++ b/.github/workflows/showcase-test.yml @@ -24,7 +24,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 7428d65a84..58d6c3e42a 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -43,7 +43,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: ${{ matrix.node }} cache: yarn @@ -84,7 +84,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js LTS - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn @@ -153,7 +153,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js LTS - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn @@ -193,7 +193,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js LTS - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/tests-swizzle.yml b/.github/workflows/tests-swizzle.yml index 28bd4988c6..a6afccc8bc 100644 --- a/.github/workflows/tests-swizzle.yml +++ b/.github/workflows/tests-swizzle.yml @@ -28,7 +28,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Node LTS - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: lts/* cache: yarn diff --git a/.github/workflows/tests-windows.yml b/.github/workflows/tests-windows.yml index 5607646e12..e8fe11cc51 100644 --- a/.github/workflows/tests-windows.yml +++ b/.github/workflows/tests-windows.yml @@ -34,7 +34,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: ${{ matrix.node }} - name: Installation diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 11a99731b8..ee5776a1a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,7 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0 with: node-version: ${{ matrix.node }} cache: yarn diff --git a/.gitignore b/.gitignore index 51636c8c18..d44178396a 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ website/i18n/**/* #!website/i18n/fr/**/* .netlify + +website/rspack-tracing.json +website/bundler-cpu-profile.json diff --git a/admin/scripts/resizeImage.js b/admin/scripts/resizeImage.js index 59baff0de3..09bf4f4ee5 100644 --- a/admin/scripts/resizeImage.js +++ b/admin/scripts/resizeImage.js @@ -9,9 +9,9 @@ import fs from 'fs-extra'; import path from 'path'; import {fileURLToPath} from 'url'; import {program} from 'commander'; -import logger from '@docusaurus/logger'; +import {logger} from '@docusaurus/logger'; import sharp from 'sharp'; -import imageSize from 'image-size'; +import {imageSizeFromFile} from 'image-size/fromFile'; // You can use it as: // @@ -64,7 +64,7 @@ program await Promise.all( images.map(async (imgPath) => { - const {width, height} = imageSize(imgPath); + const {width, height} = await imageSizeFromFile(imgPath); const targetWidth = options.width ?? (imgPath.includes(showcasePath) ? 640 : 1000); const targetHeight = diff --git a/package.json b/package.json index ceb6c4a189..73dc95d848 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "scripts": { "start": "yarn build:packages && yarn start:website", "start:website": "yarn workspace website start", + "start:website:profile": "DOCUSAURUS_BUNDLER_CPU_PROFILE=true DOCUSAURUS_RSPACK_TRACE=true yarn workspace website start", "start:website:baseUrl": "yarn workspace website start:baseUrl", "start:website:blogOnly": "yarn workspace website start:blogOnly", "start:website:deployPreview": "cross-env NETLIFY=true CONTEXT='deploy-preview' yarn workspace website start", @@ -22,6 +23,7 @@ "build": "yarn build:packages && yarn build:website", "build:packages": "lerna run build --no-private", "build:website": "yarn workspace website build", + "build:website:profile": "DOCUSAURUS_BUNDLER_CPU_PROFILE=true DOCUSAURUS_RSPACK_TRACE=true yarn workspace website build", "build:website:baseUrl": "yarn workspace website build:baseUrl", "build:website:blogOnly": "yarn workspace website build:blogOnly", "build:website:deployPreview:testWrap": "yarn workspace website test:swizzle:wrap:ts", @@ -102,7 +104,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-regexp": "^1.15.0", "husky": "^8.0.3", - "image-size": "^1.0.2", + "image-size": "^2.0.2", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jest-serializer-ansi-escapes": "^3.0.0", diff --git a/packages/docusaurus-faster/package.json b/packages/docusaurus-faster/package.json index cd99577359..9bf846fbad 100644 --- a/packages/docusaurus-faster/package.json +++ b/packages/docusaurus-faster/package.json @@ -19,7 +19,7 @@ "license": "MIT", "dependencies": { "@docusaurus/types": "3.7.0", - "@rspack/core": "^1.2.5", + "@rspack/core": "^1.3.3", "@swc/core": "^1.7.39", "@swc/html": "^1.7.39", "browserslist": "^4.24.2", diff --git a/packages/docusaurus-faster/src/index.ts b/packages/docusaurus-faster/src/index.ts index cba2c68730..ba0b2ae8c9 100644 --- a/packages/docusaurus-faster/src/index.ts +++ b/packages/docusaurus-faster/src/index.ts @@ -11,6 +11,16 @@ import browserslist from 'browserslist'; import {minify as swcHtmlMinifier} from '@swc/html'; import type {JsMinifyOptions, Options as SwcOptions} from '@swc/core'; +// See https://rspack.dev/contribute/development/profiling +// File can be opened with https://ui.perfetto.dev/ +if (process.env.DOCUSAURUS_RSPACK_TRACE) { + Rspack.experiments.globalTrace.register( + 'trace', + 'chrome', + './rspack-tracing.json', + ); +} + export const swcLoader = require.resolve('swc-loader'); export const getSwcLoaderOptions = ({ diff --git a/packages/docusaurus-mdx-loader/package.json b/packages/docusaurus-mdx-loader/package.json index fa135a39f1..3c2e7cb9d3 100644 --- a/packages/docusaurus-mdx-loader/package.json +++ b/packages/docusaurus-mdx-loader/package.json @@ -27,7 +27,7 @@ "estree-util-value-to-estree": "^3.0.1", "file-loader": "^6.2.0", "fs-extra": "^11.1.1", - "image-size": "^1.0.2", + "image-size": "^2.0.2", "mdast-util-mdx": "^3.0.0", "mdast-util-to-string": "^4.0.0", "rehype-raw": "^7.0.0", diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/utils.test.ts b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/utils.test.ts new file mode 100644 index 0000000000..32592d89fa --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/utils.test.ts @@ -0,0 +1,126 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {toHeadingHTMLValue} from '../utils'; +import type {Heading} from 'mdast'; + +describe('toHeadingHTMLValue', () => { + async function convert(heading: Heading): Promise { + const {toString} = await import('mdast-util-to-string'); + return toHeadingHTMLValue(heading, toString); + } + + it('converts a simple heading', async () => { + const heading: Heading = { + type: 'heading', + depth: 2, + children: [ + { + type: 'text', + value: 'Some heading text', + }, + ], + }; + + await expect(convert(heading)).resolves.toMatchInlineSnapshot( + `"Some heading text"`, + ); + }); + + it('converts a heading with b tag', async () => { + const heading: Heading = { + type: 'heading', + depth: 2, + children: [ + { + type: 'mdxJsxTextElement', + name: 'b', + attributes: [], + children: [ + { + type: 'text', + value: 'Some title', + }, + ], + }, + ], + }; + + await expect(convert(heading)).resolves.toMatchInlineSnapshot( + `"Some title"`, + ); + }); + + it('converts a heading with span tag + className', async () => { + const heading: Heading = { + type: 'heading', + depth: 2, + children: [ + { + type: 'mdxJsxTextElement', + name: 'span', + attributes: [ + { + type: 'mdxJsxAttribute', + name: 'className', + value: 'my-class', + }, + ], + children: [ + { + type: 'text', + value: 'Some title', + }, + ], + }, + ], + }; + + await expect(convert(heading)).resolves.toMatchInlineSnapshot( + `"Some title"`, + ); + }); + + it('converts a heading - remove img tag', async () => { + const heading: Heading = { + type: 'heading', + depth: 2, + children: [ + { + type: 'mdxJsxTextElement', + name: 'img', + attributes: [ + { + type: 'mdxJsxAttribute', + name: 'src', + value: '/img/slash-introducing.svg', + }, + { + type: 'mdxJsxAttribute', + name: 'height', + value: '32', + }, + { + type: 'mdxJsxAttribute', + name: 'alt', + value: 'test', + }, + ], + children: [], + }, + { + type: 'text', + value: ' Some title', + }, + ], + }; + + await expect(convert(heading)).resolves.toMatchInlineSnapshot( + `"Some title"`, + ); + }); +}); diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/utils.ts b/packages/docusaurus-mdx-loader/src/remark/toc/utils.ts index 59e860119f..b8200c6e48 100644 --- a/packages/docusaurus-mdx-loader/src/remark/toc/utils.ts +++ b/packages/docusaurus-mdx-loader/src/remark/toc/utils.ts @@ -5,9 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -import {toValue} from '../utils'; -import type {Node} from 'unist'; -import type {MdxjsEsm} from 'mdast-util-mdx'; +import escapeHtml from 'escape-html'; +import type {Node, Parent} from 'unist'; +import type { + MdxjsEsm, + MdxJsxAttribute, + MdxJsxTextElement, +} from 'mdast-util-mdx'; import type {TOCHeading, TOCItem, TOCItems, TOCSlice} from './types'; import type { Program, @@ -15,6 +19,7 @@ import type { ImportDeclaration, ImportSpecifier, } from 'estree'; +import type {Heading, PhrasingContent} from 'mdast'; export function getImportDeclarations(program: Program): ImportDeclaration[] { return program.body.filter( @@ -118,7 +123,7 @@ export async function createTOCExportNodeAST({ const {toString} = await import('mdast-util-to-string'); const {valueToEstree} = await import('estree-util-value-to-estree'); const value: TOCItem = { - value: toValue(heading, toString), + value: toHeadingHTMLValue(heading, toString), id: heading.data!.id!, level: heading.depth, }; @@ -172,3 +177,73 @@ export async function createTOCExportNodeAST({ }, }; } + +function stringifyChildren( + node: Parent, + toString: (param: unknown) => string, // TODO temporary, due to ESM +): string { + return (node.children as PhrasingContent[]) + .map((item) => toHeadingHTMLValue(item, toString)) + .join('') + .trim(); +} + +// TODO This is really a workaround, and not super reliable +// For now we only support serializing tagName, className and content +// Can we implement the TOC with real JSX nodes instead of html strings later? +function mdxJsxTextElementToHtml( + element: MdxJsxTextElement, + toString: (param: unknown) => string, // TODO temporary, due to ESM +): string { + const tag = element.name; + + // See https://github.com/facebook/docusaurus/issues/11003#issuecomment-2733925363 + if (tag === 'img') { + return ''; + } + + const attributes = element.attributes.filter( + (child): child is MdxJsxAttribute => child.type === 'mdxJsxAttribute', + ); + + const classAttribute = + attributes.find((attr) => attr.name === 'className') ?? + attributes.find((attr) => attr.name === 'class'); + + const classAttributeString = classAttribute + ? `class="${escapeHtml(String(classAttribute.value))}"` + : ``; + + const allAttributes = classAttributeString ? ` ${classAttributeString}` : ''; + + const content = stringifyChildren(element, toString); + + return `<${tag}${allAttributes}>${content}`; +} + +export function toHeadingHTMLValue( + node: PhrasingContent | Heading | MdxJsxTextElement, + toString: (param: unknown) => string, // TODO temporary, due to ESM +): string { + switch (node.type) { + case 'mdxJsxTextElement': { + return mdxJsxTextElementToHtml(node as MdxJsxTextElement, toString); + } + case 'text': + return escapeHtml(node.value); + case 'heading': + return stringifyChildren(node, toString); + case 'inlineCode': + return `${escapeHtml(node.value)}`; + case 'emphasis': + return `${stringifyChildren(node, toString)}`; + case 'strong': + return `${stringifyChildren(node, toString)}`; + case 'delete': + return `${stringifyChildren(node, toString)}`; + case 'link': + return stringifyChildren(node, toString); + default: + return toString(node); + } +} diff --git a/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts b/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts index a13bebf922..adf59a40ad 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts @@ -8,7 +8,6 @@ import path from 'path'; import url from 'url'; import fs from 'fs-extra'; -import {promisify} from 'util'; import { toMessageRelativeFilePath, posixPath, @@ -17,7 +16,7 @@ import { getFileLoaderUtils, } from '@docusaurus/utils'; import escapeHtml from 'escape-html'; -import sizeOf from 'image-size'; +import {imageSizeFromFile} from 'image-size/fromFile'; import logger from '@docusaurus/logger'; import {assetRequireAttributeValue, transformNode} from '../utils'; import type {Plugin, Transformer} from 'unified'; @@ -80,7 +79,7 @@ async function toImageRequireNode( } try { - const size = (await promisify(sizeOf)(imagePath))!; + const size = (await imageSizeFromFile(imagePath))!; if (size.width) { attributes.push({ type: 'mdxJsxAttribute', diff --git a/packages/docusaurus-mdx-loader/src/remark/utils/index.ts b/packages/docusaurus-mdx-loader/src/remark/utils/index.ts index e191bbfa2e..898f0617a4 100644 --- a/packages/docusaurus-mdx-loader/src/remark/utils/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/utils/index.ts @@ -5,14 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import escapeHtml from 'escape-html'; -import type {Parent, Node} from 'unist'; -import type {PhrasingContent, Heading} from 'mdast'; -import type { - MdxJsxAttribute, - MdxJsxAttributeValueExpression, - MdxJsxTextElement, -} from 'mdast-util-mdx'; +import type {Node} from 'unist'; +import type {MdxJsxAttributeValueExpression} from 'mdast-util-mdx'; /** * Util to transform one node type to another node type @@ -35,70 +29,6 @@ export function transformNode( return node as NewNode; } -export function stringifyContent( - node: Parent, - toString: (param: unknown) => string, // TODO weird but works -): string { - return (node.children as PhrasingContent[]) - .map((item) => toValue(item, toString)) - .join(''); -} - -// TODO This is really a workaround, and not super reliable -// For now we only support serializing tagName, className and content -// Can we implement the TOC with real JSX nodes instead of html strings later? -function mdxJsxTextElementToHtml( - element: MdxJsxTextElement, - toString: (param: unknown) => string, // TODO weird but works -): string { - const tag = element.name; - - const attributes = element.attributes.filter( - (child): child is MdxJsxAttribute => child.type === 'mdxJsxAttribute', - ); - - const classAttribute = - attributes.find((attr) => attr.name === 'className') ?? - attributes.find((attr) => attr.name === 'class'); - - const classAttributeString = classAttribute - ? `class="${escapeHtml(String(classAttribute.value))}"` - : ``; - - const allAttributes = classAttributeString ? ` ${classAttributeString}` : ''; - - const content = stringifyContent(element, toString); - - return `<${tag}${allAttributes}>${content}`; -} - -export function toValue( - node: PhrasingContent | Heading | MdxJsxTextElement, - toString: (param: unknown) => string, // TODO weird but works -): string { - switch (node.type) { - case 'mdxJsxTextElement': { - return mdxJsxTextElementToHtml(node as MdxJsxTextElement, toString); - } - case 'text': - return escapeHtml(node.value); - case 'heading': - return stringifyContent(node, toString); - case 'inlineCode': - return `${escapeHtml(node.value)}`; - case 'emphasis': - return `${stringifyContent(node, toString)}`; - case 'strong': - return `${stringifyContent(node, toString)}`; - case 'delete': - return `${stringifyContent(node, toString)}`; - case 'link': - return stringifyContent(node, toString); - default: - return toString(node); - } -} - export function assetRequireAttributeValue( requireString: string, hash: string, diff --git a/packages/docusaurus-module-type-aliases/package.json b/packages/docusaurus-module-type-aliases/package.json index 43fdebdcbf..a95d5742d7 100644 --- a/packages/docusaurus-module-type-aliases/package.json +++ b/packages/docusaurus-module-type-aliases/package.json @@ -17,7 +17,7 @@ "@types/react": "*", "@types/react-router-config": "*", "@types/react-router-dom": "*", - "react-helmet-async": "npm:@slorber/react-helmet-async@*", + "react-helmet-async": "npm:@slorber/react-helmet-async@1.3.0", "react-loadable": "npm:@docusaurus/react-loadable@6.0.0" }, "peerDependencies": { diff --git a/packages/docusaurus-plugin-content-blog/assets/atom.xsl b/packages/docusaurus-plugin-content-blog/assets/atom.xsl index 271895cf77..b4b2d9619c 100644 --- a/packages/docusaurus-plugin-content-blog/assets/atom.xsl +++ b/packages/docusaurus-plugin-content-blog/assets/atom.xsl @@ -71,7 +71,7 @@
-