From faf48e9b166e3e6e2ce90bd1349d526c7e53c890 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 22 May 2020 05:04:40 -0400 Subject: [PATCH 01/11] fix(v2): Resolve plugins relative to siteDir (#2789) --- packages/docusaurus/src/server/plugins/init.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus/src/server/plugins/init.ts b/packages/docusaurus/src/server/plugins/init.ts index 244483467e72..de8d098fd846 100644 --- a/packages/docusaurus/src/server/plugins/init.ts +++ b/packages/docusaurus/src/server/plugins/init.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import Module from 'module'; import importFresh from 'import-fresh'; import {LoadContext, Plugin, PluginConfig} from '@docusaurus/types'; @@ -15,9 +16,16 @@ export function initPlugins({ pluginConfigs: PluginConfig[]; context: LoadContext; }): Plugin[] { + // We need to resolve plugins from the perspective of the siteDir, since the siteDir's package.json + // declares the dependency on these plugins. + // We need to fallback to createRequireFromPath since createRequire is only available in node v12. + // See: https://nodejs.org/api/modules.html#modules_module_createrequire_filename + const createRequire = Module.createRequire || Module.createRequireFromPath; + const pluginRequire = createRequire(context.siteDir); + const plugins: Plugin[] = pluginConfigs .map((pluginItem) => { - let pluginModuleImport; + let pluginModuleImport: string | undefined; let pluginOptions = {}; if (!pluginItem) { @@ -37,7 +45,9 @@ export function initPlugins({ // The pluginModuleImport value is any valid // module identifier - npm package or locally-resolved path. - const pluginModule: any = importFresh(pluginModuleImport); + const pluginModule: any = importFresh( + pluginRequire.resolve(pluginModuleImport), + ); return (pluginModule.default || pluginModule)(context, pluginOptions); }) .filter(Boolean); From 926cbb818bf84ae832694340e77681f6549bed2e Mon Sep 17 00:00:00 2001 From: Piotr Baran Date: Fri, 22 May 2020 12:57:48 +0200 Subject: [PATCH 02/11] docs(v2): change docs for markdown features (#2786) * fix(v2): change docs for markdown features * Update doc1.md * Update doc1.md * Update doc1.md Co-authored-by: Yangshun Tay --- .../templates/bootstrap/docs/doc1.md | 23 ++++++++++++------- .../templates/classic/docs/doc1.md | 23 ++++++++++++------- .../templates/facebook/docs/doc1.md | 21 +++++++++++------ 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/packages/docusaurus-init/templates/bootstrap/docs/doc1.md b/packages/docusaurus-init/templates/bootstrap/docs/doc1.md index 92fa8fbe45be..af57d2d78d85 100644 --- a/packages/docusaurus-init/templates/bootstrap/docs/doc1.md +++ b/packages/docusaurus-init/templates/bootstrap/docs/doc1.md @@ -28,9 +28,11 @@ To serve as an example page when styling markdown based Docusaurus sites. ## Emphasis -Emphasis, aka italics, with _asterisks_ or _underscores_. + +Emphasis, aka italics, with *asterisks* or _underscores_. -Strong emphasis, aka bold, with **asterisks** or **underscores**. + +Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. @@ -41,17 +43,22 @@ Strikethrough uses two tildes. ~~Scratch this.~~ ## Lists 1. First ordered list item -1. Another item ⋅⋅\* Unordered sub-list. -1. Actual numbers don't matter, just that it's a number ⋅⋅1. Ordered sub-list +1. Another item + - Unordered sub-list. +1. Actual numbers don't matter, just that it's a number + 1. Ordered sub-list 1. And another item. -⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). + You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). -⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅ ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅ ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) + To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) -- Unordered list can use asterisks + +* Unordered list can use asterisks + * Or minuses + - Or pluses @@ -102,7 +109,7 @@ alert(s); ```python s = "Python syntax highlighting" -print(s) +print s ``` ``` diff --git a/packages/docusaurus-init/templates/classic/docs/doc1.md b/packages/docusaurus-init/templates/classic/docs/doc1.md index 92fa8fbe45be..af57d2d78d85 100644 --- a/packages/docusaurus-init/templates/classic/docs/doc1.md +++ b/packages/docusaurus-init/templates/classic/docs/doc1.md @@ -28,9 +28,11 @@ To serve as an example page when styling markdown based Docusaurus sites. ## Emphasis -Emphasis, aka italics, with _asterisks_ or _underscores_. + +Emphasis, aka italics, with *asterisks* or _underscores_. -Strong emphasis, aka bold, with **asterisks** or **underscores**. + +Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. @@ -41,17 +43,22 @@ Strikethrough uses two tildes. ~~Scratch this.~~ ## Lists 1. First ordered list item -1. Another item ⋅⋅\* Unordered sub-list. -1. Actual numbers don't matter, just that it's a number ⋅⋅1. Ordered sub-list +1. Another item + - Unordered sub-list. +1. Actual numbers don't matter, just that it's a number + 1. Ordered sub-list 1. And another item. -⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). + You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). -⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅ ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅ ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) + To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) -- Unordered list can use asterisks + +* Unordered list can use asterisks + * Or minuses + - Or pluses @@ -102,7 +109,7 @@ alert(s); ```python s = "Python syntax highlighting" -print(s) +print s ``` ``` diff --git a/packages/docusaurus-init/templates/facebook/docs/doc1.md b/packages/docusaurus-init/templates/facebook/docs/doc1.md index 98cce3215d98..af57d2d78d85 100644 --- a/packages/docusaurus-init/templates/facebook/docs/doc1.md +++ b/packages/docusaurus-init/templates/facebook/docs/doc1.md @@ -28,9 +28,11 @@ To serve as an example page when styling markdown based Docusaurus sites. ## Emphasis -Emphasis, aka italics, with _asterisks_ or _underscores_. + +Emphasis, aka italics, with *asterisks* or _underscores_. -Strong emphasis, aka bold, with **asterisks** or **underscores**. + +Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. @@ -41,17 +43,22 @@ Strikethrough uses two tildes. ~~Scratch this.~~ ## Lists 1. First ordered list item -1. Another item ⋅⋅\* Unordered sub-list. -1. Actual numbers don't matter, just that it's a number ⋅⋅1. Ordered sub-list +1. Another item + - Unordered sub-list. +1. Actual numbers don't matter, just that it's a number + 1. Ordered sub-list 1. And another item. -⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). + You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). -⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅ ⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅ ⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) + To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) -- Unordered list can use asterisks + +* Unordered list can use asterisks + * Or minuses + - Or pluses From 20fbceb9f1883a0d23ba52e79a4517b92631f7fd Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Fri, 22 May 2020 19:18:29 +0800 Subject: [PATCH 03/11] docs(v2): fix markdown syntax examples in templates --- .../docusaurus-init/templates/bootstrap/docs/doc1.md | 12 ++++-------- .../docusaurus-init/templates/classic/docs/doc1.md | 12 ++++-------- .../docusaurus-init/templates/facebook/docs/doc1.md | 12 ++++-------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/packages/docusaurus-init/templates/bootstrap/docs/doc1.md b/packages/docusaurus-init/templates/bootstrap/docs/doc1.md index af57d2d78d85..e886a419dd4f 100644 --- a/packages/docusaurus-init/templates/bootstrap/docs/doc1.md +++ b/packages/docusaurus-init/templates/bootstrap/docs/doc1.md @@ -49,18 +49,14 @@ Strikethrough uses two tildes. ~~Scratch this.~~ 1. Ordered sub-list 1. And another item. - You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). - - To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) - * Unordered list can use asterisks - -* Or minuses +- Or minuses -- Or pluses + ++ Or pluses --- @@ -109,7 +105,7 @@ alert(s); ```python s = "Python syntax highlighting" -print s +print(s) ``` ``` diff --git a/packages/docusaurus-init/templates/classic/docs/doc1.md b/packages/docusaurus-init/templates/classic/docs/doc1.md index af57d2d78d85..e886a419dd4f 100644 --- a/packages/docusaurus-init/templates/classic/docs/doc1.md +++ b/packages/docusaurus-init/templates/classic/docs/doc1.md @@ -49,18 +49,14 @@ Strikethrough uses two tildes. ~~Scratch this.~~ 1. Ordered sub-list 1. And another item. - You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). - - To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) - * Unordered list can use asterisks - -* Or minuses +- Or minuses -- Or pluses + ++ Or pluses --- @@ -109,7 +105,7 @@ alert(s); ```python s = "Python syntax highlighting" -print s +print(s) ``` ``` diff --git a/packages/docusaurus-init/templates/facebook/docs/doc1.md b/packages/docusaurus-init/templates/facebook/docs/doc1.md index af57d2d78d85..e886a419dd4f 100644 --- a/packages/docusaurus-init/templates/facebook/docs/doc1.md +++ b/packages/docusaurus-init/templates/facebook/docs/doc1.md @@ -49,18 +49,14 @@ Strikethrough uses two tildes. ~~Scratch this.~~ 1. Ordered sub-list 1. And another item. - You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). - - To have a line break without a paragraph, you will need to use two trailing spaces. Note that this line is separate, but within the same paragraph. (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) - * Unordered list can use asterisks - -* Or minuses +- Or minuses -- Or pluses + ++ Or pluses --- @@ -109,7 +105,7 @@ alert(s); ```python s = "Python syntax highlighting" -print s +print(s) ``` ``` From 1503943e3f4cc2eb1f006f9d83f9b6bb539cb99f Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 22 May 2020 16:57:02 -0400 Subject: [PATCH 04/11] fix(v2): Use `require.resolve` to resolve plugin path in presets (#2794) --- .../docusaurus-preset-bootstrap/src/index.js | 8 ++++---- .../docusaurus-preset-classic/src/index.js | 18 ++++++++++-------- website/docs/presets.md | 7 +++++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/docusaurus-preset-bootstrap/src/index.js b/packages/docusaurus-preset-bootstrap/src/index.js index 7058e0e962ae..66f4363b667a 100644 --- a/packages/docusaurus-preset-bootstrap/src/index.js +++ b/packages/docusaurus-preset-bootstrap/src/index.js @@ -7,11 +7,11 @@ module.exports = function preset(context, opts = {}) { return { - themes: [['@docusaurus/theme-bootstrap', opts.theme]], + themes: [[require.resolve('@docusaurus/theme-bootstrap'), opts.theme]], plugins: [ - ['@docusaurus/plugin-content-pages', opts.pages], - ['@docusaurus/plugin-content-blog', opts.blog], - ['@docusaurus/plugin-content-docs', opts.docs], + [require.resolve('@docusaurus/plugin-content-pages'), opts.pages], + [require.resolve('@docusaurus/plugin-content-blog'), opts.blog], + [require.resolve('@docusaurus/plugin-content-docs'), opts.docs], ], }; }; diff --git a/packages/docusaurus-preset-classic/src/index.js b/packages/docusaurus-preset-classic/src/index.js index ac74ef9269e6..2a4d489bcc76 100644 --- a/packages/docusaurus-preset-classic/src/index.js +++ b/packages/docusaurus-preset-classic/src/index.js @@ -13,17 +13,19 @@ module.exports = function preset(context, opts = {}) { return { themes: [ - ['@docusaurus/theme-classic', opts.theme], + [require.resolve('@docusaurus/theme-classic'), opts.theme], // Don't add this if algolia config is not defined. - algolia && '@docusaurus/theme-search-algolia', + algolia && require.resolve('@docusaurus/theme-search-algolia'), ], plugins: [ - ['@docusaurus/plugin-content-docs', opts.docs], - ['@docusaurus/plugin-content-blog', opts.blog], - ['@docusaurus/plugin-content-pages', opts.pages], - isProd && googleAnalytics && '@docusaurus/plugin-google-analytics', - isProd && gtag && '@docusaurus/plugin-google-gtag', - isProd && ['@docusaurus/plugin-sitemap', opts.sitemap], + [require.resolve('@docusaurus/plugin-content-docs'), opts.docs], + [require.resolve('@docusaurus/plugin-content-blog'), opts.blog], + [require.resolve('@docusaurus/plugin-content-pages'), opts.pages], + isProd && + googleAnalytics && + require.resolve('@docusaurus/plugin-google-analytics'), + isProd && gtag && require.resolve('@docusaurus/plugin-google-gtag'), + isProd && [require.resolve('@docusaurus/plugin-sitemap'), opts.sitemap], ], }; }; diff --git a/website/docs/presets.md b/website/docs/presets.md index 872be9dc31b7..44d07c8fb23f 100644 --- a/website/docs/presets.md +++ b/website/docs/presets.md @@ -40,8 +40,11 @@ Presets in some way are a shorthand function to add plugins and themes to your d ```js module.exports = function preset(context, opts = {}) { return { - themes: ['@docusaurus/themes-cool', '@docusaurus/themes-bootstrap'], - plugins: ['@docusaurus/plugin-blog'], + themes: [ + require.resolve('@docusaurus/themes-cool'), + require.resolve('@docusaurus/themes-bootstrap'), + ], + plugins: [require.resolve('@docusaurus/plugin-blog')], }; }; ``` From 85a694448f47a5dd86650d1ec9629a7339fbf846 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 22 May 2020 16:58:21 -0400 Subject: [PATCH 05/11] fix(v2): Ensure that theme classic require webpack provided by `@docusaurus/core` (#2795) --- packages/docusaurus-theme-classic/src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/index.js b/packages/docusaurus-theme-classic/src/index.js index 7cce15b4c5b8..54c997dcd7ab 100644 --- a/packages/docusaurus-theme-classic/src/index.js +++ b/packages/docusaurus-theme-classic/src/index.js @@ -6,7 +6,15 @@ */ const path = require('path'); -const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin'); +const Module = require('module'); + +const createRequire = Module.createRequire || Module.createRequireFromPath; +const requireFromDocusaurusCore = createRequire( + require.resolve('@docusaurus/core/package.json'), +); +const ContextReplacementPlugin = requireFromDocusaurusCore( + 'webpack/lib/ContextReplacementPlugin', +); // Need to be inlined to prevent dark mode FOUC // Make sure that the 'storageKey' is the same as the one in `/theme/hooks/useTheme.js` From 83f980cadfd495b721c359320abea29aac371650 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sat, 23 May 2020 00:02:18 +0300 Subject: [PATCH 06/11] refactor(v2): show only search icon on mobiles (#2791) --- .../src/theme/Navbar/styles.module.css | 2 +- .../src/theme/SearchBar/index.js | 67 ++++++++++--------- .../src/theme/SearchBar/styles.css | 40 ----------- .../src/theme/SearchBar/styles.module.css | 62 +++++++++++++++++ 4 files changed, 97 insertions(+), 74 deletions(-) delete mode 100644 packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.css create mode 100644 packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.module.css diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/styles.module.css b/packages/docusaurus-theme-classic/src/theme/Navbar/styles.module.css index 7d59c599a1e0..fb524ac417ff 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/styles.module.css +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/styles.module.css @@ -11,7 +11,7 @@ } } -@media (max-width: 360px) { +@media (max-width: 768px) { .hideLogoText { display: none; } diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js index 90abee077851..743ea73a74d2 100644 --- a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js +++ b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.js @@ -12,9 +12,9 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import {useHistory} from '@docusaurus/router'; import useSearchQuery from '@theme/hooks/useSearchQuery'; -import './styles.css'; +import styles from './styles.module.css'; -const Search = (props) => { +const Search = ({handleSearchBarToggle, isSearchBarExpanded}) => { const [algoliaLoaded, setAlgoliaLoaded] = useState(false); const searchBarRef = useRef(null); const {siteConfig = {}} = useDocusaurusContext(); @@ -76,19 +76,19 @@ const Search = (props) => { ); }; - const handleSearchIcon = useCallback(() => { + const toggleSearchInput = useCallback(() => { loadAlgolia(); if (algoliaLoaded) { searchBarRef.current.focus(); } - props.handleSearchBarToggle(!props.isSearchBarExpanded); - }, [props.isSearchBarExpanded]); + handleSearchBarToggle(!isSearchBarExpanded); + }, [isSearchBarExpanded]); const handleSearchInputBlur = useCallback(() => { - props.handleSearchBarToggle(!props.isSearchBarExpanded); - }, [props.isSearchBarExpanded]); + handleSearchBarToggle(!isSearchBarExpanded); + }, [isSearchBarExpanded]); const handleSearchInput = useCallback((e) => { const needFocus = e.type !== 'mouseover'; @@ -104,32 +104,33 @@ const Search = (props) => { return (
- - +
+ + + +
); }; diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.css b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.css deleted file mode 100644 index f9053f584510..000000000000 --- a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.css +++ /dev/null @@ -1,40 +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. - */ - -.search-icon { - background-image: var(--ifm-navbar-search-input-icon); - height: auto; - width: 24px; - cursor: pointer; - padding: 8px; - line-height: 32px; - background-repeat: no-repeat; - background-position: center; - display: none; -} - -.search-icon-hidden { - visibility: hidden; -} - -@media (max-width: 360px) { - .search-bar { - width: 0 !important; - background: none !important; - padding: 0 !important; - transition: none !important; - } - - .search-bar-expanded { - width: 9rem !important; - } - - .search-icon { - display: inline; - vertical-align: sub; - } -} diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.module.css b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.module.css new file mode 100644 index 000000000000..780f618f77da --- /dev/null +++ b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/styles.module.css @@ -0,0 +1,62 @@ +/** + * 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. + */ + +.searchIconButton { + display: none; +} + +@media (max-width: 768px) { + .searchIconButton { + display: block; + position: absolute; + right: 0; + width: 2.75rem; + height: 2rem; + z-index: 1; + } + + .searchIconButtonHidden { + visibility: hidden; + } + + :global(.navbar__items:first-of-type) { + flex: 0 1 auto; + } + + :global(.navbar__inner) { + position: relative; + } + + :global(.navbar__search) { + position: relative; + flex: 1 1 auto; + padding-left: 0; + } + + .searchWrapper { + position: absolute; + top: calc(var(--ifm-navbar-padding-vertical) * 2 * -1); + width: 100%; + display: flex; + justify-content: flex-end; + } + + .searchInput { + width: 0; + transition: width 0.3s ease-in-out; + } + + .searchInputExpanded { + width: 100%; + } + + :global(.algolia-autocomplete) { + width: 100%; + display: flex !important; + justify-content: flex-end; + } +} From 0ff6dd31f4ade91f8dc5cb55fdf3c3cb45819be5 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sat, 23 May 2020 00:05:16 +0300 Subject: [PATCH 07/11] style(v2): disable Prettier checks for Markdown files of init templates (#2792) --- .prettierignore | 1 + packages/docusaurus-init/templates/bootstrap/docs/doc1.md | 5 ----- packages/docusaurus-init/templates/classic/docs/doc1.md | 5 ----- packages/docusaurus-init/templates/facebook/docs/doc1.md | 5 ----- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.prettierignore b/.prettierignore index e918d160e80b..f54d39350982 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,6 +5,7 @@ build packages/docusaurus-utils/lib/ packages/docusaurus/lib/ packages/docusaurus-init/lib/ +packages/docusaurus-init/templates/**/*.md packages/docusaurus-plugin-content-blog/lib/ packages/docusaurus-plugin-content-docs/lib/ packages/docusaurus-plugin-content-pages/lib/ diff --git a/packages/docusaurus-init/templates/bootstrap/docs/doc1.md b/packages/docusaurus-init/templates/bootstrap/docs/doc1.md index e886a419dd4f..448cb69a983c 100644 --- a/packages/docusaurus-init/templates/bootstrap/docs/doc1.md +++ b/packages/docusaurus-init/templates/bootstrap/docs/doc1.md @@ -28,10 +28,8 @@ To serve as an example page when styling markdown based Docusaurus sites. ## Emphasis - Emphasis, aka italics, with *asterisks* or _underscores_. - Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. @@ -49,13 +47,10 @@ Strikethrough uses two tildes. ~~Scratch this.~~ 1. Ordered sub-list 1. And another item. - * Unordered list can use asterisks - - Or minuses - + Or pluses --- diff --git a/packages/docusaurus-init/templates/classic/docs/doc1.md b/packages/docusaurus-init/templates/classic/docs/doc1.md index e886a419dd4f..448cb69a983c 100644 --- a/packages/docusaurus-init/templates/classic/docs/doc1.md +++ b/packages/docusaurus-init/templates/classic/docs/doc1.md @@ -28,10 +28,8 @@ To serve as an example page when styling markdown based Docusaurus sites. ## Emphasis - Emphasis, aka italics, with *asterisks* or _underscores_. - Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. @@ -49,13 +47,10 @@ Strikethrough uses two tildes. ~~Scratch this.~~ 1. Ordered sub-list 1. And another item. - * Unordered list can use asterisks - - Or minuses - + Or pluses --- diff --git a/packages/docusaurus-init/templates/facebook/docs/doc1.md b/packages/docusaurus-init/templates/facebook/docs/doc1.md index e886a419dd4f..448cb69a983c 100644 --- a/packages/docusaurus-init/templates/facebook/docs/doc1.md +++ b/packages/docusaurus-init/templates/facebook/docs/doc1.md @@ -28,10 +28,8 @@ To serve as an example page when styling markdown based Docusaurus sites. ## Emphasis - Emphasis, aka italics, with *asterisks* or _underscores_. - Strong emphasis, aka bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. @@ -49,13 +47,10 @@ Strikethrough uses two tildes. ~~Scratch this.~~ 1. Ordered sub-list 1. And another item. - * Unordered list can use asterisks - - Or minuses - + Or pluses --- From 0e61da8f69cb8e59907233263079a7f5f34ab7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20B=C3=B8gebjerg=20Pedersen?= Date: Sat, 23 May 2020 00:07:01 +0200 Subject: [PATCH 08/11] feat(v2): allow specifying of remark and rehype plugins before default plugins (#2689) * feat(v2): swap order of markdown plugins * feat(v2): remark/rehype plugins can override default plugins --- packages/docusaurus-mdx-loader/src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index d17854083f9b..851ff6cc0b4d 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -27,10 +27,12 @@ module.exports = async function (fileString) { const options = { ...reqOptions, remarkPlugins: [ + ...(reqOptions.beforeDefaultRemarkPlugins || []), ...DEFAULT_OPTIONS.remarkPlugins, ...(reqOptions.remarkPlugins || []), ], rehypePlugins: [ + ...(reqOptions.beforeDefaultRehypePlugins || []), ...DEFAULT_OPTIONS.rehypePlugins, ...(reqOptions.rehypePlugins || []), ], From 2dbd0488d72832e340fb711900abbe16cea61669 Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Sat, 23 May 2020 06:12:24 +0800 Subject: [PATCH 09/11] docs(v2): document beforeDefaultRemarkPlugins and beforeDefaultRehypePlugins --- website/docs/using-plugins.md | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/website/docs/using-plugins.md b/website/docs/using-plugins.md index d5163096033d..d0621b23d4a3 100644 --- a/website/docs/using-plugins.md +++ b/website/docs/using-plugins.md @@ -145,36 +145,42 @@ module.exports = { '@docusaurus/plugin-content-blog', { /** - * Path to data on filesystem - * relative to site dir + * Path to data on filesystem relative to site dir. */ path: 'blog', /** - * URL for editing a blog post, example: 'https://github.com/facebook/docusaurus/edit/master/website/blog/' + * URL for editing a blog post. + * Example: 'https://github.com/facebook/docusaurus/edit/master/website/blog/' */ editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/blog/', /** - * URL route for the blog section of your site - * do not include trailing slash + * URL route for the blog section of your site. + * *DO NOT* include a trailing slash. */ routeBasePath: 'blog', include: ['*.md', '*.mdx'], postsPerPage: 10, /** - * Theme components used by the blog pages + * Theme components used by the blog pages. */ blogListComponent: '@theme/BlogListPage', blogPostComponent: '@theme/BlogPostPage', blogTagsListComponent: '@theme/BlogTagsListPage', blogTagsPostsComponent: '@theme/BlogTagsPostsPage', /** - * Remark and Rehype plugins passed to MDX + * Remark and Rehype plugins passed to MDX. */ remarkPlugins: [ /* require('remark-math') */ ], rehypePlugins: [], + /** + * Custom Remark and Rehype plugins passed to MDX before + * the default Docusaurus Remark and Rehype plugins. + */ + beforeDefaultRemarkPlugins: [], + beforeDefaultRehypePlugins: [], /** * Truncate marker, can be a regex or string. */ @@ -184,8 +190,8 @@ module.exports = { */ showReadingTime: true, /** - * Blog feed - * If feedOptions is undefined, no rss feed will be generated + * Blog feed. + * If feedOptions is undefined, no rss feed will be generated. */ feedOptions: { type: '', // required. 'rss' | 'feed' | 'all' @@ -223,17 +229,17 @@ module.exports = { '@docusaurus/plugin-content-docs', { /** - * Path to data on filesystem - * relative to site dir + * Path to data on filesystem relative to site dir. */ path: 'docs', /** - * URL for editing website repo, example: 'https://github.com/facebook/docusaurus/edit/master/website/' + * URL for editing a doc in the website repo. + * Example: 'https://github.com/facebook/docusaurus/edit/master/website/' */ editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/', /** - * URL route for the blog section of your site - * do not include trailing slash + * URL route for the blog section of your site. + * *DO NOT* include a trailing slash. */ routeBasePath: 'docs', homePageId: '_index', // Document id for docs home page. @@ -255,6 +261,12 @@ module.exports = { /* require('remark-math') */ ], rehypePlugins: [], + /** + * Custom Remark and Rehype plugins passed to MDX before + * the default Docusaurus Remark and Rehype plugins. + */ + beforeDefaultRemarkPlugins: [], + beforeDefaultRehypePlugins: [], /** * Whether to display the author who last updated the doc. */ From 78136e77a27bfdb678c104e720e1b2142d3dbe4b Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 22 May 2020 23:25:23 -0400 Subject: [PATCH 10/11] feat(v2): Use pnp-webpack-plugin to support pnp module resolution (#2796) --- packages/docusaurus/package.json | 1 + packages/docusaurus/src/webpack/base.ts | 5 +++++ yarn.lock | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index fafa327e16e4..1744bb0c134f 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -69,6 +69,7 @@ "nprogress": "^0.2.0", "null-loader": "^3.0.0", "optimize-css-assets-webpack-plugin": "^5.0.3", + "pnp-webpack-plugin": "^1.6.4", "portfinder": "^1.0.25", "postcss-loader": "^3.0.0", "postcss-preset-env": "^6.7.0", diff --git a/packages/docusaurus/src/webpack/base.ts b/packages/docusaurus/src/webpack/base.ts index e413d873c819..6526b501113d 100644 --- a/packages/docusaurus/src/webpack/base.ts +++ b/packages/docusaurus/src/webpack/base.ts @@ -8,6 +8,7 @@ import fs from 'fs-extra'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'; +import PnpWebpackPlugin from 'pnp-webpack-plugin'; import path from 'path'; import TerserPlugin from 'terser-webpack-plugin'; import {Configuration, Loader} from 'webpack'; @@ -74,6 +75,10 @@ export function createBaseConfig( 'node_modules', path.resolve(fs.realpathSync(process.cwd()), 'node_modules'), ], + plugins: [PnpWebpackPlugin], + }, + resolveLoader: { + plugins: [PnpWebpackPlugin.moduleLoader(module)], }, optimization: { removeAvailableModules: false, diff --git a/yarn.lock b/yarn.lock index e9d21b70b2b4..4d677ae62b01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13023,6 +13023,13 @@ pngjs@^3.0.0, pngjs@^3.3.3: resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-3.4.0.tgz#99ca7d725965fb655814eaf65f38f12bbdbf555f" integrity sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w== +pnp-webpack-plugin@^1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.6.4.tgz#c9711ac4dc48a685dabafc86f8b6dd9f8df84149" + integrity sha512-7Wjy+9E3WwLOEL30D+m8TSTF7qJJUJLONBnwQp0518siuMxUQUbgZwssaFX+QKlZkjHZcw/IpZCt/H0srrntSg== + dependencies: + ts-pnp "^1.1.6" + popper.js@^1.14.4: version "1.16.1" resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.16.1.tgz#2a223cb3dc7b6213d740e40372be40de43e65b1b" @@ -16936,6 +16943,11 @@ tryer@^1.0.1: resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8" integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA== +ts-pnp@^1.1.6: + version "1.2.0" + resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92" + integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw== + tslib@^1.10.0, tslib@^1.9.0: version "1.11.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35" From 705f8f3c51c977216e7a76209d9d5997075de2d6 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 22 May 2020 23:26:50 -0400 Subject: [PATCH 11/11] fix(v2): Consistently use require.resolve in official plugins to resolve modules (#2797) * fix(v2): Use require.resolve to resolve loaders in official plugins * Use require.resolve to resolve client modules --- packages/docusaurus-plugin-content-blog/src/index.ts | 4 ++-- packages/docusaurus-plugin-content-docs/src/index.ts | 4 ++-- packages/docusaurus-plugin-ideal-image/src/index.ts | 4 ++-- packages/docusaurus-theme-bootstrap/src/index.js | 2 +- packages/docusaurus-theme-classic/src/index.js | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index eda67a96289d..17d8c0de1ece 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -102,7 +102,7 @@ export default function pluginContentBlog( const modules = []; if (options.admonitions) { - modules.push('remark-admonitions/styles/infima.css'); + modules.push(require.resolve('remark-admonitions/styles/infima.css')); } return modules; @@ -396,7 +396,7 @@ export default function pluginContentBlog( getCacheLoader(isServer), getBabelLoader(isServer), { - loader: '@docusaurus/mdx-loader', + loader: require.resolve('@docusaurus/mdx-loader'), options: { remarkPlugins, rehypePlugins, diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 7899c72e9b21..19405bd07d9f 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -142,7 +142,7 @@ export default function pluginContentDocs( const modules = []; if (options.admonitions) { - modules.push('remark-admonitions/styles/infima.css'); + modules.push(require.resolve('remark-admonitions/styles/infima.css')); } return modules; @@ -522,7 +522,7 @@ export default function pluginContentDocs( getCacheLoader(isServer), getBabelLoader(isServer), { - loader: '@docusaurus/mdx-loader', + loader: require.resolve('@docusaurus/mdx-loader'), options: { remarkPlugins, rehypePlugins, diff --git a/packages/docusaurus-plugin-ideal-image/src/index.ts b/packages/docusaurus-plugin-ideal-image/src/index.ts index ecc5ecba2328..2cec59ac005b 100644 --- a/packages/docusaurus-plugin-ideal-image/src/index.ts +++ b/packages/docusaurus-plugin-ideal-image/src/index.ts @@ -27,9 +27,9 @@ export default function (_context: LoadContext, options: PluginOptions) { { test: /\.(png|jpe?g|gif)$/i, use: [ - '@docusaurus/lqip-loader', + require.resolve('@docusaurus/lqip-loader'), { - loader: '@endiliey/responsive-loader', + loader: require.resolve('@endiliey/responsive-loader'), options: { emitFile: !isServer, // don't emit for server-side rendering disable: !isProd, diff --git a/packages/docusaurus-theme-bootstrap/src/index.js b/packages/docusaurus-theme-bootstrap/src/index.js index 81e9229420b2..65125a85b242 100644 --- a/packages/docusaurus-theme-bootstrap/src/index.js +++ b/packages/docusaurus-theme-bootstrap/src/index.js @@ -14,7 +14,7 @@ module.exports = function () { return path.resolve(__dirname, './theme'); }, getClientModules() { - return ['bootstrap/dist/css/bootstrap.min.css']; + return [require.resolve('bootstrap/dist/css/bootstrap.min.css')]; }, }; }; diff --git a/packages/docusaurus-theme-classic/src/index.js b/packages/docusaurus-theme-classic/src/index.js index 54c997dcd7ab..cbe3e4c91410 100644 --- a/packages/docusaurus-theme-classic/src/index.js +++ b/packages/docusaurus-theme-classic/src/index.js @@ -65,7 +65,7 @@ module.exports = function (context, options) { getClientModules() { const modules = [ - 'infima/dist/css/default/default.css', + require.resolve('infima/dist/css/default/default.css'), path.resolve(__dirname, './prism-include-languages'), ];