Skip to content

Commit

Permalink
Merge branch 'master' of github.com:facebook/docusaurus into lex111/s…
Browse files Browse the repository at this point in the history
…earch-input-medium-screens
  • Loading branch information
lex111 committed May 23, 2020
2 parents f894133 + 705f8f3 commit 8199bef
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 73 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
20 changes: 9 additions & 11 deletions packages/docusaurus-init/templates/bootstrap/docs/doc1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ 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_**.

Expand All @@ -41,19 +41,17 @@ 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).
* Unordered list can use asterisks

⋅⋅⋅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.)
- Or minuses

- Unordered list can use asterisks

* Or minuses

- Or pluses
+ Or pluses

---

Expand Down
20 changes: 9 additions & 11 deletions packages/docusaurus-init/templates/classic/docs/doc1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ 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_**.

Expand All @@ -41,19 +41,17 @@ 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).
* Unordered list can use asterisks

⋅⋅⋅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.)
- Or minuses

- Unordered list can use asterisks

* Or minuses

- Or pluses
+ Or pluses

---

Expand Down
22 changes: 10 additions & 12 deletions packages/docusaurus-init/templates/facebook/docs/doc1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ 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_**.

Expand All @@ -41,19 +41,17 @@ 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).
* Unordered list can use asterisks

⋅⋅⋅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.)
- Or minuses

- Unordered list can use asterisks

* Or minuses

- Or pluses
+ Or pluses

---

Expand Down Expand Up @@ -102,7 +100,7 @@ alert(s);

```python
s = "Python syntax highlighting"
print s
print(s)
```

```
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-mdx-loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []),
],
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-ideal-image/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-preset-bootstrap/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
};
};
18 changes: 10 additions & 8 deletions packages/docusaurus-preset-classic/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
};
};
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-bootstrap/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')];
},
};
};
12 changes: 10 additions & 2 deletions packages/docusaurus-theme-classic/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -57,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'),
];

Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions packages/docusaurus/src/server/plugins/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -15,9 +16,16 @@ export function initPlugins({
pluginConfigs: PluginConfig[];
context: LoadContext;
}): Plugin<any>[] {
// 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<any>[] = pluginConfigs
.map((pluginItem) => {
let pluginModuleImport;
let pluginModuleImport: string | undefined;
let pluginOptions = {};

if (!pluginItem) {
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions website/docs/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
};
};
```
Expand Down
Loading

0 comments on commit 8199bef

Please sign in to comment.