From b3294004d8287e7bdad24c06377c6e548d57d940 Mon Sep 17 00:00:00 2001 From: anshul Date: Mon, 3 Aug 2020 18:27:10 +0530 Subject: [PATCH 01/15] add support to ignore pages --- .../package.json | 1 + .../website/src/pages/hello/_ignore.js | 1 + .../website/src/pages/hello/_ignore.md | 1 + .../website/src/pages/hello/_ignore.mdx | 1 + .../website/src/pages/hello/_ignore.tsx | 1 + .../src/__tests__/pluginOptionSchema.test.ts | 3 +- .../src/index.ts | 10 ++++ .../src/pluginOptionSchema.ts | 2 + .../src/types.ts | 1 + website/docs/guides/creating-pages.md | 5 +- website/docs/using-plugins.md | 6 ++- website/src/pages/examples/_ignore.md | 1 + website/src/pages/examples/_ignore_mdx.mdx | 1 + .../src/pages/examples/markdownPageExample.md | 18 +++++++ yarn.lock | 52 ------------------- 15 files changed, 48 insertions(+), 56 deletions(-) create mode 100644 packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.js create mode 100644 packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.md create mode 100644 packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.mdx create mode 100644 packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.tsx create mode 100644 website/src/pages/examples/_ignore.md create mode 100644 website/src/pages/examples/_ignore_mdx.mdx diff --git a/packages/docusaurus-plugin-content-pages/package.json b/packages/docusaurus-plugin-content-pages/package.json index 92836d58ac07..23f8f963d948 100644 --- a/packages/docusaurus-plugin-content-pages/package.json +++ b/packages/docusaurus-plugin-content-pages/package.json @@ -22,6 +22,7 @@ "@hapi/joi": "17.1.1", "globby": "^10.0.1", "loader-utils": "^1.2.3", + "minimatch": "^3.0.4", "remark-admonitions": "^1.2.1" }, "peerDependencies": { diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.js b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.js new file mode 100644 index 000000000000..27672446b8f0 --- /dev/null +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.js @@ -0,0 +1 @@ +export default (a,b)=>a+b \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.md b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.md new file mode 100644 index 000000000000..a42f8b6e8ced --- /dev/null +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.md @@ -0,0 +1 @@ +# ignored \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.mdx b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.mdx new file mode 100644 index 000000000000..a42f8b6e8ced --- /dev/null +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.mdx @@ -0,0 +1 @@ +# ignored \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.tsx b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.tsx new file mode 100644 index 000000000000..53a73c1e9036 --- /dev/null +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/__fixtures__/website/src/pages/hello/_ignore.tsx @@ -0,0 +1 @@ +export default (a:number,b:number)=>a+b; \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/pluginOptionSchema.test.ts b/packages/docusaurus-plugin-content-pages/src/__tests__/pluginOptionSchema.test.ts index dd93ec0a0072..5ed170d1f1ab 100644 --- a/packages/docusaurus-plugin-content-pages/src/__tests__/pluginOptionSchema.test.ts +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/pluginOptionSchema.test.ts @@ -10,7 +10,7 @@ import {PluginOptions} from '../types'; export default function normalizePluginOptions( options: Partial, -) { +): PluginOptions { const {value, error} = PluginOptionSchema.validate(options, { convert: false, }); @@ -37,6 +37,7 @@ describe('normalizePagesPluginOptions', () => { path: 'src/my-pages', routeBasePath: 'my-pages', include: ['**/*.{js,jsx,ts,tsx}'], + exclude: ['**/$*/'], }; const value = normalizePluginOptions(userOptions); expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions}); diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index f20e4fa3e533..31d193a0aa0b 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -8,6 +8,7 @@ import globby from 'globby'; import fs from 'fs'; import path from 'path'; +import minimatch from 'minimatch'; import { encodePath, fileToPath, @@ -49,6 +50,11 @@ export default function pluginContentPages( 'docusaurus-plugin-content-pages', ); + const excludeRegex = new RegExp( + options.exclude + .map((pattern) => minimatch.makeRe(pattern).source) + .join('|'), + ); return { name: 'docusaurus-plugin-content-pages', @@ -79,6 +85,7 @@ export default function pluginContentPages( const {baseUrl} = siteConfig; const pagesFiles = await globby(include, { cwd: pagesDir, + ignore: options.exclude, }); function toMetadata(relativeSource: string): Metadata { @@ -171,6 +178,9 @@ export default function pluginContentPages( // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. metadataPath: (mdxPath: string) => { + if (excludeRegex.test(mdxPath)) { + return null; + } const aliasedSource = aliasedSitePath(mdxPath, siteDir); return path.join( dataDir, diff --git a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts index b5d3dd29ef61..061c745e5220 100644 --- a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts +++ b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts @@ -20,12 +20,14 @@ export const DEFAULT_OPTIONS: PluginOptions = { remarkPlugins: [], rehypePlugins: [], admonitions: {}, + exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}'], }; export const PluginOptionSchema = Joi.object({ path: Joi.string().default(DEFAULT_OPTIONS.path), routeBasePath: Joi.string().default(DEFAULT_OPTIONS.routeBasePath), include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include), + exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude), mdxPageComponent: Joi.string().default(DEFAULT_OPTIONS.mdxPageComponent), remarkPlugins: RemarkPluginsSchema.default(DEFAULT_OPTIONS.remarkPlugins), rehypePlugins: RehypePluginsSchema.default(DEFAULT_OPTIONS.rehypePlugins), diff --git a/packages/docusaurus-plugin-content-pages/src/types.ts b/packages/docusaurus-plugin-content-pages/src/types.ts index 9c9e2706d996..fcafefe43bf3 100644 --- a/packages/docusaurus-plugin-content-pages/src/types.ts +++ b/packages/docusaurus-plugin-content-pages/src/types.ts @@ -9,6 +9,7 @@ export interface PluginOptions { path: string; routeBasePath: string; include: string[]; + exclude: string[]; mdxPageComponent: string; remarkPlugins: ([Function, object] | Function)[]; rehypePlugins: string[]; diff --git a/website/docs/guides/creating-pages.md b/website/docs/guides/creating-pages.md index ed33097f6053..b7f048fd5082 100644 --- a/website/docs/guides/creating-pages.md +++ b/website/docs/guides/creating-pages.md @@ -91,7 +91,7 @@ In this component-based development era, it is encouraged to co-locate your styl - Add a `/src/pages/support.js` file - Create a `/src/pages/support/` directory and a `/src/pages/support/index.js` file. -The latter is preferred as it has the benefits of letting you put files related to the page within that directory. For example, a CSS module file (`styles.module.css`) with styles meant to only be used on the "Support" page. **Note:** this is merely a recommended directory structure and you will still need to manually import the CSS module file within your component module (`support/index.js`). +The latter is preferred as it has the benefits of letting you put files related to the page within that directory. For example, a CSS module file (`styles.module.css`) with styles meant to only be used on the "Support" page. **Note:** this is merely a recommended directory structure and you will still need to manually import the CSS module file within your component module (`support/index.js`). Any Markdown or Javascript file starting with `_` will be ignored and no routes will be created for that file. ```sh my-website @@ -99,6 +99,7 @@ my-website │ └── pages │ ├── styles.module.css │ ├── index.js +| ├──_ignored.js │ └── support │ ├── index.js │ └── styles.module.css @@ -107,7 +108,7 @@ my-website :::caution -All JavaScript/TypeScript files within the `src/pages/` directory will have corresponding website paths generated for them. Do not put reusable components or test files (ending with `.test.js`) into that directory otherwise they will be turned into pages, which might not be intended. +All JavaScript/TypeScript files within the `src/pages/` directory except file starting with `_` will have corresponding website paths generated for them. Do not put reusable components or test files (ending with `.test.js`) into that directory otherwise they will be turned into pages, which might not be intended. ::: diff --git a/website/docs/using-plugins.md b/website/docs/using-plugins.md index 2acc349b026c..5e43385c5f21 100644 --- a/website/docs/using-plugins.md +++ b/website/docs/using-plugins.md @@ -375,7 +375,11 @@ module.exports = { * do not include trailing slash */ routeBasePath: '', - include: ['**/*.{js,jsx}'], + include: ['**/*.{js,jsx,ts,tsx,md,mdx}'], + /** + * No Route will be created for matching files + */ + exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}'], /** * Theme component used by markdown pages. */ diff --git a/website/src/pages/examples/_ignore.md b/website/src/pages/examples/_ignore.md new file mode 100644 index 000000000000..e434aca5f881 --- /dev/null +++ b/website/src/pages/examples/_ignore.md @@ -0,0 +1 @@ +This file is ignored and no route is created but it can be imported diff --git a/website/src/pages/examples/_ignore_mdx.mdx b/website/src/pages/examples/_ignore_mdx.mdx new file mode 100644 index 000000000000..a1db81ca2519 --- /dev/null +++ b/website/src/pages/examples/_ignore_mdx.mdx @@ -0,0 +1 @@ +# other file \ No newline at end of file diff --git a/website/src/pages/examples/markdownPageExample.md b/website/src/pages/examples/markdownPageExample.md index 9cbb1bf1aa84..d88f9a8526db 100644 --- a/website/src/pages/examples/markdownPageExample.md +++ b/website/src/pages/examples/markdownPageExample.md @@ -3,6 +3,8 @@ title: Markdown Page example title description: Markdown Page example description --- +import Comp from "./\_ignore.md" + # Markdown page This is a page generated from markdown to illustrate the markdown page feature. @@ -32,3 +34,19 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; This is an apple 🍎This is an orange 🍊This is a banana 🍌 + +## Import Mdx and Md files + +```js +// *.md file +import Comp from './_ignore.md'; + +// *.mdx file +import OtherComp from './_ignore_mdx.mdx'; +``` + +import OtherComp from './\_ignore_mdx.mdx'; + + + + diff --git a/yarn.lock b/yarn.lock index 15f8f649ae5b..19af5519ec02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8346,58 +8346,6 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -docusaurus@^2.0.0-alpha.61: - version "2.0.0-alpha.61" - resolved "https://registry.yarnpkg.com/docusaurus/-/docusaurus-2.0.0-alpha.61.tgz#f347b81c98c66f1de3ecfccf63fa421ddff52fbb" - integrity sha512-qDU3nOA4Xs95tIjjSETnEuRmTukTzgxyTZ5MgMyuG7y6h4oDHtpLcYf8F+xlXuuWHKv3VSxRJNzV8fZHPgnK3g== - dependencies: - "@babel/core" "^7.9.0" - "@babel/plugin-proposal-class-properties" "^7.8.3" - "@babel/plugin-proposal-object-rest-spread" "^7.9.0" - "@babel/polyfill" "^7.8.7" - "@babel/preset-env" "^7.9.0" - "@babel/preset-react" "^7.9.4" - "@babel/register" "^7.9.0" - "@babel/traverse" "^7.9.0" - "@babel/types" "^7.9.0" - autoprefixer "^9.7.5" - babylon "^6.18.0" - chalk "^3.0.0" - classnames "^2.2.6" - commander "^4.0.1" - crowdin-cli "^0.3.0" - cssnano "^4.1.10" - escape-string-regexp "^2.0.0" - express "^4.17.1" - feed "^4.0.0" - fs-extra "^8.1.0" - gaze "^1.1.3" - github-slugger "^1.2.1" - glob "^7.1.6" - highlight.js "^9.16.2" - imagemin "^6.0.0" - imagemin-gifsicle "^6.0.1" - imagemin-jpegtran "^6.0.0" - imagemin-optipng "^6.0.0" - imagemin-svgo "^7.0.0" - lodash "^4.17.15" - markdown-toc "^1.2.0" - mkdirp "^0.5.1" - portfinder "^1.0.25" - postcss "^7.0.23" - prismjs "^1.17.1" - react "^16.8.4" - react-dev-utils "^9.1.0" - react-dom "^16.8.4" - remarkable "^2.0.0" - request "^2.88.0" - shelljs "^0.8.4" - sitemap "^3.2.2" - tcp-port-used "^1.0.1" - tiny-lr "^1.1.1" - tree-node-cli "^1.2.5" - truncate-html "^1.0.3" - dom-converter@^0.2: version "0.2.0" resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768" From 4457a2e938bd9412bddafb5088a739f23129fe89 Mon Sep 17 00:00:00 2001 From: anshul Date: Mon, 3 Aug 2020 19:25:05 +0530 Subject: [PATCH 02/15] fix import problem --- packages/docusaurus-mdx-loader/src/index.js | 10 ++++++---- packages/docusaurus-plugin-content-pages/src/index.ts | 9 --------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index 5c3f9df26a4b..2ee1a09b6ea0 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -6,7 +6,7 @@ */ const {getOptions} = require('loader-utils'); -const {readFile} = require('fs-extra'); +const {readFile, existsSync} = require('fs-extra'); const mdx = require('@mdx-js/mdx'); const emoji = require('remark-emoji'); const matter = require('gray-matter'); @@ -60,9 +60,11 @@ module.exports = async function (fileString) { if (metadataPath) { // Add as dependency of this loader result so that we can // recompile if metadata is changed. - this.addDependency(metadataPath); - const metadata = await readFile(metadataPath, 'utf8'); - exportStr += `\nexport const metadata = ${metadata};`; + if (existsSync(metadataPath)) { + this.addDependency(metadataPath); + const metadata = await readFile(metadataPath, 'utf8'); + exportStr += `\nexport const metadata = ${metadata};`; + } } } diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index 31d193a0aa0b..8744bca76768 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -8,7 +8,6 @@ import globby from 'globby'; import fs from 'fs'; import path from 'path'; -import minimatch from 'minimatch'; import { encodePath, fileToPath, @@ -50,11 +49,6 @@ export default function pluginContentPages( 'docusaurus-plugin-content-pages', ); - const excludeRegex = new RegExp( - options.exclude - .map((pattern) => minimatch.makeRe(pattern).source) - .join('|'), - ); return { name: 'docusaurus-plugin-content-pages', @@ -178,9 +172,6 @@ export default function pluginContentPages( // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. metadataPath: (mdxPath: string) => { - if (excludeRegex.test(mdxPath)) { - return null; - } const aliasedSource = aliasedSitePath(mdxPath, siteDir); return path.join( dataDir, From 284a5cf0d833c176d8684e0131c9ac5849471613 Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Mon, 3 Aug 2020 20:21:15 +0530 Subject: [PATCH 03/15] Update website/docs/guides/creating-pages.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sébastien Lorber --- website/docs/guides/creating-pages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guides/creating-pages.md b/website/docs/guides/creating-pages.md index b7f048fd5082..f28b539f23e6 100644 --- a/website/docs/guides/creating-pages.md +++ b/website/docs/guides/creating-pages.md @@ -108,7 +108,7 @@ my-website :::caution -All JavaScript/TypeScript files within the `src/pages/` directory except file starting with `_` will have corresponding website paths generated for them. Do not put reusable components or test files (ending with `.test.js`) into that directory otherwise they will be turned into pages, which might not be intended. +All JavaScript/TypeScript files within the `src/pages/` directory will have corresponding website paths generated for them. If you want to create reusable components or test files (ending with `.test.js`) into that directory, use the `exclude` option (by default, files prefixed with `_` are not turned into pages). ::: From 9ea4b0540a45702ad434b69853e3f760ee70be2d Mon Sep 17 00:00:00 2001 From: anshul Date: Mon, 3 Aug 2020 20:28:13 +0530 Subject: [PATCH 04/15] Revert "fix import problem" This reverts commit 4457a2e938bd9412bddafb5088a739f23129fe89. --- packages/docusaurus-mdx-loader/src/index.js | 10 ++++------ packages/docusaurus-plugin-content-pages/src/index.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index 2ee1a09b6ea0..5c3f9df26a4b 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -6,7 +6,7 @@ */ const {getOptions} = require('loader-utils'); -const {readFile, existsSync} = require('fs-extra'); +const {readFile} = require('fs-extra'); const mdx = require('@mdx-js/mdx'); const emoji = require('remark-emoji'); const matter = require('gray-matter'); @@ -60,11 +60,9 @@ module.exports = async function (fileString) { if (metadataPath) { // Add as dependency of this loader result so that we can // recompile if metadata is changed. - if (existsSync(metadataPath)) { - this.addDependency(metadataPath); - const metadata = await readFile(metadataPath, 'utf8'); - exportStr += `\nexport const metadata = ${metadata};`; - } + this.addDependency(metadataPath); + const metadata = await readFile(metadataPath, 'utf8'); + exportStr += `\nexport const metadata = ${metadata};`; } } diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index 8744bca76768..31d193a0aa0b 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -8,6 +8,7 @@ import globby from 'globby'; import fs from 'fs'; import path from 'path'; +import minimatch from 'minimatch'; import { encodePath, fileToPath, @@ -49,6 +50,11 @@ export default function pluginContentPages( 'docusaurus-plugin-content-pages', ); + const excludeRegex = new RegExp( + options.exclude + .map((pattern) => minimatch.makeRe(pattern).source) + .join('|'), + ); return { name: 'docusaurus-plugin-content-pages', @@ -172,6 +178,9 @@ export default function pluginContentPages( // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. metadataPath: (mdxPath: string) => { + if (excludeRegex.test(mdxPath)) { + return null; + } const aliasedSource = aliasedSitePath(mdxPath, siteDir); return path.join( dataDir, From be85fb8880d67e4d607a45ad29226e1652c4b4dc Mon Sep 17 00:00:00 2001 From: anshul Date: Mon, 3 Aug 2020 21:10:39 +0530 Subject: [PATCH 05/15] revert --- .../src/pluginOptionSchema.ts | 2 +- website/docs/guides/creating-pages.md | 2 +- website/docs/using-plugins.md | 6 +++++- website/src/pages/examples/{_ignore.md => _chapter1.md} | 0 .../src/pages/examples/{_ignore_mdx.mdx => _chapter2.mdx} | 0 website/src/pages/examples/markdownPageExample.md | 8 ++++---- 6 files changed, 11 insertions(+), 7 deletions(-) rename website/src/pages/examples/{_ignore.md => _chapter1.md} (100%) rename website/src/pages/examples/{_ignore_mdx.mdx => _chapter2.mdx} (100%) diff --git a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts index 061c745e5220..914631f9e67b 100644 --- a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts +++ b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts @@ -20,7 +20,7 @@ export const DEFAULT_OPTIONS: PluginOptions = { remarkPlugins: [], rehypePlugins: [], admonitions: {}, - exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}'], + exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}', '**/*.test.*', '**/__tests__/**'], }; export const PluginOptionSchema = Joi.object({ diff --git a/website/docs/guides/creating-pages.md b/website/docs/guides/creating-pages.md index f28b539f23e6..67fa60b58917 100644 --- a/website/docs/guides/creating-pages.md +++ b/website/docs/guides/creating-pages.md @@ -108,7 +108,7 @@ my-website :::caution -All JavaScript/TypeScript files within the `src/pages/` directory will have corresponding website paths generated for them. If you want to create reusable components or test files (ending with `.test.js`) into that directory, use the `exclude` option (by default, files prefixed with `_` are not turned into pages). +All JavaScript/TypeScript files within the `src/pages/` directory will have corresponding website paths generated for them. If you want to create reusable components into that directory, use the `exclude` option (by default, files prefixed with `_`, test files(`.test.js`) and files in `__tests__` directory are not turned into pages). ::: diff --git a/website/docs/using-plugins.md b/website/docs/using-plugins.md index 5e43385c5f21..5199c8e9e727 100644 --- a/website/docs/using-plugins.md +++ b/website/docs/using-plugins.md @@ -379,7 +379,11 @@ module.exports = { /** * No Route will be created for matching files */ - exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}'], + exclude: [ + '**/_*.{js,jsx,ts,tsx,md,mdx}', + '**/*.test.*', + '**/__tests__/**', + ], /** * Theme component used by markdown pages. */ diff --git a/website/src/pages/examples/_ignore.md b/website/src/pages/examples/_chapter1.md similarity index 100% rename from website/src/pages/examples/_ignore.md rename to website/src/pages/examples/_chapter1.md diff --git a/website/src/pages/examples/_ignore_mdx.mdx b/website/src/pages/examples/_chapter2.mdx similarity index 100% rename from website/src/pages/examples/_ignore_mdx.mdx rename to website/src/pages/examples/_chapter2.mdx diff --git a/website/src/pages/examples/markdownPageExample.md b/website/src/pages/examples/markdownPageExample.md index d88f9a8526db..f73c538ffa7a 100644 --- a/website/src/pages/examples/markdownPageExample.md +++ b/website/src/pages/examples/markdownPageExample.md @@ -3,7 +3,7 @@ title: Markdown Page example title description: Markdown Page example description --- -import Comp from "./\_ignore.md" +import Comp from "./\_chapter1.md" # Markdown page @@ -39,13 +39,13 @@ import TabItem from '@theme/TabItem'; ```js // *.md file -import Comp from './_ignore.md'; +import Comp from './_chapter1.md'; // *.mdx file -import OtherComp from './_ignore_mdx.mdx'; +import OtherComp from './_chapter2.mdx'; ``` -import OtherComp from './\_ignore_mdx.mdx'; +import OtherComp from './\_chapter2.mdx'; From 3ca071795da75c6a5b6f6a4bd18f439f541173b5 Mon Sep 17 00:00:00 2001 From: anshul Date: Mon, 3 Aug 2020 22:06:20 +0530 Subject: [PATCH 06/15] fix slash --- packages/docusaurus-plugin-content-pages/package.json | 3 ++- packages/docusaurus-plugin-content-pages/src/index.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-pages/package.json b/packages/docusaurus-plugin-content-pages/package.json index 23f8f963d948..95305beb8838 100644 --- a/packages/docusaurus-plugin-content-pages/package.json +++ b/packages/docusaurus-plugin-content-pages/package.json @@ -23,7 +23,8 @@ "globby": "^10.0.1", "loader-utils": "^1.2.3", "minimatch": "^3.0.4", - "remark-admonitions": "^1.2.1" + "remark-admonitions": "^1.2.1", + "slash": "^3.0.0" }, "peerDependencies": { "@docusaurus/core": "^2.0.0", diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index 31d193a0aa0b..f63aba1a98d7 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -9,6 +9,7 @@ import globby from 'globby'; import fs from 'fs'; import path from 'path'; import minimatch from 'minimatch'; +import slash from 'slash'; import { encodePath, fileToPath, @@ -178,7 +179,7 @@ export default function pluginContentPages( // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. metadataPath: (mdxPath: string) => { - if (excludeRegex.test(mdxPath)) { + if (excludeRegex.test(slash(mdxPath))) { return null; } const aliasedSource = aliasedSitePath(mdxPath, siteDir); From 4a74d24b252a1b3b3e880aeada69dff8b4f91371 Mon Sep 17 00:00:00 2001 From: anshul Date: Tue, 4 Aug 2020 21:18:41 +0530 Subject: [PATCH 07/15] forbid frontmatter --- packages/docusaurus-mdx-loader/src/index.js | 11 +++++++++++ packages/docusaurus-plugin-content-pages/src/index.ts | 2 ++ .../src/pluginOptionSchema.ts | 2 +- website/docs/using-plugins.md | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index 3081306ef198..3f93c0f8c99d 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -72,6 +72,17 @@ module.exports = async function (fileString) { } } + if ( + options.forbidFrontMatter && + typeof options.forbidFrontMatter === 'function' + ) { + if ( + options.forbidFrontMatter(this.resourcePath) && + Object.keys(data).length > 0 + ) { + return callback(new Error(`Front matter is forbidden in this file`)); + } + } const code = ` import React from 'react'; import { mdx } from '@mdx-js/react'; diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index f63aba1a98d7..d4c069241614 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -188,6 +188,8 @@ export default function pluginContentPages( `${docuHash(aliasedSource)}.json`, ); }, + forbidFrontMatter: (mdxPath: string) => + excludeRegex.test(slash(mdxPath)), }, }, { diff --git a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts index 914631f9e67b..92116dd86119 100644 --- a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts +++ b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts @@ -20,7 +20,7 @@ export const DEFAULT_OPTIONS: PluginOptions = { remarkPlugins: [], rehypePlugins: [], admonitions: {}, - exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}', '**/*.test.*', '**/__tests__/**'], + exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}', '**/*.test.{js,ts}', '**/__tests__/**'], }; export const PluginOptionSchema = Joi.object({ diff --git a/website/docs/using-plugins.md b/website/docs/using-plugins.md index 5199c8e9e727..13a1185c2f6c 100644 --- a/website/docs/using-plugins.md +++ b/website/docs/using-plugins.md @@ -381,7 +381,7 @@ module.exports = { */ exclude: [ '**/_*.{js,jsx,ts,tsx,md,mdx}', - '**/*.test.*', + '**/*.test.{js,ts}', '**/__tests__/**', ], /** From 1951813eb73d6a948ed7467fd6e31d1bdfcc4528 Mon Sep 17 00:00:00 2001 From: anshul Date: Tue, 4 Aug 2020 21:26:41 +0530 Subject: [PATCH 08/15] fix formatting --- .../src/pluginOptionSchema.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts index 92116dd86119..9719ed90a638 100644 --- a/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts +++ b/packages/docusaurus-plugin-content-pages/src/pluginOptionSchema.ts @@ -20,7 +20,11 @@ export const DEFAULT_OPTIONS: PluginOptions = { remarkPlugins: [], rehypePlugins: [], admonitions: {}, - exclude: ['**/_*.{js,jsx,ts,tsx,md,mdx}', '**/*.test.{js,ts}', '**/__tests__/**'], + exclude: [ + '**/_*.{js,jsx,ts,tsx,md,mdx}', + '**/*.test.{js,ts}', + '**/__tests__/**', + ], }; export const PluginOptionSchema = Joi.object({ From aafb429662a6d7467901968f0e2d1b0116327336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:07:18 +0200 Subject: [PATCH 09/15] Update website/docs/guides/creating-pages.md --- website/docs/guides/creating-pages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guides/creating-pages.md b/website/docs/guides/creating-pages.md index d000da17dfcc..7eb77ab5b981 100644 --- a/website/docs/guides/creating-pages.md +++ b/website/docs/guides/creating-pages.md @@ -91,7 +91,7 @@ In this component-based development era, it is encouraged to co-locate your styl - Add a `/src/pages/support.js` file - Create a `/src/pages/support/` directory and a `/src/pages/support/index.js` file. -The latter is preferred as it has the benefits of letting you put files related to the page within that directory. For example, a CSS module file (`styles.module.css`) with styles meant to only be used on the "Support" page. **Note:** this is merely a recommended directory structure and you will still need to manually import the CSS module file within your component module (`support/index.js`). Any Markdown or Javascript file starting with `_` will be ignored and no routes will be created for that file. +The latter is preferred as it has the benefits of letting you put files related to the page within that directory. For example, a CSS module file (`styles.module.css`) with styles meant to only be used on the "Support" page. **Note:** this is merely a recommended directory structure and you will still need to manually import the CSS module file within your component module (`support/index.js`). By default, any Markdown or Javascript file starting with `_` will be ignored, and no routes will be created for that file (see the `exclude` option). ```sh my-website From 728448b377fa86b542c1d62e7d76a499631d539c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:10:04 +0200 Subject: [PATCH 10/15] Update website/src/pages/examples/_chapter1.md --- website/src/pages/examples/_chapter1.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/src/pages/examples/_chapter1.md b/website/src/pages/examples/_chapter1.md index e434aca5f881..b7cac1eae743 100644 --- a/website/src/pages/examples/_chapter1.md +++ b/website/src/pages/examples/_chapter1.md @@ -1 +1,3 @@ -This file is ignored and no route is created but it can be imported +# Chapter 1 + +Lorem ipsum chapter 1 From 63039242de48acac48220d7e2b872f40b3d0bfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:10:23 +0200 Subject: [PATCH 11/15] Update website/src/pages/examples/_chapter2.mdx --- website/src/pages/examples/_chapter2.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/src/pages/examples/_chapter2.mdx b/website/src/pages/examples/_chapter2.mdx index a1db81ca2519..45dbbc03886f 100644 --- a/website/src/pages/examples/_chapter2.mdx +++ b/website/src/pages/examples/_chapter2.mdx @@ -1 +1,3 @@ -# other file \ No newline at end of file +# Chapter 2 + +Lorem ipsum chapter 2 From eb74fb57487fe329de722a6b484d8ae4e8dd0576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:11:33 +0200 Subject: [PATCH 12/15] Update website/src/pages/examples/markdownPageExample.md --- website/src/pages/examples/markdownPageExample.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/website/src/pages/examples/markdownPageExample.md b/website/src/pages/examples/markdownPageExample.md index f73c538ffa7a..480b1b2d77a6 100644 --- a/website/src/pages/examples/markdownPageExample.md +++ b/website/src/pages/examples/markdownPageExample.md @@ -39,10 +39,14 @@ import TabItem from '@theme/TabItem'; ```js // *.md file -import Comp from './_chapter1.md'; +import Chapter1 from './_chapter1.md'; + + // *.mdx file -import OtherComp from './_chapter2.mdx'; +import Chapter2 from './_chapter2.mdx'; + + ``` import OtherComp from './\_chapter2.mdx'; From 0208e61bd45cf6a4b0ab0d9bb300667c6d491a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:12:05 +0200 Subject: [PATCH 13/15] Update website/src/pages/examples/markdownPageExample.md --- website/src/pages/examples/markdownPageExample.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/src/pages/examples/markdownPageExample.md b/website/src/pages/examples/markdownPageExample.md index 480b1b2d77a6..1bbd34f5fdef 100644 --- a/website/src/pages/examples/markdownPageExample.md +++ b/website/src/pages/examples/markdownPageExample.md @@ -3,8 +3,6 @@ title: Markdown Page example title description: Markdown Page example description --- -import Comp from "./\_chapter1.md" - # Markdown page This is a page generated from markdown to illustrate the markdown page feature. From b35cee701b1f546079096fd244e175f0ad1ef8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:13:01 +0200 Subject: [PATCH 14/15] Update website/src/pages/examples/markdownPageExample.md --- website/src/pages/examples/markdownPageExample.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/website/src/pages/examples/markdownPageExample.md b/website/src/pages/examples/markdownPageExample.md index 1bbd34f5fdef..747393ae8c40 100644 --- a/website/src/pages/examples/markdownPageExample.md +++ b/website/src/pages/examples/markdownPageExample.md @@ -47,8 +47,10 @@ import Chapter2 from './_chapter2.mdx'; ``` -import OtherComp from './\_chapter2.mdx'; +import Chapter1 from './\_chapter2.mdx'; - + - +import Chapter1 from './\_chapter2.mdx'; + + From c36e84d574534cb7e821ea339b387d34479d26ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 5 Aug 2020 21:23:52 +0200 Subject: [PATCH 15/15] Update website/src/pages/examples/markdownPageExample.md --- website/src/pages/examples/markdownPageExample.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/pages/examples/markdownPageExample.md b/website/src/pages/examples/markdownPageExample.md index 747393ae8c40..c30f43508d31 100644 --- a/website/src/pages/examples/markdownPageExample.md +++ b/website/src/pages/examples/markdownPageExample.md @@ -51,6 +51,6 @@ import Chapter1 from './\_chapter2.mdx'; -import Chapter1 from './\_chapter2.mdx'; +import Chapter2 from './\_chapter2.mdx';