mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 20:27:20 +02:00
feat(content-blog): add full blog post html into RSS/Atom feeds (#4330)
Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
198590446a
commit
6ed698976d
15 changed files with 377 additions and 18 deletions
|
@ -0,0 +1,6 @@
|
|||
import React from 'react';
|
||||
|
||||
export const Typography: React.FC = (props) => {
|
||||
return <p>{props.children}</p>
|
||||
}
|
||||
Typography.displayName = 'Typography'
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
title: Full Blog Sample
|
||||
date: 2021-03-05
|
||||
---
|
||||
|
||||
<h1>HTML Heading 1</h1>
|
||||
<h2>HTML Heading 2</h2>
|
||||
<p>HTML Paragraph</p>
|
||||
|
||||
import Typography from '../../component/Typography'
|
||||
|
||||
<Typography>Import DOM</Typography>
|
||||
|
||||
# Heading 1
|
||||
|
||||
## Heading 2
|
||||
|
||||
### Heading 3
|
||||
|
||||
#### Heading 4
|
||||
|
||||
##### Heading 5
|
||||
|
||||
- list1
|
||||
- list2
|
||||
- list3
|
||||
|
||||
|
||||
* list1
|
||||
* list2
|
||||
* list3
|
||||
|
||||
Normal Text *Italics Text* **Bold Text**
|
||||
|
||||
[link](https://v2.docusaurus.io/)
|
||||

|
|
@ -7,18 +7,28 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<feed xmlns=\\"http://www.w3.org/2005/Atom\\">
|
||||
<id>https://docusaurus.io/myBaseUrl/blog</id>
|
||||
<title>Hello Blog</title>
|
||||
<updated>2020-08-16T00:00:00.000Z</updated>
|
||||
<updated>2021-03-05T00:00:00.000Z</updated>
|
||||
<generator>https://github.com/jpmonette/feed</generator>
|
||||
<link rel=\\"alternate\\" href=\\"https://docusaurus.io/myBaseUrl/blog\\"/>
|
||||
<subtitle>Hello Blog</subtitle>
|
||||
<icon>https://docusaurus.io/myBaseUrl/image/favicon.ico</icon>
|
||||
<rights>Copyright</rights>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[Full Blog Sample]]></title>
|
||||
<id>Full Blog Sample</id>
|
||||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/mdx-blog-post\\"/>
|
||||
<updated>2021-03-05T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[HTML Heading 1]]></summary>
|
||||
<content type=\\"html\\"><![CDATA[<h1>HTML Heading 1</h1><h2>HTML Heading 2</h2><p>HTML Paragraph</p><div>Import DOM</div><h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><ul><li>list1</li><li>list2</li><li>list3</li></ul><ul><li>list1</li><li>list2</li><li>list3</li></ul><p>Normal Text <em>Italics Text</em> <strong>Bold Text</strong></p><p><a href=\\"https://v2.docusaurus.io/\\">link</a>
|
||||
<img src=\\"https://v2.docusaurus.io/\\" alt=\\"image\\"/></p>]]></content>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[Complex Slug]]></title>
|
||||
<id>/hey/my super path/héllô</id>
|
||||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô\\"/>
|
||||
<updated>2020-08-16T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[complex url slug]]></summary>
|
||||
<content type=\\"html\\"><![CDATA[<p>complex url slug</p>]]></content>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[Simple Slug]]></title>
|
||||
|
@ -26,6 +36,7 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/simple/slug\\"/>
|
||||
<updated>2020-08-15T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[simple url slug]]></summary>
|
||||
<content type=\\"html\\"><![CDATA[<p>simple url slug</p>]]></content>
|
||||
<author>
|
||||
<name>Sébastien Lorber</name>
|
||||
<uri>https://sebastienlorber.com</uri>
|
||||
|
@ -37,6 +48,7 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/draft\\"/>
|
||||
<updated>2020-02-27T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[this post should not be published yet]]></summary>
|
||||
<content type=\\"html\\"><![CDATA[<p>this post should not be published yet</p>]]></content>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[some heading]]></title>
|
||||
|
@ -50,6 +62,7 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/date-matter\\"/>
|
||||
<updated>2019-01-01T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[date inside front matter]]></summary>
|
||||
<content type=\\"html\\"><![CDATA[<p>date inside front matter</p>]]></content>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
|
||||
|
@ -57,6 +70,7 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/2018/12/14/Happy-First-Birthday-Slash\\"/>
|
||||
<updated>2018-12-14T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[Happy birthday! (translated)]]></summary>
|
||||
<content type=\\"html\\"><![CDATA[<p>Happy birthday! (translated)</p>]]></content>
|
||||
<author>
|
||||
<name>Yangshun Tay (translated)</name>
|
||||
</author>
|
||||
|
@ -71,21 +85,31 @@ exports[`blogFeed rss should not show feed without posts 1`] = `null`;
|
|||
|
||||
exports[`blogFeed rss shows feed item for each post 1`] = `
|
||||
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
|
||||
<rss version=\\"2.0\\">
|
||||
<rss version=\\"2.0\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\">
|
||||
<channel>
|
||||
<title>Hello Blog</title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog</link>
|
||||
<description>Hello Blog</description>
|
||||
<lastBuildDate>Sun, 16 Aug 2020 00:00:00 GMT</lastBuildDate>
|
||||
<lastBuildDate>Fri, 05 Mar 2021 00:00:00 GMT</lastBuildDate>
|
||||
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
|
||||
<generator>https://github.com/jpmonette/feed</generator>
|
||||
<copyright>Copyright</copyright>
|
||||
<item>
|
||||
<title><![CDATA[Full Blog Sample]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/mdx-blog-post</link>
|
||||
<guid>Full Blog Sample</guid>
|
||||
<pubDate>Fri, 05 Mar 2021 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[HTML Heading 1]]></description>
|
||||
<content:encoded><![CDATA[<h1>HTML Heading 1</h1><h2>HTML Heading 2</h2><p>HTML Paragraph</p><div>Import DOM</div><h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><ul><li>list1</li><li>list2</li><li>list3</li></ul><ul><li>list1</li><li>list2</li><li>list3</li></ul><p>Normal Text <em>Italics Text</em> <strong>Bold Text</strong></p><p><a href=\\"https://v2.docusaurus.io/\\">link</a>
|
||||
<img src=\\"https://v2.docusaurus.io/\\" alt=\\"image\\"/></p>]]></content:encoded>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[Complex Slug]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô</link>
|
||||
<guid>/hey/my super path/héllô</guid>
|
||||
<pubDate>Sun, 16 Aug 2020 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[complex url slug]]></description>
|
||||
<content:encoded><![CDATA[<p>complex url slug</p>]]></content:encoded>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[Simple Slug]]></title>
|
||||
|
@ -93,6 +117,7 @@ exports[`blogFeed rss shows feed item for each post 1`] = `
|
|||
<guid>/simple/slug</guid>
|
||||
<pubDate>Sat, 15 Aug 2020 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[simple url slug]]></description>
|
||||
<content:encoded><![CDATA[<p>simple url slug</p>]]></content:encoded>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[draft]]></title>
|
||||
|
@ -100,6 +125,7 @@ exports[`blogFeed rss shows feed item for each post 1`] = `
|
|||
<guid>draft</guid>
|
||||
<pubDate>Thu, 27 Feb 2020 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[this post should not be published yet]]></description>
|
||||
<content:encoded><![CDATA[<p>this post should not be published yet</p>]]></content:encoded>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[some heading]]></title>
|
||||
|
@ -113,6 +139,7 @@ exports[`blogFeed rss shows feed item for each post 1`] = `
|
|||
<guid>date-matter</guid>
|
||||
<pubDate>Tue, 01 Jan 2019 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[date inside front matter]]></description>
|
||||
<content:encoded><![CDATA[<p>date inside front matter</p>]]></content:encoded>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
|
||||
|
@ -120,6 +147,7 @@ exports[`blogFeed rss shows feed item for each post 1`] = `
|
|||
<guid>Happy 1st Birthday Slash! (translated)</guid>
|
||||
<pubDate>Fri, 14 Dec 2018 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[Happy birthday! (translated)]]></description>
|
||||
<content:encoded><![CDATA[<p>Happy birthday! (translated)</p>]]></content:encoded>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>"
|
||||
|
|
|
@ -246,23 +246,26 @@ describe('loadBlog', () => {
|
|||
test('simple website blog dates localized', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
||||
const blogPostsFrench = await getBlogPosts(siteDir, {}, getI18n('fr'));
|
||||
expect(blogPostsFrench).toHaveLength(6);
|
||||
expect(blogPostsFrench).toHaveLength(7);
|
||||
expect(blogPostsFrench[0].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"16 août 2020"`,
|
||||
`"5 mars 2021"`,
|
||||
);
|
||||
expect(blogPostsFrench[1].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"15 août 2020"`,
|
||||
`"16 août 2020"`,
|
||||
);
|
||||
expect(blogPostsFrench[2].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"27 février 2020"`,
|
||||
`"15 août 2020"`,
|
||||
);
|
||||
expect(blogPostsFrench[3].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"2 janvier 2019"`,
|
||||
`"27 février 2020"`,
|
||||
);
|
||||
expect(blogPostsFrench[4].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"1 janvier 2019"`,
|
||||
`"2 janvier 2019"`,
|
||||
);
|
||||
expect(blogPostsFrench[5].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"1 janvier 2019"`,
|
||||
);
|
||||
expect(blogPostsFrench[6].metadata.formattedDate).toMatchInlineSnapshot(
|
||||
`"14 décembre 2018"`,
|
||||
);
|
||||
});
|
||||
|
@ -292,7 +295,7 @@ describe('loadBlog', () => {
|
|||
expect(blogPost.metadata.editUrl).toEqual(hardcodedEditUrl);
|
||||
});
|
||||
|
||||
expect(editUrlFunction).toHaveBeenCalledTimes(6);
|
||||
expect(editUrlFunction).toHaveBeenCalledTimes(7);
|
||||
expect(editUrlFunction).toHaveBeenCalledWith({
|
||||
blogDirPath: 'blog',
|
||||
blogPath: 'date-matter.md',
|
||||
|
@ -305,6 +308,12 @@ describe('loadBlog', () => {
|
|||
permalink: '/blog/draft',
|
||||
locale: 'en',
|
||||
});
|
||||
expect(editUrlFunction).toHaveBeenCalledWith({
|
||||
blogDirPath: 'blog',
|
||||
blogPath: 'mdx-blog-post.mdx',
|
||||
permalink: '/blog/mdx-blog-post',
|
||||
locale: 'en',
|
||||
});
|
||||
expect(editUrlFunction).toHaveBeenCalledWith({
|
||||
blogDirPath: 'blog',
|
||||
blogPath: 'complex-slug.md',
|
||||
|
|
|
@ -26,6 +26,7 @@ import {
|
|||
getEditUrl,
|
||||
getFolderContainingFile,
|
||||
posixPath,
|
||||
mdxToHtml,
|
||||
replaceMarkdownLinks,
|
||||
Globby,
|
||||
normalizeFrontMatterTags,
|
||||
|
@ -155,6 +156,7 @@ export async function generateBlogFeed(
|
|||
link: normalizeUrl([siteUrl, permalink]),
|
||||
date,
|
||||
description,
|
||||
content: mdxToHtml(post.content),
|
||||
author: authors.map(toFeedAuthor),
|
||||
});
|
||||
});
|
||||
|
@ -292,6 +294,7 @@ async function processBlogSourceFile(
|
|||
truncated: truncateMarker?.test(content) || false,
|
||||
authors,
|
||||
},
|
||||
content,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -554,19 +554,17 @@ export default function pluginContentBlog(
|
|||
}
|
||||
|
||||
const feedTypes = options.feedOptions.type;
|
||||
const {
|
||||
siteConfig: {title},
|
||||
} = context;
|
||||
const feedTitle = options.feedOptions.title ?? context.siteConfig.title;
|
||||
const feedsConfig = {
|
||||
rss: {
|
||||
type: 'application/rss+xml',
|
||||
path: 'rss.xml',
|
||||
title: `${title} Blog RSS Feed`,
|
||||
title: `${feedTitle} RSS Feed`,
|
||||
},
|
||||
atom: {
|
||||
type: 'application/atom+xml',
|
||||
path: 'atom.xml',
|
||||
title: `${title} Blog Atom Feed`,
|
||||
title: `${feedTitle} Atom Feed`,
|
||||
},
|
||||
};
|
||||
const headTags: HtmlTags = [];
|
||||
|
|
|
@ -97,6 +97,7 @@ export interface BlogTag {
|
|||
export interface BlogPost {
|
||||
id: string;
|
||||
metadata: MetaData;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface BlogPaginatedMetadata {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/types": "2.0.0-beta.6",
|
||||
"@mdx-js/runtime": "^1.6.22",
|
||||
"@types/github-slugger": "^1.3.0",
|
||||
"chalk": "^4.1.2",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
|
@ -27,6 +28,8 @@
|
|||
"gray-matter": "^4.0.3",
|
||||
"lodash": "^4.17.20",
|
||||
"micromatch": "^4.0.4",
|
||||
"remark-mdx-remove-imports": "^1.6.22",
|
||||
"remark-mdx-remove-exports": "^1.6.22",
|
||||
"resolve-pathname": "^3.0.0",
|
||||
"tslib": "^2.3.1"
|
||||
},
|
||||
|
@ -36,6 +39,11 @@
|
|||
"devDependencies": {
|
||||
"@types/dedent": "^0.7.0",
|
||||
"@types/micromatch": "^4.0.2",
|
||||
"@types/react-dom": "^17.0.1",
|
||||
"dedent": "^0.7.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "*",
|
||||
"react-dom": "*"
|
||||
}
|
||||
}
|
||||
|
|
133
packages/docusaurus-utils/src/__tests__/mdxUtils.test.ts
Normal file
133
packages/docusaurus-utils/src/__tests__/mdxUtils.test.ts
Normal file
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* 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 {mdxToHtml} from '../mdxUtils';
|
||||
|
||||
describe('mdxToHtml', () => {
|
||||
test('work with simple markdown', () => {
|
||||
const mdxString = `
|
||||
# title
|
||||
|
||||
title text **bold**
|
||||
|
||||
## subtitle
|
||||
|
||||
subtitle text *italic*
|
||||
|
||||
> Quote
|
||||
|
||||
`;
|
||||
|
||||
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
||||
`"<h1>title</h1><p>title text <strong>bold</strong></p><h2>subtitle</h2><p>subtitle text <em>italic</em></p><blockquote><p>Quote</p></blockquote>"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('work with MDX imports', () => {
|
||||
const mdxString = `
|
||||
# title
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
text
|
||||
|
||||
`;
|
||||
|
||||
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
||||
`"<h1>title</h1><p>text</p>"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('work with MDX exports', () => {
|
||||
const mdxString = `
|
||||
# title
|
||||
|
||||
export const someExport = 42
|
||||
|
||||
export const MyLocalComponent = () => "result"
|
||||
|
||||
export const toc = [
|
||||
{id: "title",label: "title"}
|
||||
]
|
||||
|
||||
text
|
||||
|
||||
|
||||
`;
|
||||
|
||||
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(
|
||||
`"<h1>title</h1><p>text</p>"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('work with MDX Tabs', () => {
|
||||
const mdxString = `
|
||||
# title
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="apple" label="Apple">
|
||||
This is an apple 🍎
|
||||
</TabItem>
|
||||
<TabItem value="orange" label="Orange">
|
||||
This is an orange 🍊
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
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(
|
||||
`"<h1>title</h1><div><div value=\\"apple\\" label=\\"Apple\\">This is an apple 🍎</div><div value=\\"orange\\" label=\\"Orange\\">This is an orange 🍊</div></div><p>text</p>"`,
|
||||
);
|
||||
});
|
||||
|
||||
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
|
||||
<Tabs>
|
||||
<TabItem value="apple" label="Apple">
|
||||
This is an apple 🍎
|
||||
</TabItem>
|
||||
<TabItem value="orange" label="Orange">
|
||||
This is an orange 🍊
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
\`\`\`
|
||||
|
||||
text
|
||||
|
||||
`;
|
||||
|
||||
// TODO bad behavior!
|
||||
// ```mdx-code-block should be unwrapped and inner MDX content should be evaluated
|
||||
expect(mdxToHtml(mdxString)).toMatchInlineSnapshot(`
|
||||
"<h1>title</h1><pre><code class=\\"language-mdx-code-block\\"><Tabs>
|
||||
<TabItem value="apple" label="Apple">
|
||||
This is an apple 🍎
|
||||
</TabItem>
|
||||
<TabItem value="orange" label="Orange">
|
||||
This is an orange 🍊
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
</code></pre><p>text</p>"
|
||||
`);
|
||||
});
|
||||
});
|
12
packages/docusaurus-utils/src/dependencies.d.ts
vendored
Normal file
12
packages/docusaurus-utils/src/dependencies.d.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Dependencies with missing typedefs
|
||||
|
||||
declare module '@mdx-js/runtime';
|
||||
declare module 'remark-mdx-remove-imports';
|
||||
declare module 'remark-mdx-remove-exports';
|
|
@ -25,6 +25,7 @@ import {posixPath as posixPathImport} from './posixPath';
|
|||
import {simpleHash, docuHash} from './hashUtils';
|
||||
import {normalizeUrl} from './normalizeUrl';
|
||||
|
||||
export * from './mdxUtils';
|
||||
export * from './normalizeUrl';
|
||||
export * from './tags';
|
||||
|
||||
|
|
32
packages/docusaurus-utils/src/mdxUtils.ts
Normal file
32
packages/docusaurus-utils/src/mdxUtils.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* 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,
|
||||
]),
|
||||
);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: Blog post MDX Feed tests
|
||||
authors:
|
||||
- slorber
|
||||
---
|
||||
|
||||
Some MDX tests, mostly to test how the RSS feed render those
|
||||
|
||||
<!-- truncate -->
|
||||
|
||||
## Imports
|
||||
|
||||
Here are some imports:
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
## Exports
|
||||
|
||||
Here are some exports:
|
||||
|
||||
export const someExport = 42;
|
||||
|
||||
## Tabs test
|
||||
|
||||
Here are some tabs:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="apple" label="Apple">
|
||||
This is an apple 🍎
|
||||
</TabItem>
|
||||
<TabItem value="orange" label="Orange">
|
||||
This is an orange 🍊
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
Here are some tabs, inside `mdx-code-block`:
|
||||
|
||||
```mdx-code-block
|
||||
<Tabs>
|
||||
<TabItem value="apple" label="Apple">
|
||||
This is an apple 🍎
|
||||
</TabItem>
|
||||
<TabItem value="orange" label="Orange">
|
||||
This is an orange 🍊
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
```
|
|
@ -28,6 +28,7 @@ const dogfoodingPluginInstances = [
|
|||
postsPerPage: 3,
|
||||
feedOptions: {
|
||||
type: 'all',
|
||||
title: 'Docusaurus Tests Blog',
|
||||
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`,
|
||||
},
|
||||
}),
|
||||
|
|
49
yarn.lock
49
yarn.lock
|
@ -2518,7 +2518,7 @@
|
|||
stringify-entities "^3.0.1"
|
||||
stringify-object "^3.3.0"
|
||||
|
||||
"@mdx-js/mdx@^1.6.21":
|
||||
"@mdx-js/mdx@1.6.22", "@mdx-js/mdx@^1.6.21":
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/@mdx-js/mdx/-/mdx-1.6.22.tgz#8a723157bf90e78f17dc0f27995398e6c731f1ba"
|
||||
integrity sha512-AMxuLxPz2j5/6TpF/XSdKpQP1NlG0z11dFOlq+2IP/lSgl11GY8ji6S/rgsViN/L0BDvHvUMruRb7ub+24LUYA==
|
||||
|
@ -2543,11 +2543,20 @@
|
|||
unist-builder "2.0.3"
|
||||
unist-util-visit "2.0.3"
|
||||
|
||||
"@mdx-js/react@^1.6.21":
|
||||
"@mdx-js/react@1.6.22", "@mdx-js/react@^1.6.21":
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.6.22.tgz#ae09b4744fddc74714ee9f9d6f17a66e77c43573"
|
||||
integrity sha512-TDoPum4SHdfPiGSAaRBw7ECyI8VaHpK8GJugbJIJuqyh6kzw9ZLJZW3HGL3NNrJGxcAixUvqROm+YuQOo5eXtg==
|
||||
|
||||
"@mdx-js/runtime@^1.6.22":
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/@mdx-js/runtime/-/runtime-1.6.22.tgz#3edd388bf68a519ffa1aaf9c446b548165102345"
|
||||
integrity sha512-p17spaO2+55VLCuxXA3LVHC4phRx60NR2XMdZ+qgVU1lKvEX4y88dmFNOzGDCPLJ03IZyKrJ/rPWWRiBrd9JrQ==
|
||||
dependencies:
|
||||
"@mdx-js/mdx" "1.6.22"
|
||||
"@mdx-js/react" "1.6.22"
|
||||
buble-jsx-only "^0.19.8"
|
||||
|
||||
"@mdx-js/util@1.6.22":
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/@mdx-js/util/-/util-1.6.22.tgz#219dfd89ae5b97a8801f015323ffa4b62f45718b"
|
||||
|
@ -4408,7 +4417,7 @@
|
|||
"@types/webpack" "^4"
|
||||
"@types/webpack-dev-server" "^3"
|
||||
|
||||
"@types/react-dom@^17.0.9":
|
||||
"@types/react-dom@^17.0.1", "@types/react-dom@^17.0.9":
|
||||
version "17.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.9.tgz#441a981da9d7be117042e1a6fd3dac4b30f55add"
|
||||
integrity sha512-wIvGxLfgpVDSAMH5utdL9Ngm5Owu0VsGmldro3ORLXV8CShrL8awVj06NuEXFQ5xyaYfdca7Sgbk/50Ri1GdPg==
|
||||
|
@ -5997,6 +6006,19 @@ btoa-lite@^1.0.0:
|
|||
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
|
||||
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=
|
||||
|
||||
buble-jsx-only@^0.19.8:
|
||||
version "0.19.8"
|
||||
resolved "https://registry.yarnpkg.com/buble-jsx-only/-/buble-jsx-only-0.19.8.tgz#6e3524aa0f1c523de32496ac9aceb9cc2b493867"
|
||||
integrity sha512-7AW19pf7PrKFnGTEDzs6u9+JZqQwM1VnLS19OlqYDhXomtFFknnoQJAPHeg84RMFWAvOhYrG7harizJNwUKJsA==
|
||||
dependencies:
|
||||
acorn "^6.1.1"
|
||||
acorn-dynamic-import "^4.0.0"
|
||||
acorn-jsx "^5.0.1"
|
||||
chalk "^2.4.2"
|
||||
magic-string "^0.25.3"
|
||||
minimist "^1.2.0"
|
||||
regexpu-core "^4.5.4"
|
||||
|
||||
buble@0.19.6:
|
||||
version "0.19.6"
|
||||
resolved "https://registry.yarnpkg.com/buble/-/buble-0.19.6.tgz#915909b6bd5b11ee03b1c885ec914a8b974d34d3"
|
||||
|
@ -17215,6 +17237,20 @@ remark-math@^3.0.1:
|
|||
resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-3.0.1.tgz#85a02a15b15cad34b89a27244d4887b3a95185bb"
|
||||
integrity sha512-epT77R/HK0x7NqrWHdSV75uNLwn8g9qTyMqCRCDujL0vj/6T6+yhdrR7mjELWtkse+Fw02kijAaBuVcHBor1+Q==
|
||||
|
||||
remark-mdx-remove-exports@^1.6.22:
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/remark-mdx-remove-exports/-/remark-mdx-remove-exports-1.6.22.tgz#9e34f3d02c9c54b02ca0a1fde946449338d06ecb"
|
||||
integrity sha512-7g2uiTmTGfz5QyVb+toeX25frbk1Y6yd03RXGPtqx0+DVh86Gb7MkNYbk7H2X27zdZ3CQv1W/JqlFO0Oo8IxVA==
|
||||
dependencies:
|
||||
unist-util-remove "2.0.0"
|
||||
|
||||
remark-mdx-remove-imports@^1.6.22:
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/remark-mdx-remove-imports/-/remark-mdx-remove-imports-1.6.22.tgz#79f711c95359cff437a120d1fbdc1326ec455826"
|
||||
integrity sha512-lmjAXD8Ltw0TsvBzb45S+Dxx7LTJAtDaMneMAv8LAUIPEyYoKkmGbmVsiF0/pY6mhM1Q16swCmu1TN+ie/vn/A==
|
||||
dependencies:
|
||||
unist-util-remove "2.0.0"
|
||||
|
||||
remark-mdx@1.6.22, remark-mdx@^1.6.21:
|
||||
version "1.6.22"
|
||||
resolved "https://registry.yarnpkg.com/remark-mdx/-/remark-mdx-1.6.22.tgz#06a8dab07dcfdd57f3373af7f86bd0e992108bbd"
|
||||
|
@ -19790,6 +19826,13 @@ unist-util-remove-position@^3.0.0:
|
|||
dependencies:
|
||||
unist-util-visit "^2.0.0"
|
||||
|
||||
unist-util-remove@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/unist-util-remove/-/unist-util-remove-2.0.0.tgz#32c2ad5578802f2ca62ab808173d505b2c898488"
|
||||
integrity sha512-HwwWyNHKkeg/eXRnE11IpzY8JT55JNM1YCwwU9YNCnfzk6s8GhPXrVBBZWiwLeATJbI7euvoGSzcy9M29UeW3g==
|
||||
dependencies:
|
||||
unist-util-is "^4.0.0"
|
||||
|
||||
unist-util-remove@^2.0.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/unist-util-remove/-/unist-util-remove-2.1.0.tgz#b0b4738aa7ee445c402fda9328d604a02d010588"
|
||||
|
|
Loading…
Add table
Reference in a new issue