From 0813920349b97c8b6a09548241da05e8fd0d55bc Mon Sep 17 00:00:00 2001 From: Zach Badgett Date: Wed, 1 May 2019 21:57:13 -0600 Subject: [PATCH 1/3] refactor: refactor code tab split (#1369) * refactor: refactor code tab split * Add split tab unit test * Fix code tab list bug --- .eslintignore | 1 + package.json | 2 + packages/docusaurus-1.x/lib/core/Doc.js | 179 +++++++++--- .../__tests__/__fixtures__/split-tab_doc1.md | 29 ++ .../__tests__/__fixtures__/split-tab_doc2.md | 32 ++ .../__fixtures__/website/i18n/en.json | 10 + .../__fixtures__/website/siteConfig.js | 64 ++++ .../lib/core/__tests__/split-tab.test.js | 124 ++++++++ yarn.lock | 273 +++++++++++++++++- 9 files changed, 671 insertions(+), 43 deletions(-) create mode 100644 packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc1.md create mode 100644 packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc2.md create mode 100644 packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/i18n/en.json create mode 100644 packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/siteConfig.js create mode 100644 packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js diff --git a/.eslintignore b/.eslintignore index 839e0614c446..41d132a32969 100644 --- a/.eslintignore +++ b/.eslintignore @@ -9,3 +9,4 @@ website/ scripts packages/docusaurus-1.x/lib/core/metadata.js packages/docusaurus-1.x/lib/core/MetadataBlog.js +packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js diff --git a/package.json b/package.json index b5ded2d10e33..00f756c60ef5 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "devDependencies": { "babel-core": "^7.0.0-0", "babel-eslint": "8", + "enzyme": "^3.9.0", + "enzyme-adapter-react-16": "^1.12.1", "eslint": "4.x", "eslint-config-airbnb": "17.1.0", "eslint-config-prettier": "^2.9.0", diff --git a/packages/docusaurus-1.x/lib/core/Doc.js b/packages/docusaurus-1.x/lib/core/Doc.js index d31505f0bb5f..3b64b787dff6 100644 --- a/packages/docusaurus-1.x/lib/core/Doc.js +++ b/packages/docusaurus-1.x/lib/core/Doc.js @@ -19,20 +19,120 @@ const translateThisDoc = translate( 'Translate this Doc|recruitment message asking to translate the docs', ); -const splitTabsToTitleAndContent = content => { - const titles = content.match(//gms); - const tabs = content.split(//gms); - if (!titles || !tabs || !titles.length || !tabs.length) { - return []; +const splitTabsToTitleAndContent = (lines, indents) => { + let first = false; + let inBlock = false; + let whitespace = false; + const tc = []; + let current = { + content: [], + }; + lines.forEach(line => { + if (indents) { + line = line.replace(new RegExp(`^((\\t|\\s{4}){${indents}})`, 'g'), ''); + } + let pos = 0; + const end = line.length; + const isToken = (cline, cpos, ...chars) => { + for (let i = 0; i < chars.length; i++) { + if (cline.charCodeAt(cpos) !== chars[i]) { + return false; + } + cpos++; + } + return true; + }; + while (pos + 1 < end) { + // Skip all the whitespace when we first start the scan. + for (let max = end; pos < max; pos++) { + if (line.charCodeAt(pos) !== 0x20 && line.charCodeAt(pos) !== 0x0a) { + break; + } + whitespace = true; + } + // Check for the start of a comment: + for (let max = end; pos < max; pos++) { + const b = line.charCodeAt(pos); + if (b0 === 0x2d /* - */ && b1 === 0x2d /* - */) { + if (b !== 0x3e /* > */) { + throw new Error(`Invalid comment sequence "--"`); + } + break; + } + buf.push(b); + b0 = b1; + b1 = b; + } + // Clear the line out before we add it to content. + // This also means tabs can only be defined on a line by itself. + line = '\n'; + // Trim the last 2 characters: -- + current.title = String.fromCharCode(...buf) + .substring(0, buf.length - 2) + .trim(); + } + // If the first thing in a code tab is not a title it's invalid. + if (!first) { + throw new Error(`Invalid code tab markdown`); + } + // Check for code block: ``` + // If the line begins with whitespace we don't consider it a code block. + if ( + isToken(line, pos, 0x60 /* ` */, 0x60 /* ` */, 0x60 /* ` */) && + !whitespace + ) { + pos += 3; + inBlock = !inBlock; + } + pos++; + whitespace = false; + } + current.content.push(line); + }); + if (current !== null && current.title !== undefined) { + tc.push({ + title: current.title, + content: current.content.join('\n'), + }); } - tabs.shift(); - return titles.map((title, idx) => ({ - title: title.substring(4, title.length - 3).trim(), - content: tabs[idx], - })); + return tc; }; -const cleanTheCodeTag = content => { +const cleanTheCodeTag = (content, indents) => { + const prepend = (line, indent) => { + if (indent) { + return ' '.repeat(indent) + line; + } + return line; + }; const contents = content.split(/(
)(.*?)(<\/pre>)/gms);
   let inCodeBlock = false;
   const cleanContents = contents.map(c => {
@@ -47,7 +147,7 @@ const cleanTheCodeTag = content => {
     if (inCodeBlock) {
       return c.replace(/\n/g, '
'); } - return c; + return prepend(c, indents); }); return cleanContents.join(''); }; @@ -56,32 +156,43 @@ const cleanTheCodeTag = content => { class Doc extends React.Component { renderContent() { const {content} = this.props; - let inCodeTabs = false; - const contents = content.split( - /(\n)(.*?)(\n)/gms, - ); - - const renderResult = contents.map(c => { - if (c === '\n') { - inCodeTabs = true; - return ''; - } - if (c === '\n') { - inCodeTabs = false; - return ''; - } - if (inCodeTabs) { + let indents = 0; + return content.replace( + /(\t|\s{4})*?(\n)(.*?)((\n|\t|\s{4}))/gms, + m => { + const contents = m.split('\n').filter(c => { + if (!indents) { + indents = ( + c.match(/((\t|\s{4})+)/) || [] + ).length; + } + if (c.match(/(\t|\s{4})+/)) { + return false; + } + if ( + c.match( + /|/, + ) || + (indents > 0 && + c.match( + /(\t|\s{4})+(|)/, + )) + ) { + return false; + } + return true; + }); + if (indents) { + indents -= 1; + } const codeTabsMarkdownBlock = renderToStaticMarkup( - {splitTabsToTitleAndContent(c)} + {splitTabsToTitleAndContent(contents, indents)} , ); - return cleanTheCodeTag(codeTabsMarkdownBlock); - } - return c; - }); - - return renderResult.join(''); + return cleanTheCodeTag(codeTabsMarkdownBlock, indents); + }, + ); } render() { diff --git a/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc1.md b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc1.md new file mode 100644 index 000000000000..1e89fe34f56d --- /dev/null +++ b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc1.md @@ -0,0 +1,29 @@ + + +```js +console.log('Hello, world!'); +``` + +```py +print('Hello, world!') +``` + + +```C +#include + +int main() { + printf("Hello World!"); + return 0; +} +``` + + +```Pascal +program HelloWorld; +begin + WriteLn('Hello, world!'); +end. +``` + + diff --git a/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc2.md b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc2.md new file mode 100644 index 000000000000..14a7da6a4ecb --- /dev/null +++ b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/split-tab_doc2.md @@ -0,0 +1,32 @@ +1. Doc + * Hello + + + ```js + console.log('Hello, world!'); + ``` + + ```py + print('Hello, world!') + ``` + + + ```C + #include + + int main() { + printf("Hello World!"); + return 0; + } + ``` + + + ```Pascal + program HelloWorld; + begin + WriteLn('Hello, world!'); + end. + ``` + + + 1. Do that \ No newline at end of file diff --git a/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/i18n/en.json b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/i18n/en.json new file mode 100644 index 000000000000..43c508fe876d --- /dev/null +++ b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/i18n/en.json @@ -0,0 +1,10 @@ +{ + "_comment": "This file is auto-generated by write-translations.js", + "localized-strings": { + }, + "pages-strings": { + "Help Translate|recruit community translators for your project": "Help Us Translate", + "Edit this Doc|recruitment message asking to edit the doc source": "Edit", + "Translate this Doc|recruitment message asking to translate the docs": "Translate" + } +} diff --git a/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/siteConfig.js b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/siteConfig.js new file mode 100644 index 000000000000..c3aadfd8fcad --- /dev/null +++ b/packages/docusaurus-1.x/lib/core/__tests__/__fixtures__/website/siteConfig.js @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/* List of projects/orgs using your project for the users page */ + +const siteConfig = { + title: 'Docusaurus', + tagline: 'Easy to Maintain Open Source Documentation Websites', + url: 'https://docusaurus.io', + baseUrl: '/', + organizationName: 'facebook', + projectName: 'Docusaurus', + cname: 'docusaurus.io', + noIndex: false, + editUrl: 'https://github.com/facebook/docusaurus/edit/master/docs/', + headerLinks: [], + headerIcon: 'img/docusaurus.svg', + footerIcon: 'img/docusaurus_monochrome.svg', + favicon: 'img/docusaurus.ico', + algolia: { + apiKey: '3eb9507824b8be89e7a199ecaa1a9d2c', + indexName: 'docusaurus', + algoliaOptions: { + facetFilters: ['language:LANGUAGE', 'version:VERSION'], + }, + }, + colors: { + primaryColor: '#2E8555', + secondaryColor: '#205C3B', + }, + translationRecruitingLink: 'https://crowdin.com/project/docusaurus', + copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc.`, + usePrism: ['jsx'], + highlight: { + theme: 'atom-one-dark', + }, + scripts: [ + 'https://buttons.github.io/buttons.js', + 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js', + '/js/code-blocks-buttons.js', + ], + gaTrackingId: 'UA-44373548-31', + facebookAppId: '199138890728411', + facebookComments: true, + twitter: 'true', + twitterUsername: 'docusaurus', + ogImage: 'img/docusaurus.png', + twitterImage: 'img/docusaurus.png', + onPageNav: 'separate', + cleanUrl: true, + scrollToTop: true, + scrollToTopOptions: { + zIndex: 100, + }, + enableUpdateTime: true, + enableUpdateBy: true, + docsSideNavCollapsible: true, +}; + +module.exports = siteConfig; diff --git a/packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js b/packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js new file mode 100644 index 000000000000..9d35617f4d66 --- /dev/null +++ b/packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @jest-environment jsdom + */ +process.cwd = () => `${__dirname}/__fixtures__/website`; + +const React = require('react'); +const {configure, mount} = require('enzyme'); +const Adapter = require('enzyme-adapter-react-16'); +const fs = require('fs'); +const _ = require('lodash'); +const Doc = require('../Doc.js'); + +configure({adapter: new Adapter()}); + +describe('when code tabs are used correctly', () => { + // clear unique id counter + _.uniqueId = _.runInContext().uniqueId; + const props = { + content: fs.readFileSync( + `${__dirname}/__fixtures__/split-tab_doc1.md`, + 'utf-8', + ), + metadata: {}, + config: {}, + }; + let mountedDoc; + const docPage = () => { + if (!mountedDoc) { + mountedDoc = mount(); + } + return mountedDoc; + }; + const page = docPage(); + it('renders tabs correctly', () => { + const node = page.getDOMNode(); + const firstTab = node.querySelector('[data-tab$="-content-2"]').textContent; + expect('JavaScript').toEqual(firstTab); + const secondTab = node.querySelector('[data-tab$="-content-3"]') + .textContent; + expect('Python').toEqual(secondTab); + const thirdTab = node.querySelector('[data-tab$="-content-4"]').textContent; + expect('C').toEqual(thirdTab); + const fourthTab = node.querySelector('[data-tab$="-content-5"]') + .textContent; + expect('Pascal').toEqual(fourthTab); + }); + it('renders content correctly', () => { + const node = page.getDOMNode(); + const firstContent = node.querySelector('[id$="-content-2"] code') + .textContent; + expect("console.log('Hello, world!');").toEqual(firstContent); + const secondContent = node.querySelector('[id$="-content-3"] code') + .textContent; + expect("print('Hello, world!')").toEqual(secondContent); + const thirdContent = node.querySelector('[id$="-content-4"] code') + .textContent; + expect( + '#include int main() { printf("Hello World!"); return 0;}', + ).toEqual(thirdContent); + const fourthContent = node.querySelector('[id$="-content-5"] code') + .textContent; + expect("program HelloWorld;begin WriteLn('Hello, world!');end.").toEqual( + fourthContent, + ); + }); +}); + +describe('when code tab is used in a list', () => { + // clear unique id counter + _.uniqueId = _.runInContext().uniqueId; + const props = { + content: fs.readFileSync( + `${__dirname}/__fixtures__/split-tab_doc2.md`, + 'utf-8', + ), + metadata: {}, + config: {}, + }; + let mountedDoc; + const docPage = () => { + if (!mountedDoc) { + mountedDoc = mount(); + } + return mountedDoc; + }; + const page = docPage(); + it('renders tabs correctly', () => { + const node = page.getDOMNode(); + const firstTab = node.querySelector('[data-tab$="-content-2"]').textContent; + expect('JavaScript').toEqual(firstTab); + const secondTab = node.querySelector('[data-tab$="-content-3"]') + .textContent; + expect('Python').toEqual(secondTab); + const thirdTab = node.querySelector('[data-tab$="-content-4"]').textContent; + expect('C').toEqual(thirdTab); + const fourthTab = node.querySelector('[data-tab$="-content-5"]') + .textContent; + expect('Pascal').toEqual(fourthTab); + }); + it('renders content correctly', () => { + const node = page.getDOMNode(); + const firstContent = node.querySelector('[id$="-content-2"] code') + .textContent; + expect("console.log('Hello, world!');").toEqual(firstContent); + const secondContent = node.querySelector('[id$="-content-3"] code') + .textContent; + expect("print('Hello, world!')").toEqual(secondContent); + const thirdContent = node.querySelector('[id$="-content-4"] code') + .textContent; + expect( + '#include int main() { printf("Hello World!"); return 0;}', + ).toEqual(thirdContent); + const fourthContent = node.querySelector('[id$="-content-5"] code') + .textContent; + expect("program HelloWorld;begin WriteLn('Hello, world!');end.").toEqual( + fourthContent, + ); + }); +}); diff --git a/yarn.lock b/yarn.lock index b4fbcdc53366..552fbe7cdb5d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2069,6 +2069,22 @@ agentkeepalive@^3.4.1: dependencies: humanize-ms "^1.2.1" +airbnb-prop-types@^2.12.0: + version "2.13.2" + resolved "https://registry.yarnpkg.com/airbnb-prop-types/-/airbnb-prop-types-2.13.2.tgz#43147a5062dd2a4a5600e748a47b64004cc5f7fc" + integrity sha512-2FN6DlHr6JCSxPPi25EnqGaXC4OC3/B3k1lCd6MMYrZ51/Gf/1qDfaR+JElzWa+Tl7cY2aYOlsYJGFeQyVHIeQ== + dependencies: + array.prototype.find "^2.0.4" + function.prototype.name "^1.1.0" + has "^1.0.3" + is-regex "^1.0.4" + object-is "^1.0.1" + object.assign "^4.1.0" + object.entries "^1.1.0" + prop-types "^15.7.2" + prop-types-exact "^1.2.0" + react-is "^16.8.6" + ajv-errors@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d" @@ -2282,6 +2298,11 @@ array-equal@^1.0.0: resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" integrity sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM= +array-filter@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-1.0.0.tgz#baf79e62e6ef4c2a4c0b831232daffec251f9d83" + integrity sha1-uveeYubvTCpMC4MSMtr/7CUfnYM= + array-filter@~0.0.0: version "0.0.1" resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec" @@ -2347,6 +2368,23 @@ array-unique@^0.3.2: resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg= +array.prototype.find@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/array.prototype.find/-/array.prototype.find-2.0.4.tgz#556a5c5362c08648323ddaeb9de9d14bc1864c90" + integrity sha1-VWpcU2LAhkgyPdrrnenRS8GGTJA= + dependencies: + define-properties "^1.1.2" + es-abstract "^1.7.0" + +array.prototype.flat@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/array.prototype.flat/-/array.prototype.flat-1.2.1.tgz#812db8f02cad24d3fab65dd67eabe3b8903494a4" + integrity sha512-rVqIs330nLJvfC7JqYvEWwqVr5QjYF1ib02i3YJtR/fICO6527Tjpc/e4Mvmxh3GIePPreRXMdaGyC99YphWEw== + dependencies: + define-properties "^1.1.2" + es-abstract "^1.10.0" + function-bind "^1.1.1" + arrify@^1.0.0, arrify@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" @@ -3277,6 +3315,18 @@ cheerio@0.22.0, cheerio@^0.22.0: lodash.reject "^4.4.0" lodash.some "^4.4.0" +cheerio@^1.0.0-rc.2: + version "1.0.0-rc.3" + resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.3.tgz#094636d425b2e9c0f4eb91a46c05630c9a1a8bf6" + integrity sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA== + dependencies: + css-select "~1.2.0" + dom-serializer "~0.1.1" + entities "~1.1.1" + htmlparser2 "^3.9.1" + lodash "^4.15.0" + parse5 "^3.0.1" + chokidar@^2.0.0, chokidar@^2.1.5: version "2.1.5" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.5.tgz#0ae8434d962281a5f56c72869e79cb6d9d86ad4d" @@ -4547,6 +4597,11 @@ dir-glob@^2.2.1: dependencies: path-type "^3.0.0" +discontinuous-range@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz#e38331f0844bba49b9a9cb71c771585aab1bc65a" + integrity sha1-44Mx8IRLukm5qctxx3FYWqsbxlo= + dns-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d" @@ -4656,7 +4711,7 @@ dom-converter@^0.2: dependencies: utila "~0.4" -dom-serializer@0, dom-serializer@~0.1.0: +dom-serializer@0, dom-serializer@~0.1.0, dom-serializer@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0" integrity sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA== @@ -4882,6 +4937,58 @@ envify@^4.0.0: esprima "^4.0.0" through "~2.3.4" +enzyme-adapter-react-16@^1.12.1: + version "1.12.1" + resolved "https://registry.yarnpkg.com/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.12.1.tgz#6a2d74c80559d35ac0a91ca162fa45f4186290cf" + integrity sha512-GB61gvY97XvrA6qljExGY+lgI6BBwz+ASLaRKct9VQ3ozu0EraqcNn3CcrUckSGIqFGa1+CxO5gj5is5t3lwrw== + dependencies: + enzyme-adapter-utils "^1.11.0" + object.assign "^4.1.0" + object.values "^1.1.0" + prop-types "^15.7.2" + react-is "^16.8.6" + react-test-renderer "^16.0.0-0" + semver "^5.6.0" + +enzyme-adapter-utils@^1.11.0: + version "1.11.0" + resolved "https://registry.yarnpkg.com/enzyme-adapter-utils/-/enzyme-adapter-utils-1.11.0.tgz#6ffff782b1b57dd46c72a845a91fc4103956a117" + integrity sha512-0VZeoE9MNx+QjTfsjmO1Mo+lMfunucYB4wt5ficU85WB/LoetTJrbuujmHP3PJx6pSoaAuLA+Mq877x4LoxdNg== + dependencies: + airbnb-prop-types "^2.12.0" + function.prototype.name "^1.1.0" + object.assign "^4.1.0" + object.fromentries "^2.0.0" + prop-types "^15.7.2" + semver "^5.6.0" + +enzyme@^3.9.0: + version "3.9.0" + resolved "https://registry.yarnpkg.com/enzyme/-/enzyme-3.9.0.tgz#2b491f06ca966eb56b6510068c7894a7e0be3909" + integrity sha512-JqxI2BRFHbmiP7/UFqvsjxTirWoM1HfeaJrmVSZ9a1EADKkZgdPcAuISPMpoUiHlac9J4dYt81MC5BBIrbJGMg== + dependencies: + array.prototype.flat "^1.2.1" + cheerio "^1.0.0-rc.2" + function.prototype.name "^1.1.0" + has "^1.0.3" + html-element-map "^1.0.0" + is-boolean-object "^1.0.0" + is-callable "^1.1.4" + is-number-object "^1.0.3" + is-regex "^1.0.4" + is-string "^1.0.4" + is-subset "^0.1.1" + lodash.escape "^4.0.1" + lodash.isequal "^4.5.0" + object-inspect "^1.6.0" + object-is "^1.0.1" + object.assign "^4.1.0" + object.entries "^1.0.4" + object.values "^1.0.4" + raf "^3.4.0" + rst-selector-parser "^2.2.3" + string.prototype.trim "^1.1.2" + err-code@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/err-code/-/err-code-1.1.2.tgz#06e0116d3028f6aef4806849eb0ea6a748ae6960" @@ -4909,7 +5016,7 @@ error@^7.0.0: string-template "~0.2.1" xtend "~4.0.0" -es-abstract@^1.11.0, es-abstract@^1.12.0, es-abstract@^1.5.1, es-abstract@^1.7.0: +es-abstract@^1.10.0, es-abstract@^1.11.0, es-abstract@^1.12.0, es-abstract@^1.5.0, es-abstract@^1.5.1, es-abstract@^1.7.0: version "1.13.0" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.13.0.tgz#ac86145fdd5099d8dd49558ccba2eaf9b88e24e9" integrity sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg== @@ -5898,11 +6005,20 @@ fstream@^1.0.0, fstream@^1.0.2: mkdirp ">=0.5 0" rimraf "2" -function-bind@^1.1.1: +function-bind@^1.0.2, function-bind@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== +function.prototype.name@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/function.prototype.name/-/function.prototype.name-1.1.0.tgz#8bd763cc0af860a859cc5d49384d74b932cd2327" + integrity sha512-Bs0VRrTz4ghD8pTmbJQD1mZ8A/mN0ur/jGz+A6FBxPDUPkm1tNfF6bhTYPA7i7aF4lZJVr+OXTNNrnnIl58Wfg== + dependencies: + define-properties "^1.1.2" + function-bind "^1.1.1" + is-callable "^1.1.3" + functional-red-black-tree@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" @@ -6600,6 +6716,13 @@ html-comment-regex@^1.1.0: resolved "https://registry.yarnpkg.com/html-comment-regex/-/html-comment-regex-1.1.2.tgz#97d4688aeb5c81886a364faa0cad1dda14d433a7" integrity sha512-P+M65QY2JQ5Y0G9KKdlDpo0zK+/OHptU5AaBwUfAIDJZk1MYf32Frm84EcOytfJE0t5JvkAnKlmjsXDnWzCJmQ== +html-element-map@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/html-element-map/-/html-element-map-1.0.1.tgz#3c4fcb4874ebddfe4283b51c8994e7713782b592" + integrity sha512-BZSfdEm6n706/lBfXKWa4frZRZcT5k1cOusw95ijZsHlI+GdgY0v95h6IzO3iIDf2ROwq570YTwqNPqHcNMozw== + dependencies: + array-filter "^1.0.0" + html-encoding-sniffer@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz#e70d84b94da53aa375e11fe3a351be6642ca46f8" @@ -7127,6 +7250,11 @@ is-binary-path@^1.0.0: dependencies: binary-extensions "^1.0.0" +is-boolean-object@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.0.0.tgz#98f8b28030684219a95f375cfbd88ce3405dff93" + integrity sha1-mPiygDBoQhmpXzdc+9iM40Bd/5M= + is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" @@ -7137,7 +7265,7 @@ is-buffer@^2.0.0: resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725" integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw== -is-callable@^1.1.4: +is-callable@^1.1.3, is-callable@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA== @@ -7287,6 +7415,11 @@ is-natural-number@^4.0.1: resolved "https://registry.yarnpkg.com/is-natural-number/-/is-natural-number-4.0.1.tgz#ab9d76e1db4ced51e35de0c72ebecf09f734cde8" integrity sha1-q5124dtM7VHjXeDHLr7PCfc0zeg= +is-number-object@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.3.tgz#f265ab89a9f445034ef6aff15a8f00b00f551799" + integrity sha1-8mWrian0RQNO9q/xWo8AsA9VF5k= + is-number@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f" @@ -7420,6 +7553,11 @@ is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0: resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= +is-string@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.4.tgz#cc3a9b69857d621e963725a24caeec873b826e64" + integrity sha1-zDqbaYV9Yh6WNyWiTK7shzuCbmQ= + is-subset@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/is-subset/-/is-subset-0.1.1.tgz#8a59117d932de1de00f245fcdd39ce43f1e939a6" @@ -8481,6 +8619,11 @@ lodash.defaults@^4.0.1: resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c" integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw= +lodash.escape@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-4.0.1.tgz#c9044690c21e04294beaa517712fded1fa88de98" + integrity sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg= + lodash.filter@^4.4.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.filter/-/lodash.filter-4.6.0.tgz#668b1d4981603ae1cc5a6fa760143e480b4c4ace" @@ -8491,6 +8634,11 @@ lodash.flatten@^4.2.0: resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f" integrity sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8= +lodash.flattendeep@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2" + integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= + lodash.foreach@^4.3.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.foreach/-/lodash.foreach-4.5.0.tgz#1a6a35eace401280c7f06dddec35165ab27e3e53" @@ -8501,6 +8649,11 @@ lodash.get@^4.4.2: resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= +lodash.isequal@^4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA= + lodash.map@^4.4.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3" @@ -8571,7 +8724,7 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.10: +lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.10: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== @@ -9125,6 +9278,11 @@ modify-values@^1.0.0: resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== +moo@^0.4.3: + version "0.4.3" + resolved "https://registry.yarnpkg.com/moo/-/moo-0.4.3.tgz#3f847a26f31cf625a956a87f2b10fbc013bfd10e" + integrity sha512-gFD2xGCl8YFgGHsqJ9NKRVdwlioeW3mI1iqfLNYQOv0+6JRwG58Zk9DIGQgyIaffSYaO1xsKnMaYzzNr1KyIAw== + move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92" @@ -9207,6 +9365,17 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= +nearley@^2.7.10: + version "2.16.0" + resolved "https://registry.yarnpkg.com/nearley/-/nearley-2.16.0.tgz#77c297d041941d268290ec84b739d0ee297e83a7" + integrity sha512-Tr9XD3Vt/EujXbZBv6UAHYoLUSMQAxSsTnm9K3koXzjzNWY195NqALeyrzLZBKzAkL3gl92BcSogqrHjD8QuUg== + dependencies: + commander "^2.19.0" + moo "^0.4.3" + railroad-diagrams "^1.0.0" + randexp "0.4.6" + semver "^5.4.1" + needle@^2.2.1: version "2.2.4" resolved "https://registry.yarnpkg.com/needle/-/needle-2.2.4.tgz#51931bff82533b1928b7d1d69e01f1b00ffd2a4e" @@ -9589,6 +9758,16 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" +object-inspect@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.6.0.tgz#c70b6cbf72f274aab4c34c0c82f5167bf82cf15b" + integrity sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ== + +object-is@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.0.1.tgz#0aa60ec9989a0b3ed795cf4d06f62cf1ad6539b6" + integrity sha1-CqYOyZiaCz7Xlc9NBvYs8a1lObY= + object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.0.tgz#11bd22348dd2e096a045ab06f6c85bcc340fa032" @@ -9611,7 +9790,7 @@ object.assign@^4.1.0: has-symbols "^1.0.0" object-keys "^1.0.11" -object.entries@^1.0.4: +object.entries@^1.0.4, object.entries@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.1.0.tgz#2024fc6d6ba246aee38bdb0ffd5cfbcf371b7519" integrity sha512-l+H6EQ8qzGRxbkHOd5I/aHRhHDKoQXQ8g0BYt4uSweQU1/J6dZUOyWh9a2Vky35YCKjzmgxOzta2hH6kf9HuXA== @@ -9646,7 +9825,7 @@ object.pick@^1.2.0, object.pick@^1.3.0: dependencies: isobject "^3.0.1" -object.values@^1.1.0: +object.values@^1.0.4, object.values@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/object.values/-/object.values-1.1.0.tgz#bf6810ef5da3e5325790eaaa2be213ea84624da9" integrity sha512-8mf0nKLAoFX6VlNVdhGj31SVYpaNFtUnuoOXWyFEstsWRgU837AK+JYM0iAxwkSzGRbwn8cbFmgbyxj1j4VbXg== @@ -10071,6 +10250,13 @@ parse5@4.0.0: resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608" integrity sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA== +parse5@^3.0.1: + version "3.0.3" + resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c" + integrity sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA== + dependencies: + "@types/node" "*" + parse5@^5.0.0: version "5.1.0" resolved "https://registry.yarnpkg.com/parse5/-/parse5-5.1.0.tgz#c59341c9723f414c452975564c7c00a68d58acd2" @@ -10703,7 +10889,16 @@ promzard@^0.3.0: dependencies: read "1" -prop-types@^15.5.0, prop-types@^15.5.4, prop-types@^15.6.2: +prop-types-exact@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/prop-types-exact/-/prop-types-exact-1.2.0.tgz#825d6be46094663848237e3925a98c6e944e9869" + integrity sha512-K+Tk3Kd9V0odiXFP9fwDHUYRyvK3Nun3GVyPapSIs5OBkITAm15W0CPFD/YKTkMUAbc0b9CUwRQp2ybiBIq+eA== + dependencies: + has "^1.0.3" + object.assign "^4.1.0" + reflect.ownkeys "^0.2.0" + +prop-types@^15.5.0, prop-types@^15.5.4, prop-types@^15.6.2, prop-types@^15.7.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== @@ -10868,6 +11063,26 @@ quick-lru@^1.0.0: resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8" integrity sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g= +raf@^3.4.0: + version "3.4.1" + resolved "https://registry.yarnpkg.com/raf/-/raf-3.4.1.tgz#0742e99a4a6552f445d73e3ee0328af0ff1ede39" + integrity sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA== + dependencies: + performance-now "^2.1.0" + +railroad-diagrams@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e" + integrity sha1-635iZ1SN3t+4mcG5Dlc3RVnN234= + +randexp@0.4.6: + version "0.4.6" + resolved "https://registry.yarnpkg.com/randexp/-/randexp-0.4.6.tgz#e986ad5e5e31dae13ddd6f7b3019aa7c87f60ca3" + integrity sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ== + dependencies: + discontinuous-range "1.0.0" + ret "~0.1.10" + randomatic@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" @@ -11015,7 +11230,7 @@ react-helmet@^6.0.0-beta: react-fast-compare "^2.0.2" react-side-effect "^1.1.0" -react-is@^16.6.0, react-is@^16.7.0: +react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.6: version "16.8.6" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA== @@ -11081,6 +11296,16 @@ react-side-effect@^1.1.0: exenv "^1.2.1" shallowequal "^1.0.1" +react-test-renderer@^16.0.0-0: + version "16.8.6" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.8.6.tgz#188d8029b8c39c786f998aa3efd3ffe7642d5ba1" + integrity sha512-H2srzU5IWYT6cZXof6AhUcx/wEyJddQ8l7cLM/F7gDXYyPr4oq+vCIxJYXVGhId1J706sqziAjuOEjyNkfgoEw== + dependencies: + object-assign "^4.1.1" + prop-types "^15.6.2" + react-is "^16.8.6" + scheduler "^0.13.6" + react@^16.5.0, react@^16.8.4: version "16.8.5" resolved "https://registry.yarnpkg.com/react/-/react-16.8.5.tgz#49be3b655489d74504ad994016407e8a0445de66" @@ -11304,6 +11529,11 @@ reduce@^1.0.1: dependencies: object-keys "^1.1.0" +reflect.ownkeys@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/reflect.ownkeys/-/reflect.ownkeys-0.2.0.tgz#749aceec7f3fdf8b63f927a04809e90c5c0b3460" + integrity sha1-dJrO7H8/34tj+SegSAnpDFwLNGA= + refractor@^2.3.0: version "2.7.0" resolved "https://registry.yarnpkg.com/refractor/-/refractor-2.7.0.tgz#3ed9a96a619e75326a429e644241dea51be070a3" @@ -11702,6 +11932,14 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" +rst-selector-parser@^2.2.3: + version "2.2.3" + resolved "https://registry.yarnpkg.com/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz#81b230ea2fcc6066c89e3472de794285d9b03d91" + integrity sha1-gbIw6i/MYGbInjRy3nlChdmwPZE= + dependencies: + lodash.flattendeep "^4.4.0" + nearley "^2.7.10" + rsvp@^4.8.4: version "4.8.4" resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.4.tgz#b50e6b34583f3dd89329a2f23a8a2be072845911" @@ -11800,6 +12038,14 @@ scheduler@^0.13.5: loose-envify "^1.1.0" object-assign "^4.1.1" +scheduler@^0.13.6: + version "0.13.6" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889" + integrity sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + schema-utils@^0.4.5: version "0.4.7" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187" @@ -12490,6 +12736,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +string.prototype.trim@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz#d04de2c89e137f4d7d206f086b5ed2fae6be8cea" + integrity sha1-0E3iyJ4Tf019IG8Ia17S+ua+jOo= + dependencies: + define-properties "^1.1.2" + es-abstract "^1.5.0" + function-bind "^1.0.2" + string_decoder@0.10: version "0.10.31" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" From 373d17ee729e2cac3faba4780d2c7670c66e08df Mon Sep 17 00:00:00 2001 From: Endi Date: Thu, 2 May 2019 17:24:47 +0700 Subject: [PATCH 2/3] refactor(v2): simplify code by removing wip i18n & translation (#1431) * refactor(v2): remove i18n & versioning + cleaner code * totally remove i18n and versioning from plugin --- jest.config.js | 2 +- .../src/index.js | 9 +- .../__snapshots__/sidebars.test.js.snap | 83 ----- .../src/__tests__/index.test.js | 212 +---------- .../src/__tests__/metadata.test.js | 336 +----------------- .../src/__tests__/sidebars.test.js | 31 +- .../src/index.js | 161 ++------- .../src/markdown/index.js | 24 +- .../src/metadata.js | 112 +----- .../src/sidebars.js | 28 +- .../src/__tests__/index.test.js | 88 +---- .../src/index.js | 44 +-- .../src/__tests__/index.test.js | 21 +- .../src/__tests__/index.test.js | 10 +- packages/docusaurus/lib/client/App.js | 4 +- .../client/__tests__}/flat.test.js | 2 +- .../lib/default-theme/BlogPage/index.js | 16 +- .../lib/default-theme/BlogPost/index.js | 20 +- .../docusaurus/lib/default-theme/Doc/index.js | 13 +- .../lib/default-theme/DocBody/index.js | 12 +- .../lib/default-theme/Layout/index.js | 18 +- .../lib/default-theme/Markdown/index.js | 46 --- .../lib/default-theme/Navbar/index.js | 24 +- .../docusaurus/lib/default-theme/NotFound.js | 6 +- .../lib/default-theme/Pages/index.js | 21 +- .../lib/default-theme/Sidebar/index.js | 6 +- packages/docusaurus/lib/server/index.js | 11 +- .../bad-site/docusaurus.config.js | 0 .../custom-site/docusaurus.config.js | 0 .../__fixtures__/custom-site/pages/bar/baz.js | 0 .../__fixtures__/custom-site/pages/foo.js | 0 .../custom-site/pages/foo/index.js | 0 .../__fixtures__/custom-site/pages/index.js | 0 .../__fixtures__/custom-site/sidebars.json | 0 .../custom-site/static/img/docusaurus.ico | Bin .../custom-site/static/img/docusaurus.svg | 0 .../__tests__}/__fixtures__/docs/foo/bar.md | 0 .../__tests__}/__fixtures__/docs/foo/baz.md | 0 .../__tests__}/__fixtures__/docs/hello.md | 0 .../__tests__}/__fixtures__/docs/permalink.md | 2 +- .../simple-site/docusaurus.config.js | 0 .../simple-site/pages/hello/world.js | 0 .../__fixtures__/simple-site/pages/index.js | 0 .../__fixtures__/simple-site/sidebars.json | 0 .../simple-site/static/img/docusaurus.ico | Bin .../simple-site/static/img/docusaurus.svg | 0 .../simple-site/static/img/sakura.png | Bin .../static/img/slash-introducing.png | Bin .../wrong-site/docusaurus.config.js | 0 .../server/load/__tests__}/config.test.js | 4 +- .../server/load/__tests__}/loadSetup.js | 11 +- .../lib/server/load/__tests__/routes.test.js | 42 +++ packages/docusaurus/lib/server/load/env.js | 71 ---- packages/docusaurus/lib/server/load/theme.js | 11 +- .../webpack/__tests__}/base.test.js | 4 +- .../webpack/__tests__}/client.test.js | 5 +- .../webpack/__tests__}/server.test.js | 5 +- .../webpack/__tests__}/utils.test.js | 2 +- .../translated-site/docusaurus.config.js | 34 -- .../__fixtures__/translated-site/languages.js | 185 ---------- .../translated-site/pages/hello/world.js | 22 -- .../translated-site/pages/index.js | 23 -- .../translated-site/sidebars.json | 11 - .../translated-site/static/img/docusaurus.ico | Bin 3626 -> 0 bytes .../translated-site/static/img/docusaurus.svg | 1 - .../translated-site/static/img/sakura.png | Bin 79340 -> 0 bytes .../translated-site/static/img/siteConfig.js | 22 -- .../static/img/slash-introducing.png | Bin 15983 -> 0 bytes .../translated_docs/ko/foo/bar.md | 66 ---- .../translated_docs/ko/foo/baz.md | 74 ---- .../translated_docs/ko/hello.md | 54 --- .../transversioned-site/docusaurus.config.js | 34 -- .../transversioned-site/languages.js | 185 ---------- .../transversioned-site/pages/hello/world.js | 22 -- .../transversioned-site/pages/index.js | 23 -- .../transversioned-site/sidebars.json | 11 - .../static/img/docusaurus.ico | Bin 3626 -> 0 bytes .../static/img/docusaurus.svg | 1 - .../transversioned-site/static/img/sakura.png | Bin 79340 -> 0 bytes .../static/img/siteConfig.js | 22 -- .../static/img/slash-introducing.png | Bin 15983 -> 0 bytes .../translated_docs/ko/foo/bar.md | 66 ---- .../translated_docs/ko/foo/baz.md | 74 ---- .../translated_docs/ko/hello.md | 54 --- .../ko/version-1.0.0/foo/bar.md | 66 ---- .../ko/version-1.0.0/foo/baz.md | 74 ---- .../translated_docs/ko/version-1.0.0/hello.md | 54 --- .../ko/version-1.0.1/foo/bar.md | 66 ---- .../ko/version-1.0.1/foo/baz.md | 74 ---- .../translated_docs/ko/version-1.0.1/hello.md | 54 --- .../versioned_docs/version-1.0.0/foo/bar.md | 66 ---- .../versioned_docs/version-1.0.0/foo/baz.md | 74 ---- .../versioned_docs/version-1.0.0/hello.md | 54 --- .../versioned_docs/version-1.0.1/foo/bar.md | 66 ---- .../versioned_docs/version-1.0.1/foo/baz.md | 74 ---- .../versioned_docs/version-1.0.1/hello.md | 54 --- .../version-1.0.0-sidebars.json | 11 - .../version-1.0.1-sidebars.json | 11 - .../transversioned-site/versions.json | 4 - .../versioned-site/docusaurus.config.js | 33 -- .../versioned-site/pages/hello/world.js | 22 -- .../versioned-site/pages/index.js | 23 -- .../__fixtures__/versioned-site/sidebars.json | 11 - .../versioned-site/static/img/docusaurus.ico | Bin 3626 -> 0 bytes .../versioned-site/static/img/docusaurus.svg | 1 - .../versioned-site/static/img/sakura.png | Bin 79340 -> 0 bytes .../static/img/slash-introducing.png | Bin 15983 -> 0 bytes .../versioned_docs/version-1.0.0/foo/bar.md | 66 ---- .../versioned_docs/version-1.0.0/foo/baz.md | 74 ---- .../versioned_docs/version-1.0.0/hello.md | 54 --- .../versioned_docs/version-1.0.1/foo/bar.md | 66 ---- .../versioned_docs/version-1.0.1/foo/baz.md | 74 ---- .../versioned_docs/version-1.0.1/hello.md | 54 --- .../version-1.0.0-sidebars.json | 11 - .../version-1.0.1-sidebars.json | 11 - .../__fixtures__/versioned-site/versions.json | 4 - packages/docusaurus/test/jest.config.js | 23 -- .../load/__fixtures__/bad-site/languages.js | 185 ---------- .../test/load/__snapshots__/env.test.js.snap | 101 ------ packages/docusaurus/test/load/env.test.js | 106 ------ packages/docusaurus/test/load/routes.test.js | 102 ------ website/pages/index.js | 3 - yarn.lock | 5 + 123 files changed, 170 insertions(+), 4162 deletions(-) rename packages/docusaurus/{test/client => lib/client/__tests__}/flat.test.js (97%) delete mode 100644 packages/docusaurus/lib/default-theme/Markdown/index.js rename packages/docusaurus/{test/load => lib/server/load/__tests__}/__fixtures__/bad-site/docusaurus.config.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/docusaurus.config.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/pages/bar/baz.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/pages/foo.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/pages/foo/index.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/pages/index.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/sidebars.json (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/static/img/docusaurus.ico (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/custom-site/static/img/docusaurus.svg (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/docs/foo/bar.md (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/docs/foo/baz.md (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/docs/hello.md (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/docs/permalink.md (52%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/docusaurus.config.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/pages/hello/world.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/pages/index.js (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/sidebars.json (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/static/img/docusaurus.ico (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/static/img/docusaurus.svg (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/static/img/sakura.png (100%) rename packages/docusaurus/{test => lib/server/load/__tests__}/__fixtures__/simple-site/static/img/slash-introducing.png (100%) rename packages/docusaurus/{test/load => lib/server/load/__tests__}/__fixtures__/wrong-site/docusaurus.config.js (100%) rename packages/docusaurus/{test/load => lib/server/load/__tests__}/config.test.js (96%) rename packages/docusaurus/{test => lib/server/load/__tests__}/loadSetup.js (61%) create mode 100644 packages/docusaurus/lib/server/load/__tests__/routes.test.js delete mode 100644 packages/docusaurus/lib/server/load/env.js rename packages/docusaurus/{test/webpack => lib/webpack/__tests__}/base.test.js (87%) rename packages/docusaurus/{test/webpack => lib/webpack/__tests__}/client.test.js (86%) rename packages/docusaurus/{test/webpack => lib/webpack/__tests__}/server.test.js (87%) rename packages/docusaurus/{test/webpack => lib/webpack/__tests__}/utils.test.js (97%) delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/docusaurus.config.js delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/languages.js delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/pages/hello/world.js delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/pages/index.js delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/static/img/docusaurus.ico delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/static/img/docusaurus.svg delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/static/img/sakura.png delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/static/img/siteConfig.js delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/static/img/slash-introducing.png delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/translated_docs/ko/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/translated_docs/ko/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/translated-site/translated_docs/ko/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/docusaurus.config.js delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/languages.js delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/pages/hello/world.js delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/pages/index.js delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/static/img/docusaurus.ico delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/static/img/docusaurus.svg delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/static/img/sakura.png delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/static/img/siteConfig.js delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/static/img/slash-introducing.png delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.0/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/translated_docs/ko/version-1.0.1/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.0/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_docs/version-1.0.1/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_sidebars/version-1.0.0-sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versioned_sidebars/version-1.0.1-sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/transversioned-site/versions.json delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/docusaurus.config.js delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/pages/hello/world.js delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/pages/index.js delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/static/img/docusaurus.ico delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/static/img/docusaurus.svg delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/static/img/sakura.png delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/static/img/slash-introducing.png delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_docs/version-1.0.0/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/bar.md delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_docs/version-1.0.1/foo/baz.md delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_sidebars/version-1.0.0-sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json delete mode 100644 packages/docusaurus/test/__fixtures__/versioned-site/versions.json delete mode 100644 packages/docusaurus/test/jest.config.js delete mode 100644 packages/docusaurus/test/load/__fixtures__/bad-site/languages.js delete mode 100644 packages/docusaurus/test/load/__snapshots__/env.test.js.snap delete mode 100644 packages/docusaurus/test/load/env.test.js delete mode 100644 packages/docusaurus/test/load/routes.test.js diff --git a/jest.config.js b/jest.config.js index 36e32c34ed17..11af0dbe4e80 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,7 +15,7 @@ module.exports = { moduleNameMapper: { '^@lib/(.*)$': '/packages/docusaurus/lib/$1', }, - testPathIgnorePatterns: ['/node_modules/', '__fixtures__'], + testPathIgnorePatterns: ['loadSetup.js', '/node_modules/', '__fixtures__'], transform: { '^.+\\.js$': '/jest.transform.js', }, diff --git a/packages/docusaurus-plugin-content-blog/src/index.js b/packages/docusaurus-plugin-content-blog/src/index.js index 04788c6a33a9..c4b3eb14737a 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.js +++ b/packages/docusaurus-plugin-content-blog/src/index.js @@ -8,7 +8,7 @@ const globby = require('globby'); const path = require('path'); const fs = require('fs-extra'); -const {parse, idx, normalizeUrl, docuHash} = require('@docusaurus/utils'); +const {parse, normalizeUrl, docuHash} = require('@docusaurus/utils'); // TODO: Use a better slugify function that doesn't rely on a specific file extension. function fileToUrl(fileName) { @@ -50,7 +50,7 @@ class DocusaurusPluginContentBlog { // Fetches blog contents and returns metadata for the contents. async loadContent() { const {pageCount, include, routeBasePath} = this.options; - const {env, siteConfig} = this.context; + const {siteConfig} = this.context; const blogDir = this.contentPath; const {baseUrl} = siteConfig; @@ -61,9 +61,6 @@ class DocusaurusPluginContentBlog { // Prepare metadata container. const blogMetadata = []; - // Language for each blog page. - const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']); - await Promise.all( blogFiles.map(async relativeSource => { const source = path.join(blogDir, relativeSource); @@ -89,7 +86,6 @@ class DocusaurusPluginContentBlog { source, ...rawMetadata, date, - language: defaultLangTag, }; blogMetadata.push(metadata); }), @@ -108,7 +104,6 @@ class DocusaurusPluginContentBlog { page > 0 ? normalizeUrl([basePageUrl, `page/${page + 1}`]) : basePageUrl, - language: defaultLangTag, isBlogPage: true, posts: blogMetadata.slice(page * pageCount, (page + 1) * pageCount), }); diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap index 62485e8df66e..60217ba1d2c2 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap @@ -31,87 +31,4 @@ Object { } `; -exports[`loadSidebars site with sidebars & versioned sidebars 1`] = ` -Object { - "docs": Array [ - Object { - "items": Array [ - Object { - "id": "foo/bar", - "type": "doc", - }, - Object { - "id": "foo/baz", - "type": "doc", - }, - ], - "label": "Test", - "type": "category", - }, - Object { - "items": Array [ - Object { - "id": "hello", - "type": "doc", - }, - ], - "label": "Guides", - "type": "category", - }, - ], - "version-1.0.0-docs": Array [ - Object { - "items": Array [ - Object { - "id": "version-1.0.0-foo/bar", - "type": "doc", - }, - Object { - "id": "version-1.0.0-foo/baz", - "type": "doc", - }, - ], - "label": "Test", - "type": "category", - }, - Object { - "items": Array [ - Object { - "id": "version-1.0.0-hello", - "type": "doc", - }, - ], - "label": "Guides", - "type": "category", - }, - ], - "version-1.0.1-docs": Array [ - Object { - "items": Array [ - Object { - "id": "version-1.0.1-foo/bar", - "type": "doc", - }, - Object { - "id": "version-1.0.1-foo/baz", - "type": "doc", - }, - ], - "label": "Test", - "type": "category", - }, - Object { - "items": Array [ - Object { - "id": "version-1.0.1-hello", - "type": "doc", - }, - ], - "label": "Guides", - "type": "category", - }, - ], -} -`; - exports[`loadSidebars site without sidebars 1`] = `Object {}`; diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.js b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.js index 0e3c71144cfd..e1c33180e40c 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.js +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.js @@ -7,16 +7,15 @@ import '@babel/polyfill'; import path from 'path'; -import loadSetup from '../../../docusaurus/test/loadSetup'; +import loadSetup from '../../../docusaurus/lib/server/load/__tests__/loadSetup'; import DocusaurusPluginContentDocs from '../index'; describe('loadDocs', () => { test('simple website', async () => { - const {env, siteDir, siteConfig} = await loadSetup('simple'); + const {siteDir, siteConfig} = await loadSetup('simple'); const sidebarPath = path.join(siteDir, 'sidebars.json'); const plugin = new DocusaurusPluginContentDocs( { - env, siteDir, siteConfig, }, @@ -31,229 +30,22 @@ describe('loadDocs', () => { expect(docsMetadata.hello).toEqual({ category: 'Guides', id: 'hello', - language: null, - localized_id: 'hello', permalink: '/docs/hello', previous: 'foo/baz', - previous_id: 'foo/baz', previous_title: 'baz', sidebar: 'docs', source: path.join(docsDir, 'hello.md'), title: 'Hello, World !', - version: null, }); expect(docsMetadata['foo/bar']).toEqual({ category: 'Test', id: 'foo/bar', - language: null, - localized_id: 'foo/bar', next: 'foo/baz', - next_id: 'foo/baz', next_title: 'baz', permalink: '/docs/foo/bar', sidebar: 'docs', source: path.join(docsDir, 'foo', 'bar.md'), title: 'Bar', - version: null, }); }); - - test('versioned website', async () => { - const {env, siteDir, siteConfig} = await loadSetup('versioned'); - const sidebarPath = path.join(siteDir, 'sidebars.json'); - const plugin = new DocusaurusPluginContentDocs( - { - env, - siteDir, - siteConfig, - }, - { - path: '../docs', - sidebarPath, - }, - ); - const {docs: docsMetadata, versionedDir} = await plugin.loadContent(); - const docsDir = plugin.contentPath; - - expect(docsMetadata['version-1.0.0-foo/bar']).toEqual({ - category: 'Test', - id: 'version-1.0.0-foo/bar', - language: null, - localized_id: 'version-1.0.0-foo/bar', - next: 'version-1.0.0-foo/baz', - next_id: 'version-1.0.0-foo/baz', - next_title: 'Baz', - permalink: '/docs/1.0.0/foo/bar', - sidebar: 'version-1.0.0-docs', - source: path.join(versionedDir, 'version-1.0.0/foo/bar.md'), - title: 'Bar', - version: '1.0.0', - }); - expect(docsMetadata['foo/bar']).toEqual({ - category: 'Test', - id: 'foo/bar', - language: null, - localized_id: 'foo/bar', - next: 'foo/baz', - next_id: 'foo/baz', - next_title: 'baz', - permalink: '/docs/next/foo/bar', - sidebar: 'docs', - source: path.join(docsDir, 'foo/bar.md'), - title: 'Bar', - version: 'next', - }); - }); - - test('versioned & translated website', async () => { - const {env, siteDir, siteConfig} = await loadSetup('transversioned'); - const sidebarPath = path.join(siteDir, 'sidebars.json'); - const plugin = new DocusaurusPluginContentDocs( - { - env, - siteDir, - siteConfig, - }, - { - path: '../docs', - sidebarPath, - }, - ); - const { - docs: docsMetadata, - translatedDir, - versionedDir, - } = await plugin.loadContent(); - const docsDir = plugin.contentPath; - - expect(docsMetadata['ko-version-1.0.0-foo/bar']).toEqual({ - category: 'Test', - id: 'ko-version-1.0.0-foo/bar', - language: 'ko', - localized_id: 'version-1.0.0-foo/bar', - next: 'ko-version-1.0.0-foo/baz', - next_id: 'version-1.0.0-foo/baz', - next_title: 'baz', - permalink: '/docs/ko/1.0.0/foo/bar', - sidebar: 'version-1.0.0-docs', - source: path.join(translatedDir, '/ko/version-1.0.0/foo/bar.md'), - title: 'Bar', - version: '1.0.0', - }); - expect(docsMetadata['en-version-1.0.0-foo/baz']).toEqual({ - category: 'Test', - id: 'en-version-1.0.0-foo/baz', - language: 'en', - localized_id: 'version-1.0.0-foo/baz', - next: 'en-version-1.0.0-hello', - next_id: 'version-1.0.0-hello', - next_title: 'Hello, World !', - permalink: '/docs/en/1.0.0/foo/baz', - previous: 'en-version-1.0.0-foo/bar', - previous_id: 'version-1.0.0-foo/bar', - previous_title: 'Bar', - sidebar: 'version-1.0.0-docs', - source: path.join(versionedDir, 'version-1.0.0/foo/baz.md'), - title: 'Baz', - version: '1.0.0', - }); - expect(docsMetadata['en-hello']).toEqual({ - category: 'Guides', - id: 'en-hello', - language: 'en', - localized_id: 'hello', - permalink: '/docs/en/next/hello', - previous: 'en-foo/baz', - previous_id: 'foo/baz', - previous_title: 'baz', - sidebar: 'docs', - source: path.join(docsDir, 'hello.md'), - title: 'Hello, World !', - version: 'next', - }); - }); - - test('translated website', async () => { - const {env, siteDir, siteConfig} = await loadSetup('translated'); - const sidebarPath = path.join(siteDir, 'sidebars.json'); - const plugin = new DocusaurusPluginContentDocs( - { - env, - siteDir, - siteConfig, - }, - { - path: '../docs', - sidebarPath, - }, - ); - const {docs: docsMetadata, translatedDir} = await plugin.loadContent(); - const docsDir = plugin.contentPath; - - expect(docsMetadata['ko-foo/baz']).toEqual({ - category: 'Test', - id: 'ko-foo/baz', - language: 'ko', - localized_id: 'foo/baz', - next: 'ko-hello', - next_id: 'hello', - next_title: 'Hello, World !', - permalink: '/docs/ko/foo/baz', - previous: 'ko-foo/bar', - previous_id: 'foo/bar', - previous_title: 'Bar', - sidebar: 'docs', - source: path.join(translatedDir, 'ko', 'foo', 'baz.md'), - title: 'baz', - version: null, - }); - expect(docsMetadata['en-foo/bar']).toEqual({ - category: 'Test', - id: 'en-foo/bar', - language: 'en', - localized_id: 'foo/bar', - next: 'en-foo/baz', - next_id: 'foo/baz', - next_title: 'baz', - permalink: '/docs/en/foo/bar', - sidebar: 'docs', - source: path.join(docsDir, 'foo', 'bar.md'), - title: 'Bar', - version: null, - }); - }); - - test('versioned website with skip next release', async () => { - const {env, siteDir, siteConfig} = await loadSetup('versioned'); - const sidebarPath = path.join(siteDir, 'sidebars.json'); - const plugin = new DocusaurusPluginContentDocs( - { - env, - siteDir, - siteConfig, - }, - { - path: '../docs', - sidebarPath, - skipNextRelease: true, - }, - ); - const {docs: docsMetadata, versionedDir} = await plugin.loadContent(); - - expect(docsMetadata['version-1.0.0-foo/bar']).toEqual({ - category: 'Test', - id: 'version-1.0.0-foo/bar', - language: null, - localized_id: 'version-1.0.0-foo/bar', - next: 'version-1.0.0-foo/baz', - next_id: 'version-1.0.0-foo/baz', - next_title: 'Baz', - permalink: '/docs/1.0.0/foo/bar', - sidebar: 'version-1.0.0-docs', - source: path.join(versionedDir, 'version-1.0.0/foo/bar.md'), - title: 'Bar', - version: '1.0.0', - }); - expect(docsMetadata['foo/bar']).toBeUndefined(); - }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.js b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.js index 8ee433717517..a78a35767d0f 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.js +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.js @@ -8,19 +8,18 @@ import '@babel/polyfill'; import path from 'path'; import processMetadata from '../metadata'; -import loadSetup from '../../../docusaurus/test/loadSetup'; +import loadSetup from '../../../docusaurus/lib/server/load/__tests__/loadSetup'; describe('processMetadata', () => { test('normal docs', async () => { const props = await loadSetup('simple'); - const {siteDir, env, siteConfig} = props; + const {siteDir, siteConfig} = props; const docsDir = path.resolve(siteDir, '..', 'docs'); const sourceA = path.join('foo', 'bar.md'); const sourceB = path.join('hello.md'); const dataA = await processMetadata( sourceA, docsDir, - env, {}, siteConfig, 'docs', @@ -28,362 +27,35 @@ describe('processMetadata', () => { const dataB = await processMetadata( sourceB, docsDir, - env, {}, siteConfig, 'docs', ); expect(dataA).toEqual({ id: 'foo/bar', - language: null, - localized_id: 'foo/bar', permalink: '/docs/foo/bar', source: path.join(docsDir, sourceA), title: 'Bar', - version: null, }); expect(dataB).toEqual({ id: 'hello', - language: null, - localized_id: 'hello', permalink: '/docs/hello', source: path.join(docsDir, sourceB), title: 'Hello, World !', - version: null, }); }); test('docs with custom permalink', async () => { const props = await loadSetup('simple'); - const {siteDir, env, siteConfig} = props; + const {siteDir, siteConfig} = props; const docsDir = path.resolve(siteDir, '..', 'docs'); const source = path.join('permalink.md'); - const data = await processMetadata( - source, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); + const data = await processMetadata(source, docsDir, {}, siteConfig, 'docs'); expect(data).toEqual({ id: 'permalink', - language: null, - localized_id: 'permalink', permalink: '/docs/endiliey/permalink', source: path.join(docsDir, source), title: 'Permalink', - version: null, - }); - }); - - test('versioned docs (without translation)', async () => { - const props = await loadSetup('versioned'); - const {siteDir, env, siteConfig} = props; - const docsDir = path.resolve(siteDir, '..', 'docs'); - const versionedDir = path.join(siteDir, 'versioned_docs'); - const sourceA = path.join('version-1.0.0', 'foo', 'bar.md'); - const sourceB = path.join('version-1.0.0', 'hello.md'); - const sourceC = path.join('foo', 'bar.md'); - const sourceD = path.join('hello.md'); - const dataA = await processMetadata( - sourceA, - versionedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataB = await processMetadata( - sourceB, - versionedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataC = await processMetadata( - sourceC, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataD = await processMetadata( - sourceD, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); - expect(dataA).toEqual({ - id: 'version-1.0.0-foo/bar', - language: null, - localized_id: 'version-1.0.0-foo/bar', - permalink: '/docs/1.0.0/foo/bar', - source: path.join(versionedDir, sourceA), - title: 'Bar', - version: '1.0.0', - }); - expect(dataB).toEqual({ - id: 'version-1.0.0-hello', - language: null, - localized_id: 'version-1.0.0-hello', - permalink: '/docs/1.0.0/hello', - source: path.join(versionedDir, sourceB), - title: 'Hello, World !', - version: '1.0.0', - }); - expect(dataC).toEqual({ - id: 'foo/bar', - language: null, - localized_id: 'foo/bar', - permalink: '/docs/next/foo/bar', - source: path.join(docsDir, sourceC), - title: 'Bar', - version: 'next', - }); - expect(dataD).toEqual({ - id: 'hello', - language: null, - localized_id: 'hello', - permalink: '/docs/next/hello', - source: path.join(docsDir, sourceD), - title: 'Hello, World !', - version: 'next', - }); - }); - - test('translated versioned docs', async () => { - const props = await loadSetup('transversioned'); - const {siteDir, env, siteConfig} = props; - const docsDir = path.resolve(siteDir, '..', 'docs'); - const versionedDir = path.join(siteDir, 'versioned_docs'); - const translatedDir = path.join(siteDir, 'translated_docs'); - const sourceA = path.join('ko', 'version-1.0.0', 'foo', 'bar.md'); - const sourceB = path.join('ko', 'version-1.0.0', 'hello.md'); - const sourceC = path.join('ko', 'version-1.0.1', 'foo', 'bar.md'); - const sourceD = path.join('ko', 'version-1.0.1', 'hello.md'); - const sourceE = path.join('foo', 'bar.md'); - const sourceF = path.join('hello.md'); - const sourceG = path.join('version-1.0.0', 'foo', 'bar.md'); - const sourceH = path.join('version-1.0.0', 'hello.md'); - const dataA = await processMetadata( - sourceA, - translatedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataB = await processMetadata( - sourceB, - translatedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataC = await processMetadata( - sourceC, - translatedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataD = await processMetadata( - sourceD, - translatedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataE = await processMetadata( - sourceE, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataF = await processMetadata( - sourceF, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataG = await processMetadata( - sourceG, - versionedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataH = await processMetadata( - sourceH, - versionedDir, - env, - {}, - siteConfig, - 'docs', - ); - expect(dataA).toEqual({ - id: 'ko-version-1.0.0-foo/bar', - language: 'ko', - localized_id: 'version-1.0.0-foo/bar', - permalink: '/docs/ko/1.0.0/foo/bar', - source: path.join(translatedDir, sourceA), - title: 'Bar', - version: '1.0.0', - }); - expect(dataB).toEqual({ - id: 'ko-version-1.0.0-hello', - language: 'ko', - localized_id: 'version-1.0.0-hello', - permalink: '/docs/ko/1.0.0/hello', - source: path.join(translatedDir, sourceB), - title: 'Hello, World !', - version: '1.0.0', - }); - expect(dataC).toEqual({ - id: 'ko-version-1.0.1-foo/bar', - language: 'ko', - localized_id: 'version-1.0.1-foo/bar', - permalink: '/docs/ko/foo/bar', - source: path.join(translatedDir, sourceC), - title: 'Bar', - version: '1.0.1', - }); - expect(dataD).toEqual({ - id: 'ko-version-1.0.1-hello', - language: 'ko', - localized_id: 'version-1.0.1-hello', - permalink: '/docs/ko/hello', - source: path.join(translatedDir, sourceD), - title: 'Hello, World !', - version: '1.0.1', - }); - expect(dataE).toEqual({ - id: 'en-foo/bar', - language: 'en', - localized_id: 'foo/bar', - permalink: '/docs/en/next/foo/bar', - source: path.join(docsDir, sourceE), - title: 'Bar', - version: 'next', - }); - expect(dataF).toEqual({ - id: 'en-hello', - language: 'en', - localized_id: 'hello', - permalink: '/docs/en/next/hello', - source: path.join(docsDir, sourceF), - title: 'Hello, World !', - version: 'next', - }); - expect(dataG).toEqual({ - id: 'en-version-1.0.0-foo/bar', - language: 'en', - localized_id: 'version-1.0.0-foo/bar', - permalink: '/docs/en/1.0.0/foo/bar', - source: path.join(versionedDir, sourceG), - title: 'Bar', - version: '1.0.0', - }); - expect(dataH).toEqual({ - id: 'en-version-1.0.0-hello', - language: 'en', - localized_id: 'version-1.0.0-hello', - permalink: '/docs/en/1.0.0/hello', - source: path.join(versionedDir, sourceH), - title: 'Hello, World !', - version: '1.0.0', - }); - }); - - test('translated docs only', async () => { - const props = await loadSetup('translated'); - const {siteDir, env, siteConfig} = props; - const docsDir = path.resolve(siteDir, '..', 'docs'); - const translatedDir = path.join(siteDir, 'translated_docs'); - const sourceA = path.join('ko', 'foo', 'bar.md'); - const sourceB = path.join('ko', 'hello.md'); - const sourceC = path.join('foo', 'bar.md'); - const sourceD = path.join('hello.md'); - const dataA = await processMetadata( - sourceA, - translatedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataB = await processMetadata( - sourceB, - translatedDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataC = await processMetadata( - sourceC, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); - const dataD = await processMetadata( - sourceD, - docsDir, - env, - {}, - siteConfig, - 'docs', - ); - expect(dataA).toEqual({ - id: 'ko-foo/bar', - language: 'ko', - localized_id: 'foo/bar', - permalink: '/docs/ko/foo/bar', - source: path.join(translatedDir, sourceA), - title: 'Bar', - version: null, - }); - expect(dataB).toEqual({ - id: 'ko-hello', - language: 'ko', - localized_id: 'hello', - permalink: '/docs/ko/hello', - source: path.join(translatedDir, sourceB), - title: 'Hello, World !', - version: null, - }); - expect(dataC).toEqual({ - id: 'en-foo/bar', - language: 'en', - localized_id: 'foo/bar', - permalink: '/docs/en/foo/bar', - source: path.join(docsDir, sourceC), - title: 'Bar', - version: null, - }); - expect(dataD).toEqual({ - id: 'en-hello', - language: 'en', - localized_id: 'hello', - permalink: '/docs/en/hello', - source: path.join(docsDir, sourceD), - title: 'Hello, World !', - version: null, }); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js b/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js index 833144b39303..d288909e674f 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js @@ -7,7 +7,7 @@ import path from 'path'; import loadSidebars from '../sidebars'; -import loadSetup from '../../../docusaurus/test/loadSetup'; +import loadSetup from '../../../docusaurus/lib/server/load/__tests__/loadSetup'; /* eslint-disable global-require, import/no-dynamic-require */ @@ -15,38 +15,15 @@ describe('loadSidebars', () => { const fixtures = path.join(__dirname, '..', '__fixtures__'); test('normal site with sidebars', async () => { - const {env, siteDir} = await loadSetup('simple'); + const {siteDir} = await loadSetup('simple'); const sidebar = require(path.join(siteDir, 'sidebars.json')); - const result = loadSidebars({siteDir, env, sidebar}); + const result = loadSidebars({siteDir, sidebar}); expect(result).toMatchSnapshot(); }); test('site without sidebars', () => { - const env = {}; const siteDir = path.join(fixtures, 'bad-site'); - const result = loadSidebars({siteDir, env, sidebar: {}}); + const result = loadSidebars({siteDir, sidebar: {}}); expect(result).toMatchSnapshot(); }); - - test('site with sidebars & versioned sidebars', async () => { - const {env, siteDir} = await loadSetup('versioned'); - const sidebar = require(path.join(siteDir, 'sidebars.json')); - const result = loadSidebars({siteDir, env, sidebar}); - expect(result).toMatchSnapshot(); - }); - - test('site with missing versioned sidebars', async () => { - const env = { - versioning: { - enabled: true, - versions: ['2.0.0'], - }, - }; - const {siteDir} = await loadSetup('versioned'); - expect(() => { - loadSidebars({siteDir, env, sidebar: {}}); - }).toThrowErrorMatchingInlineSnapshot( - `"Failed to load versioned_sidebars/version-2.0.0-sidebars.json. It does not exist."`, - ); - }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/index.js b/packages/docusaurus-plugin-content-docs/src/index.js index a0a04e0cd3a8..ddc8cbf66ae4 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.js +++ b/packages/docusaurus-plugin-content-docs/src/index.js @@ -8,12 +8,7 @@ const globby = require('globby'); const importFresh = require('import-fresh'); const path = require('path'); -const { - getSubFolder, - idx, - normalizeUrl, - docuHash, -} = require('@docusaurus/utils'); +const {idx, normalizeUrl, docuHash} = require('@docusaurus/utils'); const createOrder = require('./order'); const loadSidebars = require('./sidebars'); @@ -28,7 +23,6 @@ const DEFAULT_OPTIONS = { // TODO: Settle themeing. docLayoutComponent: '@theme/Doc', docItemComponent: '@theme/DocBody', - skipNextRelease: false, // Skip documents from next release (default = false) }; class DocusaurusPluginContentDocs { @@ -53,123 +47,36 @@ class DocusaurusPluginContentDocs { // Fetches blog contents and returns metadata for the contents. async loadContent() { - const {include, routeBasePath, sidebarPath, skipNextRelease} = this.options; - const {siteDir, env, siteConfig} = this.context; + const {include, routeBasePath, sidebarPath} = this.options; + const {siteDir, siteConfig} = this.context; const docsDir = this.contentPath; // We don't want sidebars to be cached because of hotreloading. const sidebar = importFresh(sidebarPath); - const docsSidebars = loadSidebars({siteDir, env, sidebar}); + const docsSidebars = loadSidebars({siteDir, sidebar}); // @tested - build the docs ordering such as next, previous, category and sidebar const order = createOrder(docsSidebars); - // Settle versions & translations from environment. - const translationEnabled = idx(env, ['translation', 'enabled']); - const enabledLanguages = - translationEnabled && idx(env, ['translation', 'enabledLanguages']); - const enabledLangTags = - (enabledLanguages && enabledLanguages.map(lang => lang.tag)) || []; - const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']); - const versioningEnabled = idx(env, ['versioning', 'enabled']); - const versions = - (versioningEnabled && idx(env, ['versioning', 'versions'])) || []; - // Prepare metadata container. const docs = {}; - if (!(versioningEnabled && skipNextRelease)) { - // Metadata for default docs files. - const docsFiles = await globby(include, { - cwd: docsDir, - }); - await Promise.all( - docsFiles.map(async source => { - // Do not allow reserved version/ translated folder name in 'docs' - // e.g: 'docs/version-1.0.0/' should not be allowed as it can cause unwanted bug - const subFolder = getSubFolder( - path.resolve(docsDir, source), - docsDir, - ); - const versionsFolders = versions.map(version => `version-${version}`); - if ([...enabledLangTags, ...versionsFolders].includes(subFolder)) { - throw new Error( - `You cannot have a folder named 'docs/${subFolder}/'`, - ); - } - - const metadata = await processMetadata( - source, - docsDir, - env, - order, - siteConfig, - routeBasePath, - ); - docs[metadata.id] = metadata; - }), - ); - } - - // Metadata for non-default-language docs. - let translatedDir = null; - if (translationEnabled) { - translatedDir = path.join(siteDir, 'translated_docs'); - const translatedFiles = await globby(include, { - cwd: translatedDir, - }); - await Promise.all( - translatedFiles.map(async source => { - /* - Do not process disabled & default languages folder in `translated_docs` - e.g: 'translated_docs/ja/**' should not be processed if lang 'ja' is disabled - */ - const translatedFilePath = path.resolve(translatedDir, source); - const detectedLangTag = getSubFolder( - translatedFilePath, - translatedDir, - ); - if ( - detectedLangTag === defaultLangTag || - !enabledLangTags.includes(detectedLangTag) - ) { - return; - } - - const metadata = await processMetadata( - source, - translatedDir, - env, - order, - siteConfig, - routeBasePath, - ); - docs[metadata.id] = metadata; - }), - ); - } - - // Metadata for versioned docs. - let versionedDir = null; - if (versioningEnabled) { - versionedDir = path.join(siteDir, 'versioned_docs'); - const versionedFiles = await globby(include, { - cwd: versionedDir, - }); - await Promise.all( - versionedFiles.map(async source => { - const metadata = await processMetadata( - source, - versionedDir, - env, - order, - siteConfig, - routeBasePath, - ); - docs[metadata.id] = metadata; - }), - ); - } + // Metadata for default docs files. + const docsFiles = await globby(include, { + cwd: docsDir, + }); + await Promise.all( + docsFiles.map(async source => { + const metadata = await processMetadata( + source, + docsDir, + order, + siteConfig, + routeBasePath, + ); + docs[metadata.id] = metadata; + }), + ); // Get the titles of the previous and next ids so that we can use them. Object.keys(docs).forEach(currentID => { @@ -185,28 +92,19 @@ class DocusaurusPluginContentDocs { } }); - const sourceToMetadata = {}; + const sourceToPermalink = {}; const permalinkToId = {}; - Object.values(docs).forEach( - ({id, source, version, permalink, language}) => { - sourceToMetadata[source] = { - version, - permalink, - language, - }; - - permalinkToId[permalink] = id; - }, - ); + Object.values(docs).forEach(({id, source, permalink}) => { + sourceToPermalink[source] = permalink; + permalinkToId[permalink] = id; + }); this.content = { docs, docsDir, docsSidebars, - sourceToMetadata, + sourceToPermalink, permalinkToId, - translatedDir, - versionedDir, }; return this.content; @@ -254,9 +152,6 @@ class DocusaurusPluginContentDocs { } configureWebpack(config, isServer, {getBabelLoader, getCacheLoader}) { - const versionedDir = path.join(this.context.siteDir, 'versioned_docs'); - const translatedDir = path.join(this.context.siteDir, 'translated_docs'); - return { module: { rules: [ @@ -271,10 +166,8 @@ class DocusaurusPluginContentDocs { loader: path.resolve(__dirname, './markdown/index.js'), options: { siteConfig: this.context.siteConfig, - versionedDir, - translatedDir, docsDir: this.content.docsDir, - sourceToMetadata: this.content.sourceToMetadata, + sourceToPermalink: this.content.sourceToPermalink, }, }, ], diff --git a/packages/docusaurus-plugin-content-docs/src/markdown/index.js b/packages/docusaurus-plugin-content-docs/src/markdown/index.js index f22e12d7e6ec..5572e2fca4aa 100644 --- a/packages/docusaurus-plugin-content-docs/src/markdown/index.js +++ b/packages/docusaurus-plugin-content-docs/src/markdown/index.js @@ -7,7 +7,6 @@ const fm = require('front-matter'); const {getOptions} = require('loader-utils'); -const path = require('path'); const {resolve} = require('url'); module.exports = async function(fileString) { @@ -15,7 +14,7 @@ module.exports = async function(fileString) { const options = Object.assign({}, getOptions(this), { filepath: this.resourcePath, }); - const {versionedDir, docsDir, translatedDir, sourceToMetadata} = options; + const {docsDir, sourceToPermalink} = options; // Extract content of markdown (without frontmatter). const {body} = fm(fileString); @@ -23,19 +22,7 @@ module.exports = async function(fileString) { // Determine the source dir. e.g: /docs, /website/versioned_docs/version-1.0.0 let sourceDir; const thisSource = this.resourcePath; - if (thisSource.startsWith(translatedDir)) { - const {language, version} = sourceToMetadata[thisSource] || {}; - if (language && version && version !== 'next') { - sourceDir = path.join(translatedDir, language, `version-${version}`); - } else if (language && (!version || version === 'next')) { - sourceDir = path.join(translatedDir, language); - } - } else if (thisSource.startsWith(versionedDir)) { - const {version} = sourceToMetadata[thisSource] || {}; - if (version) { - sourceDir = path.join(versionedDir, `version-${version}`); - } - } else if (thisSource.startsWith(docsDir)) { + if (thisSource.startsWith(docsDir)) { sourceDir = docsDir; } @@ -59,10 +46,9 @@ module.exports = async function(fileString) { // Replace it to correct html link. const mdLink = mdMatch[1]; const targetSource = `${sourceDir}/${mdLink}`; - const {permalink} = - sourceToMetadata[resolve(thisSource, mdLink)] || - sourceToMetadata[targetSource] || - {}; + const permalink = + sourceToPermalink[resolve(thisSource, mdLink)] || + sourceToPermalink[targetSource]; if (permalink) { modifiedLine = modifiedLine.replace(mdLink, permalink); } diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.js b/packages/docusaurus-plugin-content-docs/src/metadata.js index 32e38c6560b7..7b9438febddc 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.js +++ b/packages/docusaurus-plugin-content-docs/src/metadata.js @@ -7,53 +7,11 @@ const fs = require('fs-extra'); const path = require('path'); -const {getSubFolder, idx, parse, normalizeUrl} = require('@docusaurus/utils'); - -function getLanguage(filepath, refDir, env) { - const translationEnabled = idx(env, ['translation', 'enabled']); - - if (translationEnabled) { - const detectedLangTag = getSubFolder(filepath, refDir); - const enabledLanguages = idx(env, ['translation', 'enabledLanguages']); - const langTags = - (enabledLanguages && enabledLanguages.map(lang => lang.tag)) || []; - if (langTags.includes(detectedLangTag)) { - return detectedLangTag; - } - - const defaultLanguage = idx(env, ['translation', 'defaultLanguage']); - if (defaultLanguage && defaultLanguage.tag) { - return defaultLanguage.tag; - } - } - - return null; -} - -function getVersion(filepath, refDir, env) { - const versioningEnabled = idx(env, ['versioning', 'enabled']); - - if (versioningEnabled) { - const subFolder = getSubFolder(filepath, refDir); - - if (subFolder) { - const detectedVersion = subFolder.replace(/^version-/, ''); - const versions = idx(env, ['versioning', 'versions']) || []; - if (versions.includes(detectedVersion)) { - return detectedVersion; - } - } - - return 'next'; - } - - return null; -} +const {parse, normalizeUrl} = require('@docusaurus/utils'); module.exports = async function processMetadata( source, refDir, - env, order, siteConfig, docsBasePath, @@ -75,44 +33,9 @@ module.exports = async function processMetadata( metadata.title = metadata.id; } - // Language. - const language = getLanguage(filepath, refDir, env); - metadata.language = language; - const langPart = (language && `${language}/`) || ''; - - // Version. - const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']); - let versionRefDir = refDir; - if (language && language !== defaultLangTag) { - versionRefDir = path.join(refDir, language); - } - const version = getVersion(filepath, versionRefDir, env); - metadata.version = version; - const latestVersion = idx(env, ['versioning', 'latestVersion']); - const versionPart = - (version && version !== latestVersion && `${version}/`) || ''; - - // Convert temporarily metadata.id to the form of dirname/id without version/lang prefix. - // e.g.: file `versioned_docs/version-1.0.0/en/foo/bar.md` with id `version-1.0.0-bar` => `foo/bar` - if (language) { - metadata.id = metadata.id.replace(new RegExp(`^${language}-`), ''); - } - - if (version) { - metadata.id = metadata.id.replace(new RegExp(`^version-${version}-`), ''); - } - const dirName = path.dirname(source); if (dirName !== '.') { - let prefix = dirName; - if (language) { - prefix = prefix.replace(new RegExp(`^${language}`), ''); - } - prefix = prefix.replace(/^\//, ''); - if (version) { - prefix = prefix.replace(new RegExp(`^version-${version}`), ''); - } - prefix = prefix.replace(/^\//, ''); + const prefix = dirName; if (prefix) { metadata.id = `${prefix}/${metadata.id}`; } @@ -132,46 +55,23 @@ module.exports = async function processMetadata( metadata.permalink .replace(/:baseUrl/, baseUrl) .replace(/:docsUrl/, docsBasePath) - .replace(/:langPart/, langPart) - .replace(/:versionPart/, versionPart) .replace(/:id/, metadata.id), ); } else { - metadata.permalink = normalizeUrl([ - baseUrl, - docsBasePath, - langPart, - versionPart, - metadata.id, - ]); - } - - // If version. - if (version && version !== 'next') { - metadata.id = `version-${version}-${metadata.id}`; - } - - // Save localized id before adding language on it. - metadata.localized_id = metadata.id; - - // If language. - if (language) { - metadata.id = `${language}-${metadata.id}`; + metadata.permalink = normalizeUrl([baseUrl, docsBasePath, metadata.id]); } // Determine order. - const id = metadata.localized_id; + const {id} = metadata; if (order[id]) { metadata.sidebar = order[id].sidebar; metadata.category = order[id].category; metadata.subCategory = order[id].subCategory; if (order[id].next) { - metadata.next_id = order[id].next; - metadata.next = (language ? `${language}-` : '') + order[id].next; + metadata.next = order[id].next; } if (order[id].previous) { - metadata.previous_id = order[id].previous; - metadata.previous = (language ? `${language}-` : '') + order[id].previous; + metadata.previous = order[id].previous; } } diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars.js b/packages/docusaurus-plugin-content-docs/src/sidebars.js index 44fbfe772068..db26d603b7d6 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars.js +++ b/packages/docusaurus-plugin-content-docs/src/sidebars.js @@ -5,10 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -const fs = require('fs-extra'); -const path = require('path'); -const {idx} = require('@docusaurus/utils'); - /** * Check that item contains only allowed keys * @@ -113,29 +109,7 @@ function normalizeSidebar(sidebars) { }, {}); } -module.exports = function loadSidebars({siteDir, env, sidebar}) { +module.exports = function loadSidebars({sidebar}) { const allSidebars = sidebar; - - // Versioned sidebars. - if (idx(env, ['versioning', 'enabled'])) { - const versions = idx(env, ['versioning', 'versions']); - if (Array.isArray(versions)) { - versions.forEach(version => { - const versionedSidebarsJSONFile = path.join( - siteDir, - 'versioned_sidebars', - `version-${version}-sidebars.json`, - ); - if (fs.existsSync(versionedSidebarsJSONFile)) { - const sidebar = require(versionedSidebarsJSONFile); // eslint-disable-line - Object.assign(allSidebars, sidebar); - } else { - const missingFile = path.relative(siteDir, versionedSidebarsJSONFile); - throw new Error(`Failed to load ${missingFile}. It does not exist.`); - } - }); - } - } - return normalizeSidebar(allSidebars); }; diff --git a/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js b/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js index 4662f7b2d1d0..4d651fd712ed 100644 --- a/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js +++ b/packages/docusaurus-plugin-content-pages/src/__tests__/index.test.js @@ -7,7 +7,7 @@ import path from 'path'; -import loadSetup from '../../../docusaurus/test/loadSetup'; +import loadSetup from '../../../docusaurus/lib/server/load/__tests__/loadSetup'; import DocusaurusPluginContentPages from '../index'; describe('docusaurus-plugin-content-pages', () => { @@ -26,93 +26,9 @@ describe('docusaurus-plugin-content-pages', () => { }, ], ], - [ - 'versioned', - pagesDir => [ - { - permalink: '/', - source: path.join(pagesDir, 'index.js'), - }, - { - permalink: '/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - ], - ], - [ - 'translated', - pagesDir => [ - { - language: 'en', - permalink: '/', - source: path.join(pagesDir, 'index.js'), - }, - { - language: 'en', - permalink: '/en/', - source: path.join(pagesDir, 'index.js'), - }, - { - language: 'ko', - permalink: '/ko/', - source: path.join(pagesDir, 'index.js'), - }, - { - language: 'en', - permalink: '/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - { - language: 'en', - permalink: '/en/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - { - language: 'ko', - permalink: '/ko/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - ], - [ - 'transversioned', - pagesDir => [ - { - language: 'en', - permalink: '/', - source: path.join(pagesDir, 'index.js'), - }, - { - language: 'en', - permalink: '/en/', - source: path.join(pagesDir, 'index.js'), - }, - { - language: 'ko', - permalink: '/ko/', - source: path.join(pagesDir, 'index.js'), - }, - { - language: 'en', - permalink: '/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - { - language: 'en', - permalink: '/en/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - { - language: 'ko', - permalink: '/ko/hello/world', - source: path.join(pagesDir, 'hello', 'world.js'), - }, - ], - ], - ], ])('%s website', async (type, expected) => { - const {env, siteDir, siteConfig} = await loadSetup(type); + const {siteDir, siteConfig} = await loadSetup(type); const plugin = new DocusaurusPluginContentPages({ - env, siteDir, siteConfig, }); diff --git a/packages/docusaurus-plugin-content-pages/src/index.js b/packages/docusaurus-plugin-content-pages/src/index.js index de6c60c45c22..f9f5d30264b1 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.js +++ b/packages/docusaurus-plugin-content-pages/src/index.js @@ -7,7 +7,7 @@ const globby = require('globby'); const path = require('path'); -const {encodePath, fileToPath, idx, docuHash} = require('@docusaurus/utils'); +const {encodePath, fileToPath, docuHash} = require('@docusaurus/utils'); const DEFAULT_OPTIONS = { path: 'pages', // Path to data on filesystem, relative to site dir. @@ -37,7 +37,7 @@ class DocusaurusPluginContentPages { async loadContent() { const {include} = this.options; - const {env, siteConfig} = this.context; + const {siteConfig} = this.context; const pagesDir = this.contentPath; const {baseUrl} = siteConfig; @@ -48,44 +48,16 @@ class DocusaurusPluginContentPages { // Prepare metadata container. const pagesMetadatas = []; - // Translation. - const translationEnabled = idx(env, ['translation', 'enabled']); - const enabledLanguages = - translationEnabled && idx(env, ['translation', 'enabledLanguages']); - const enabledLangTags = - (enabledLanguages && enabledLanguages.map(lang => lang.tag)) || []; - const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']); - await Promise.all( pagesFiles.map(async relativeSource => { const source = path.join(pagesDir, relativeSource); const pathName = encodePath(fileToPath(relativeSource)); - if (translationEnabled && enabledLangTags.length > 0) { - enabledLangTags.forEach(langTag => { - // Default lang should also be available. E.g: /en/users and /users is the same. - if (langTag === defaultLangTag) { - pagesMetadatas.push({ - permalink: pathName.replace(/^\//, baseUrl), - language: langTag, - source, - }); - } - - const metadata = { - permalink: pathName.replace(/^\//, `${baseUrl}${langTag}/`), - language: langTag, - source, - }; - pagesMetadatas.push(metadata); - }); - } else { - // Default Language. - const metadata = { - permalink: pathName.replace(/^\//, baseUrl), - source, - }; - pagesMetadatas.push(metadata); - } + // Default Language. + const metadata = { + permalink: pathName.replace(/^\//, baseUrl), + source, + }; + pagesMetadatas.push(metadata); }), ); diff --git a/packages/docusaurus-plugin-sitemap/src/__tests__/index.test.js b/packages/docusaurus-plugin-sitemap/src/__tests__/index.test.js index 5b40294b44c5..bb30f04b57e6 100644 --- a/packages/docusaurus-plugin-sitemap/src/__tests__/index.test.js +++ b/packages/docusaurus-plugin-sitemap/src/__tests__/index.test.js @@ -5,22 +5,19 @@ * LICENSE file in the root directory of this source tree. */ -import loadSetup from '../../../docusaurus/test/loadSetup'; +import loadSetup from '../../../docusaurus/lib/server/load/__tests__/loadSetup'; import DocusaurusPluginSitemap from '../index'; describe('docusaurus-plugin-sitemap', () => { describe('createSitemap', () => { - test.each(['simple', 'versioned', 'translated', 'transversioned'])( - '%s website', - async type => { - const context = await loadSetup(type); - const plugin = new DocusaurusPluginSitemap(context, null); - const sitemap = await plugin.createSitemap(context); - expect(sitemap).toContain( - ``, - ); - }, - ); + test.each(['simple'])('%s website', async type => { + const context = await loadSetup(type); + const plugin = new DocusaurusPluginSitemap(context, null); + const sitemap = await plugin.createSitemap(context); + expect(sitemap).toContain( + ``, + ); + }); test('empty site', async () => { const context = await loadSetup('empty'); diff --git a/packages/docusaurus-utils/src/__tests__/index.test.js b/packages/docusaurus-utils/src/__tests__/index.test.js index ad48fae6c006..193709b63e28 100644 --- a/packages/docusaurus-utils/src/__tests__/index.test.js +++ b/packages/docusaurus-utils/src/__tests__/index.test.js @@ -113,7 +113,7 @@ describe('load utils', () => { test('idx', () => { const a = {}; const b = {hello: 'world'}; - const env = { + const obj = { translation: { enabled: true, enabledLanguages: [ @@ -139,13 +139,13 @@ describe('load utils', () => { expect(idx(a, [('b', 'c')])).toBeUndefined(); expect(idx(b, ['hello'])).toEqual('world'); expect(idx(b, 'hello')).toEqual('world'); - expect(idx(env, 'typo')).toBeUndefined(); - expect(idx(env, 'versioning')).toEqual({ + expect(idx(obj, 'typo')).toBeUndefined(); + expect(idx(obj, 'versioning')).toEqual({ enabled: false, versions: [], }); - expect(idx(env, ['translation', 'enabled'])).toEqual(true); - expect(idx(env, ['translation', variable]).map(lang => lang.tag)).toEqual([ + expect(idx(obj, ['translation', 'enabled'])).toEqual(true); + expect(idx(obj, ['translation', variable]).map(lang => lang.tag)).toEqual([ 'en', 'ja', ]); diff --git a/packages/docusaurus/lib/client/App.js b/packages/docusaurus/lib/client/App.js index 5e9a13e6323a..61ad5ad4e50f 100644 --- a/packages/docusaurus/lib/client/App.js +++ b/packages/docusaurus/lib/client/App.js @@ -10,7 +10,6 @@ import {renderRoutes} from 'react-router-config'; import Head from '@docusaurus/Head'; // eslint-disable-line import routes from '@generated/routes'; // eslint-disable-line -import env from '@generated/env'; // eslint-disable-line import siteConfig from '@generated/docusaurus.config'; //eslint-disable-line import DocusaurusContext from '@docusaurus/context'; // eslint-disable-line import PendingNavigation from './PendingNavigation'; @@ -18,8 +17,7 @@ import PendingNavigation from './PendingNavigation'; function App() { const [context, setContext] = useState({}); return ( - + {/* TODO: this link stylesheet to infima is temporary */} { test('nested', () => { diff --git a/packages/docusaurus/lib/default-theme/BlogPage/index.js b/packages/docusaurus/lib/default-theme/BlogPage/index.js index 361e593c9a11..efa7b68715d5 100644 --- a/packages/docusaurus/lib/default-theme/BlogPage/index.js +++ b/packages/docusaurus/lib/default-theme/BlogPage/index.js @@ -7,30 +7,17 @@ import React from 'react'; -import Head from '@docusaurus/Head'; -import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; // eslint-disable-line - -import Footer from '@theme/Footer'; // eslint-disable-line import Layout from '@theme/Layout'; // eslint-disable-line import Post from '../Post'; function BlogPage(props) { - const context = useDocusaurusContext(); - const {language, siteConfig = {}} = context; - const {baseUrl, favicon} = siteConfig; const { metadata: {posts = []}, entries: BlogPosts, } = props; return ( - - - Blog - {favicon && } - {language && } - {language && } - +
@@ -44,7 +31,6 @@ function BlogPage(props) {
-