From 7c646d63f928bd2932a9e0aa1be4982219e0fe49 Mon Sep 17 00:00:00 2001 From: AmrMustafa <90666301+AmrMustafa282@users.noreply.github.com> Date: Wed, 13 Nov 2024 04:59:18 +0200 Subject: [PATCH] feat: transform GitHub alert blocks into Docusaurus admonitions (#655) Co-authored-by: Erick Zhao --- docusaurus.config.ts | 19 +++++++++++++++++++ package.json | 1 + yarn.lock | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index ab3feea..cfb79c3 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -2,6 +2,11 @@ import path from 'path'; import { Config } from '@docusaurus/types'; import npm2yarn from '@docusaurus/remark-plugin-npm2yarn'; import { themes as prismThemes } from 'prism-react-renderer'; +import remarkGithubAdmonitionsToDirectives, { + DEFAULT_MAPPING, + DirectiveName, + GithubAlertType, +} from 'remark-github-admonitions-to-directives'; import apiLabels from './src/transformers/api-labels'; import apiOptionsClass from './src/transformers/api-options-class'; @@ -208,6 +213,18 @@ const config: Config = { '@docusaurus/preset-classic', { docs: { + path: 'docs', + beforeDefaultRemarkPlugins: [ + [ + remarkGithubAdmonitionsToDirectives, + { + mapping: { + ...DEFAULT_MAPPING, + [GithubAlertType.NOTE]: DirectiveName.INFO, + }, + }, + ], + ], sidebarPath: require.resolve('./sidebars.js'), routeBasePath: '/docs/', editUrl: ({ docPath }) => { @@ -226,6 +243,8 @@ const config: Config = { }, blog: { // See `node_modules/@docusaurus/plugin-content-blog/src/pluginOptionSchema.ts` for full undocumented options + path: 'blog', + beforeDefaultRemarkPlugins: [remarkGithubAdmonitionsToDirectives], blogSidebarCount: 'ALL', blogSidebarTitle: 'Latest posts', blogTitle: `Electron's blog`, diff --git a/package.json b/package.json index 4f40634..879a909 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "react-dom": "^18.3.1", "react-markdown": "^9.0.1", "react-useportal": "^1.0.14", + "remark-github-admonitions-to-directives": "^2.0.0", "sass": "^1.37.5", "semver": "^7.5.4", "yaml": "^2.4.3" diff --git a/yarn.lock b/yarn.lock index 3b4a086..c6e032d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13050,6 +13050,16 @@ remark-gfm@^4.0.0: remark-stringify "^11.0.0" unified "^11.0.0" +remark-github-admonitions-to-directives@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/remark-github-admonitions-to-directives/-/remark-github-admonitions-to-directives-2.1.0.tgz#5bdb5deb3e1d6ee7a1427aeea9e27e7b3ea96ff4" + integrity sha512-bI3E4Oj1pKY3ym2IQrrVCdORgEu0+mSrWgpCYFNy8QvytfnLs/nAacVPjkWU/JzDMUiQio2k4nTFP7bsIr9TSA== + dependencies: + "@types/mdast" "^4.0.0" + mdast-util-directive "^3.0.0" + unified "^11.0.0" + unist-util-visit "^5.0.0" + remark-mdx@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/remark-mdx/-/remark-mdx-3.0.1.tgz#8f73dd635c1874e44426e243f72c0977cf60e212"