"`,
- );
- });
-
- test('work with MDX Tabs', () => {
- const mdxString = `
-# title
-
-import Tabs from '@theme/Tabs';
-import TabItem from '@theme/TabItem';
-
-
-
- This is an apple 🍎
-
-
- This is an orange 🍊
-
-
-
-text
-
-
- `;
-
- // TODO this is not an ideal behavior!
- // There is a warning "Component TabItem was not imported, exported, or provided by MDXProvider as global scope"
- // Theme + MDX config should provide a list of React components to put in MDX scope
- expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
- `"
title
This is an apple 🍎
This is an orange 🍊
text
"`,
- );
- });
-
- test('work with MDX Tabs with ```mdx-code-block', () => {
- const mdxString = `
-# title
-
-import Tabs from '@theme/Tabs';
-import TabItem from '@theme/TabItem';
-
-\`\`\`mdx-code-block
-
-
- This is an apple 🍎
-
-
- This is an orange 🍊
-
-
-\`\`\`
-
-text
-
- `;
-
- // TODO bad behavior!
- // ```mdx-code-block should be unwrapped and inner MDX content should be evaluated
- expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(`
- "
title
<Tabs>
- <TabItem value="apple" label="Apple">
- This is an apple 🍎
- </TabItem>
- <TabItem value="orange" label="Orange">
- This is an orange 🍊
- </TabItem>
- </Tabs>
-
text
"
- `);
- });
-});
diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts
index c04956645cc8..3a028f45eccc 100644
--- a/packages/docusaurus-utils/src/index.ts
+++ b/packages/docusaurus-utils/src/index.ts
@@ -23,7 +23,6 @@ import {simpleHash, docuHash} from './hashUtils';
import {DEFAULT_PLUGIN_ID} from './constants';
export * from './constants';
-export * from './mdxUtils';
export * from './urlUtils';
export * from './tags';
export * from './markdownParser';
diff --git a/packages/docusaurus-utils/src/mdxUtils.ts b/packages/docusaurus-utils/src/mdxUtils.ts
deleted file mode 100644
index a8028896fc02..000000000000
--- a/packages/docusaurus-utils/src/mdxUtils.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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 React from 'react';
-import ReactDOMServer from 'react-dom/server';
-import MDX from '@mdx-js/runtime';
-import removeImports from 'remark-mdx-remove-imports';
-import removeExports from 'remark-mdx-remove-exports';
-
-/**
- * Transform mdx text to plain html text
- * Initially created to convert MDX blog posts to HTML for the RSS feed
- * without import/export nodes
- *
- * TODO not ideal implementation, won't work well with MDX elements!
- * TODO theme+global site config should be able to declare MDX comps in scope for rendering the RSS feeds
- * see also https://github.com/facebook/docusaurus/issues/4625
- */
-export function mdxToHtml(
- mdxStr: string,
- // TODO allow providing components/scope here, see https://github.com/mdx-js/mdx/tree/v1.6.13/packages/runtime
-): string {
- return ReactDOMServer.renderToString(
- React.createElement(MDX, {remarkPlugins: [removeImports, removeExports]}, [
- mdxStr,
- ]),
- );
-}
diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts
index 8b2fde09906f..916fe423ce12 100644
--- a/packages/docusaurus/src/commands/build.ts
+++ b/packages/docusaurus/src/commands/build.ts
@@ -176,7 +176,7 @@ async function buildLocale({
if (configureWebpack) {
clientConfig = applyConfigureWebpack(
- configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
+ configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
clientConfig,
false,
props.siteConfig.webpack?.jsLoader,
@@ -184,7 +184,7 @@ async function buildLocale({
);
serverConfig = applyConfigureWebpack(
- configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
+ configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
serverConfig,
true,
props.siteConfig.webpack?.jsLoader,
@@ -220,7 +220,8 @@ async function buildLocale({
if (!plugin.postBuild) {
return;
}
- await plugin.postBuild(props);
+ // The plugin may reference `this`. We manually bind it again to prevent any bugs.
+ await plugin.postBuild.call(plugin, props);
}),
);
diff --git a/yarn.lock b/yarn.lock
index 541254f101b7..fc0fe2e5ba44 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5863,6 +5863,17 @@ chardet@^0.7.0:
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
+cheerio-select@^1.5.0:
+ version "1.5.0"
+ resolved "https://registry.yarnpkg.com/cheerio-select/-/cheerio-select-1.5.0.tgz#faf3daeb31b17c5e1a9dabcee288aaf8aafa5823"
+ integrity sha512-qocaHPv5ypefh6YNxvnbABM07KMxExbtbfuJoIie3iZXX1ERwYmJcIiRrr9H05ucQP1k28dav8rpdDgjQd8drg==
+ dependencies:
+ css-select "^4.1.3"
+ css-what "^5.0.1"
+ domelementtype "^2.2.0"
+ domhandler "^4.2.0"
+ domutils "^2.7.0"
+
cheerio@^0.22.0:
version "0.22.0"
resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-0.22.0.tgz#a9baa860a3f9b595a6b81b1a86873121ed3a269e"
@@ -5885,6 +5896,19 @@ cheerio@^0.22.0:
lodash.reject "^4.4.0"
lodash.some "^4.4.0"
+cheerio@^1.0.0-rc.10:
+ version "1.0.0-rc.10"
+ resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.10.tgz#2ba3dcdfcc26e7956fc1f440e61d51c643379f3e"
+ integrity sha512-g0J0q/O6mW8z5zxQ3A8E8J1hUgp4SMOvEoW/x84OwyHKe/Zccz83PVT4y5Crcr530FV6NgmKI1qvGTKVl9XXVw==
+ dependencies:
+ cheerio-select "^1.5.0"
+ dom-serializer "^1.3.2"
+ domhandler "^4.2.0"
+ htmlparser2 "^6.1.0"
+ parse5 "^6.0.1"
+ parse5-htmlparser2-tree-adapter "^6.0.1"
+ tslib "^2.2.0"
+
chokidar@^3.0.2, chokidar@^3.4.0, chokidar@^3.4.2, chokidar@^3.5.2:
version "3.5.2"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75"
@@ -6864,7 +6888,7 @@ css-what@2.1:
resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.3.tgz#a6d7604573365fe74686c3f311c56513d88285f2"
integrity sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg==
-css-what@^5.1.0:
+css-what@^5.0.1, css-what@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-5.1.0.tgz#3f7b707aadf633baf62c2ceb8579b545bb40f7fe"
integrity sha512-arSMRWIIFY0hV8pIxZMEfmMI47Wj3R/aWpZDDxWYCPEiOMv6tfOrnpDtgxBYPEQD4V0Y/958+1TdC3iWTFcUPw==
@@ -7504,7 +7528,7 @@ dom-serializer@0:
domelementtype "^2.0.1"
entities "^2.0.0"
-dom-serializer@^1.0.1:
+dom-serializer@^1.0.1, dom-serializer@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-1.3.2.tgz#6206437d32ceefaec7161803230c7a20bc1b4d91"
integrity sha512-5c54Bk5Dw4qAxNOI1pFEizPSjVsx5+bpJKmL2kPn8JhBUq2q09tTCa3mjijun2NfK78NMouDYNMBkOrPZiS+ig==
@@ -7573,7 +7597,7 @@ domutils@^1.5.1:
dom-serializer "0"
domelementtype "1"
-domutils@^2.5.2, domutils@^2.8.0:
+domutils@^2.5.2, domutils@^2.7.0, domutils@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-2.8.0.tgz#4437def5db6e2d1f5d6ee859bd95ca7d02048135"
integrity sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==
@@ -14247,7 +14271,7 @@ parse-url@^6.0.0:
parse-path "^4.0.0"
protocols "^1.4.0"
-parse5-htmlparser2-tree-adapter@^6.0.0:
+parse5-htmlparser2-tree-adapter@^6.0.0, parse5-htmlparser2-tree-adapter@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz#2cdf9ad823321140370d4dbf5d3e92c7c8ddc6e6"
integrity sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA==
@@ -18089,7 +18113,7 @@ tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
-tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.1:
+tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.2.0, tslib@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
From 666c4eee84530b1925e4caa2b52c21225c10e87b Mon Sep 17 00:00:00 2001
From: Joshua Chen
Date: Sun, 23 Jan 2022 22:22:36 +0800
Subject: [PATCH 2/4] fix snaps
---
.../14/Happy-First-Birthday-Slash/index.html | 18 ++++++++++++++++++
.../build-snap/blog/archive/index.html | 18 ++++++++++++++++++
.../build-snap/blog/date-matter/index.html | 18 ++++++++++++++++++
.../blog/heading-as-title/index.html | 18 ++++++++++++++++++
.../h\303\251ll\303\264/index.html" | 18 ++++++++++++++++++
.../website/build-snap/blog/index.html | 19 +++++++++++++++++++
.../build-snap/blog/mdx-blog-post/index.html | 19 +++++++++++++++++++
.../blog/mdx-require-blog-post/index.html | 18 ++++++++++++++++++
.../build-snap/blog/simple/slug/index.html | 18 ++++++++++++++++++
.../build-snap/blog/tags/birthday/index.html | 18 ++++++++++++++++++
.../build-snap/blog/tags/complex/index.html | 18 ++++++++++++++++++
.../build-snap/blog/tags/date/index.html | 18 ++++++++++++++++++
.../website/build-snap/blog/tags/index.html | 18 ++++++++++++++++++
.../src/__tests__/feed.test.ts | 4 ++--
14 files changed, 238 insertions(+), 2 deletions(-)
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/archive/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/date-matter/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/heading-as-title/index.html
create mode 100644 "packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html"
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-blog-post/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/simple/slug/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/birthday/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/date/index.html
create mode 100644 packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/index.html
diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html
new file mode 100644
index 000000000000..b2b3453900bf
--- /dev/null
+++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/2018/12/14/Happy-First-Birthday-Slash/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+Happy 1st Birthday Slash! | My Site
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html" "b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html"
new file mode 100644
index 000000000000..a32aabe301ad
--- /dev/null
+++ "b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/hey/my super path/h\303\251ll\303\264/index.html"
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+Complex Slug | My Site
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html
new file mode 100644
index 000000000000..f34484b91730
--- /dev/null
+++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/mdx-require-blog-post/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+MDX Blog Sample with require calls | My Site
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/birthday/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/birthday/index.html
new file mode 100644
index 000000000000..f9820c0f210a
--- /dev/null
+++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/birthday/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+One post tagged with "birthday" | My Site
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html
new file mode 100644
index 000000000000..c8b5017f1a44
--- /dev/null
+++ b/packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/build-snap/blog/tags/complex/index.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+One post tagged with "complex" | My Site
+
+
+
+
+