diff --git a/.eslintrc.js b/.eslintrc.js index 051366201728..c24b8215bd2d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,7 +19,8 @@ module.exports = { }, parser: '@typescript-eslint/parser', parserOptions: { - allowImportExportEverywhere: true, + // tsconfigRootDir: __dirname, + // project: ['./tsconfig.json', './website/tsconfig.json'], }, globals: { JSX: true, @@ -30,6 +31,8 @@ module.exports = { 'plugin:jest/recommended', 'airbnb', 'plugin:@typescript-eslint/recommended', + // 'plugin:@typescript-eslint/recommended-requiring-type-checking', + // 'plugin:@typescript-eslint/strict', 'plugin:regexp/recommended', 'prettier', 'plugin:@docusaurus/all', @@ -302,6 +305,9 @@ module.exports = { 'react/prop-types': OFF, 'react/require-default-props': [ERROR, {ignoreFunctionalComponents: true}], + '@typescript-eslint/consistent-type-definitions': OFF, + '@typescript-eslint/require-await': OFF, + '@typescript-eslint/ban-ts-comment': [ ERROR, {'ts-expect-error': 'allow-with-description'}, @@ -363,20 +369,39 @@ module.exports = { overrides: [ { files: [ - 'packages/docusaurus-*/src/theme/**/*.js', - 'packages/docusaurus-*/src/theme/**/*.ts', - 'packages/docusaurus-*/src/theme/**/*.tsx', + 'packages/docusaurus-*/src/theme/**/*.{js,ts,tsx}', + 'packages/docusaurus/src/client/**/*.{js,ts,tsx}', ], rules: { - 'import/no-named-export': ERROR, + 'no-restricted-imports': [ + 'error', + { + patterns: [ + // Prevent importing lodash in client bundle for bundle size + 'lodash', + 'lodash.**', + 'lodash/**', + // Prevent importing server code in client bundle + '**/../babel/**', + '**/../server/**', + '**/../commands/**', + '**/../webpack/**', + ], + }, + ], }, }, { files: [ - 'packages/create-docusaurus/templates/**/*.js', - 'packages/create-docusaurus/templates/**/*.ts', - 'packages/create-docusaurus/templates/**/*.tsx', + 'packages/docusaurus-*/src/theme/**/*.{js,ts,tsx}', + 'packages/docusaurus/src/client/theme-fallback/**/*.{js,ts,tsx}', ], + rules: { + 'import/no-named-export': ERROR, + }, + }, + { + files: ['packages/create-docusaurus/templates/**/*.{js,ts,tsx}'], rules: { 'header/header': OFF, 'global-require': OFF, @@ -391,14 +416,14 @@ module.exports = { }, }, { - files: ['*.ts', '*.tsx'], + files: ['*.{ts,tsx}'], rules: { 'no-undef': OFF, 'import/no-import-module-exports': OFF, }, }, { - files: ['*.js', '*.mjs', '.cjs'], + files: ['*.{js,mjs,cjs}'], rules: { // Make JS code directly runnable in Node. '@typescript-eslint/no-var-requires': OFF, @@ -419,8 +444,7 @@ module.exports = { // Internal files where extraneous deps don't matter much at long as // they run files: [ - '*.test.ts', - '*.test.tsx', + '*.test.{js,ts,tsx}', 'admin/**', 'jest/**', 'website/**', @@ -431,5 +455,9 @@ module.exports = { 'import/no-extraneous-dependencies': OFF, }, }, + { + files: ['packages/eslint-plugin/**/*.{js,ts}'], + extends: ['plugin:eslint-plugin/recommended'], + }, ], }; diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 92b9f5319f84..ef3e2d103474 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -64,11 +64,6 @@ jobs: matrix: nodeLinker: [pnp, node-modules] variant: [-s, -st] - exclude: - # Running tsc on PnP requires additional installations, which is not - # worthwhile for a simple E2E test - - variant: -st - nodeLinker: pnp steps: - name: Checkout uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3 @@ -98,13 +93,21 @@ jobs: working-directory: ../test-website env: YARN_ENABLE_IMMUTABLE_INSTALLS: false # Yarn berry should create the lockfile, despite CI env + - name: Install missing dependencies + if: matrix.variant == '-st' && matrix.nodeLinker == 'pnp' + run: | + # These dependencies are referenced in the init project, not by our packages + yarn add @docusaurus/theme-classic @docusaurus/types @types/node + yarn config set packageExtensions --json '{ "unified@^9.2.2": { "dependencies": { "@types/unist": "^2.0.6" } } }' + working-directory: ../test-website - name: Start test-website project run: yarn start --no-open working-directory: ../test-website env: E2E_TEST: true - name: Type check - if: matrix.variant == '-st' + # TODO: there're some lingering issues with PnP + tsc. Enable tsc in PnP later. + if: matrix.variant == '-st' && matrix.nodeLinker != 'pnp' run: yarn typecheck working-directory: ../test-website - name: Build test-website project diff --git a/CHANGELOG.md b/CHANGELOG.md index bb3245d49f70..22ab4e6fa124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,115 @@ # Docusaurus 2 Changelog +## 2.0.0-beta.21 (2022-05-27) + +#### :boom: Breaking Change + +- `docusaurus-plugin-pwa` + - [#7422](https://github.com/facebook/docusaurus/pull/7422) refactor(pwa): remove reloadPopup option in favor of swizzling ([@Josh-Cena](https://github.com/Josh-Cena)) +- `create-docusaurus`, `docusaurus-cssnano-preset`, `docusaurus-logger`, `docusaurus-mdx-loader`, `docusaurus-migrate`, `docusaurus-plugin-client-redirects`, `docusaurus-plugin-content-blog`, `docusaurus-plugin-content-docs`, `docusaurus-plugin-content-pages`, `docusaurus-plugin-debug`, `docusaurus-plugin-google-analytics`, `docusaurus-plugin-google-gtag`, `docusaurus-plugin-ideal-image`, `docusaurus-plugin-pwa`, `docusaurus-plugin-sitemap`, `docusaurus-preset-classic`, `docusaurus-remark-plugin-npm2yarn`, `docusaurus-theme-classic`, `docusaurus-theme-common`, `docusaurus-theme-live-codeblock`, `docusaurus-theme-search-algolia`, `docusaurus-theme-translations`, `docusaurus-utils-common`, `docusaurus-utils-validation`, `docusaurus-utils`, `docusaurus`, `eslint-plugin`, `lqip-loader` + - [#7501](https://github.com/facebook/docusaurus/pull/7501) chore: require Node 16.14 ([@Josh-Cena](https://github.com/Josh-Cena)) + +#### :rocket: New Feature + +- `docusaurus-plugin-sitemap` + - [#7469](https://github.com/facebook/docusaurus/pull/7469) feat(sitemap): allow customizing the output name ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-utils`, `docusaurus` + - [#7371](https://github.com/facebook/docusaurus/pull/7371) feat(core): support docusaurus.config.cjs as default file name ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus` + - [#7500](https://github.com/facebook/docusaurus/pull/7500) feat: make docusaurus serve automatically open in browser ([@Zamiell](https://github.com/Zamiell)) + - [#7452](https://github.com/facebook/docusaurus/pull/7452) feat: add --no-minify flag to docusaurus start ([@lanegoolsby](https://github.com/lanegoolsby)) +- `docusaurus-theme-classic` + - [#7357](https://github.com/facebook/docusaurus/pull/7357) feat(theme-classic): allow className as option for type: "search" ([@JPeer264](https://github.com/JPeer264)) + +#### :bug: Bug Fix + +- `docusaurus` + - [#7362](https://github.com/facebook/docusaurus/pull/7362) fix: always emit SEO title + og:title meta ([@charleskorn](https://github.com/charleskorn)) + - [#7453](https://github.com/facebook/docusaurus/pull/7453) fix(core): avoid using logger and fs.readJSON in SSR ([@Josh-Cena](https://github.com/Josh-Cena)) + - [#7369](https://github.com/facebook/docusaurus/pull/7369) fix(cli): output correct path when swizzling bare-file component in subfolder ([@Josh-Cena](https://github.com/Josh-Cena)) + - [#7360](https://github.com/facebook/docusaurus/pull/7360) fix(core): allow githubPort in config validation ([@mhughes2k](https://github.com/mhughes2k)) +- `docusaurus-plugin-google-gtag` + - [#7424](https://github.com/facebook/docusaurus/pull/7424) fix(gtag): send the newly rendered page's title instead of the old one's ([@ori-shalom](https://github.com/ori-shalom)) +- `create-docusaurus`, `docusaurus-utils` + - [#7507](https://github.com/facebook/docusaurus/pull/7507) fix(create-docusaurus): potential security issue with command injection ([@slorber](https://github.com/slorber)) +- `docusaurus-module-type-aliases`, `docusaurus-theme-classic`, `docusaurus` + - [#7492](https://github.com/facebook/docusaurus/pull/7492) fix(core): always treat error boundary fallback as a callback ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-theme-classic` + - [#7438](https://github.com/facebook/docusaurus/pull/7438) fix(theme-classic): allow nested task lists to preserve the indent ([@Josh-Cena](https://github.com/Josh-Cena)) + - [#7430](https://github.com/facebook/docusaurus/pull/7430) fix(theme-classic): consistently apply the right active class name for all navbar items ([@Josh-Cena](https://github.com/Josh-Cena)) + - [#7411](https://github.com/facebook/docusaurus/pull/7411) fix(theme-classic): autocollapse sidebar categories when navigating with paginator ([@pranabdas](https://github.com/pranabdas)) + - [#7363](https://github.com/facebook/docusaurus/pull/7363) fix(theme-classic): resolve customCss from site dir ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-utils` + - [#7464](https://github.com/facebook/docusaurus/pull/7464) fix(utils): fix Markdown link replacement when link text is same as href ([@Josh-Cena](https://github.com/Josh-Cena)) + - [#7458](https://github.com/facebook/docusaurus/pull/7458) fix(utils): avoid replacing Markdown links missing the directly next link ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-mdx-loader` + - [#7392](https://github.com/facebook/docusaurus/pull/7392) fix(mdx-loader): use React.Fragment as fragment factory ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-plugin-content-docs` + - [#7385](https://github.com/facebook/docusaurus/pull/7385) fix(content-docs): restore functionality when a category only has index page ([@Josh-Cena](https://github.com/Josh-Cena)) + +#### :nail_care: Polish + +- `docusaurus-theme-translations` + - [#7493](https://github.com/facebook/docusaurus/pull/7493) chore(theme-translations): complete French translations ([@forresst](https://github.com/forresst)) + - [#7474](https://github.com/facebook/docusaurus/pull/7474) chore(theme-translations): complete zh translations ([@Josh-Cena](https://github.com/Josh-Cena)) + - [#7400](https://github.com/facebook/docusaurus/pull/7400) chore(theme-translations): complete Farsi translations ([@massoudmaboudi](https://github.com/massoudmaboudi)) +- `docusaurus` + - [#7499](https://github.com/facebook/docusaurus/pull/7499) fix: avoid printing period after localhost URL ([@Zamiell](https://github.com/Zamiell)) +- `create-docusaurus` + - [#7374](https://github.com/facebook/docusaurus/pull/7374) refactor(create): clean up logic when prompting for unspecified arguments ([@Josh-Cena](https://github.com/Josh-Cena)) + +#### :memo: Documentation + +- [#7503](https://github.com/facebook/docusaurus/pull/7503) docs: document MDXComponents scope ([@Josh-Cena](https://github.com/Josh-Cena)) +- [#7497](https://github.com/facebook/docusaurus/pull/7497) docs: link every reference of types in API table to the type definition ([@Zamiell](https://github.com/Zamiell)) +- [#7407](https://github.com/facebook/docusaurus/pull/7407) docs: add Azure SWA as deployment option ([@nitya](https://github.com/nitya)) +- [#7390](https://github.com/facebook/docusaurus/pull/7390) fix(website): use react-lite-youtube-embed for lazy YouTube video ([@matkoch](https://github.com/matkoch)) + +#### :wrench: Maintenance + +- `create-docusaurus`, `docusaurus-logger`, `docusaurus-mdx-loader`, `docusaurus-migrate`, `docusaurus-module-type-aliases`, `docusaurus-plugin-client-redirects`, `docusaurus-plugin-content-blog`, `docusaurus-plugin-content-docs`, `docusaurus-plugin-content-pages`, `docusaurus-plugin-debug`, `docusaurus-plugin-google-gtag`, `docusaurus-plugin-ideal-image`, `docusaurus-plugin-pwa`, `docusaurus-plugin-sitemap`, `docusaurus-remark-plugin-npm2yarn`, `docusaurus-theme-classic`, `docusaurus-theme-common`, `docusaurus-theme-live-codeblock`, `docusaurus-theme-search-algolia`, `docusaurus-theme-translations`, `docusaurus-utils-validation`, `docusaurus-utils`, `docusaurus`, `lqip-loader`, `stylelint-copyright` + - [#7477](https://github.com/facebook/docusaurus/pull/7477) refactor: fix a lot of errors in type-aware linting ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-theme-classic`, `docusaurus-theme-translations` + - [#7447](https://github.com/facebook/docusaurus/pull/7447) refactor(theme-classic): migrate to tsc for build ([@Josh-Cena](https://github.com/Josh-Cena)) +- `stylelint-copyright` + - [#7441](https://github.com/facebook/docusaurus/pull/7441) refactor(stylelint-copyright): migrate to TS ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-cssnano-preset` + - [#7440](https://github.com/facebook/docusaurus/pull/7440) refactor(cssnano-preset): migrate to TS ([@Josh-Cena](https://github.com/Josh-Cena)) +- `create-docusaurus`, `docusaurus-logger`, `docusaurus-mdx-loader`, `docusaurus-migrate`, `docusaurus-plugin-client-redirects`, `docusaurus-plugin-content-blog`, `docusaurus-plugin-content-docs`, `docusaurus-plugin-content-pages`, `docusaurus-plugin-debug`, `docusaurus-plugin-google-analytics`, `docusaurus-plugin-google-gtag`, `docusaurus-plugin-ideal-image`, `docusaurus-plugin-pwa`, `docusaurus-plugin-sitemap`, `docusaurus-preset-classic`, `docusaurus-remark-plugin-npm2yarn`, `docusaurus-theme-classic`, `docusaurus-theme-common`, `docusaurus-theme-live-codeblock`, `docusaurus-theme-search-algolia`, `docusaurus-theme-translations`, `docusaurus-utils-common`, `docusaurus-utils-validation`, `docusaurus-utils`, `docusaurus`, `eslint-plugin`, `lqip-loader` + - [#7437](https://github.com/facebook/docusaurus/pull/7437) refactor: use TS project references instead of running tsc multiple times ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-plugin-pwa` + - [#7421](https://github.com/facebook/docusaurus/pull/7421) refactor(pwa): migrate client modules to TS ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus-theme-classic` + - [#7415](https://github.com/facebook/docusaurus/pull/7415) refactor(theme-classic): always collocate stylesheets with components in one folder ([@Josh-Cena](https://github.com/Josh-Cena)) +- `docusaurus` + - [#7405](https://github.com/facebook/docusaurus/pull/7405) refactor(core): properly code-split NotFound page ([@Josh-Cena](https://github.com/Josh-Cena)) + +#### Committers: 23 + +- Akara ([@Messiahhh](https://github.com/Messiahhh)) +- Benjamin Diolez ([@BenDz](https://github.com/BenDz)) +- Charles Korn ([@charleskorn](https://github.com/charleskorn)) +- Designatory ([@Designatory](https://github.com/Designatory)) +- Forresst ([@forresst](https://github.com/forresst)) +- Ggicci ([@ggicci](https://github.com/ggicci)) +- James ([@Zamiell](https://github.com/Zamiell)) +- Jan Peer Stöcklmair ([@JPeer264](https://github.com/JPeer264)) +- Jeremy ([@jrmyw92](https://github.com/jrmyw92)) +- Joshua Chen ([@Josh-Cena](https://github.com/Josh-Cena)) +- Junjie ([@junjieweb](https://github.com/junjieweb)) +- Lane Goolsby ([@lanegoolsby](https://github.com/lanegoolsby)) +- Massoud Maboudi ([@massoudmaboudi](https://github.com/massoudmaboudi)) +- Matthias Koch ([@matkoch](https://github.com/matkoch)) +- Michael Hughes ([@mhughes2k](https://github.com/mhughes2k)) +- Ngô Quốc Đạt ([@datlechin](https://github.com/datlechin)) +- Nitya Narasimhan ([@nitya](https://github.com/nitya)) +- Oluwatobi Sofela ([@oluwatobiss](https://github.com/oluwatobiss)) +- Ori Shalom ([@ori-shalom](https://github.com/ori-shalom)) +- Pranab Das ([@pranabdas](https://github.com/pranabdas)) +- Rui Peres ([@RuiAAPeres](https://github.com/RuiAAPeres)) +- Sébastien Lorber ([@slorber](https://github.com/slorber)) +- 凱恩 Kane ([@Gary50613](https://github.com/Gary50613)) + ## 2.0.0-beta.20 (2022-05-05) #### :bug: Bug Fix diff --git a/admin/new.docusaurus.io/package.json b/admin/new.docusaurus.io/package.json index 07fa3c05d87e..fe86a0cbfacd 100644 --- a/admin/new.docusaurus.io/package.json +++ b/admin/new.docusaurus.io/package.json @@ -1,6 +1,6 @@ { "name": "new.docusaurus.io", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "private": true, "scripts": { "start": "npx --package netlify-cli netlify dev" diff --git a/lerna.json b/lerna.json index 264ec32ae60f..b1fa19591185 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "npmClient": "yarn", "useWorkspaces": true, "changelog": { diff --git a/package.json b/package.json index 533f32b71f48..1d449484aa38 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "devDependencies": { "@crowdin/cli": "^3.7.8", - "@swc/core": "^1.2.189", + "@swc/core": "^1.2.194", "@swc/jest": "^0.2.21", "@testing-library/react-hooks": "^8.0.0", "@types/fs-extra": "^9.0.13", @@ -76,8 +76,8 @@ "@types/react-test-renderer": "^18.0.0", "@types/semver": "^7.3.9", "@types/shelljs": "^0.8.11", - "@typescript-eslint/eslint-plugin": "^5.25.0", - "@typescript-eslint/parser": "^5.25.0", + "@typescript-eslint/eslint-plugin": "^5.26.0", + "@typescript-eslint/parser": "^5.26.0", "cross-env": "^7.0.3", "cspell": "^6.0.0", "eslint": "^8.16.0", @@ -95,21 +95,22 @@ "jest": "^28.1.0", "jest-environment-jsdom": "^28.1.0", "jest-serializer-react-helmet-async": "^1.0.21", - "lerna": "^4.0.0", + "lerna": "^5.0.0", "lerna-changelog": "^2.2.0", - "lint-staged": "^12.4.1", + "lint-staged": "^12.4.2", "npm-run-all": "^4.1.5", "prettier": "^2.6.2", "react": "^17.0.2", "react-dom": "^17.0.2", + "react-helmet-async": "^1.3.0", "react-test-renderer": "^17.0.2", "remark-parse": "^8.0.2", "rimraf": "^3.0.2", - "sharp": "^0.30.4", + "sharp": "^0.30.5", "strip-ansi": "^6.0.1", "stylelint": "^14.8.3", "stylelint-config-prettier": "^9.0.3", "stylelint-config-standard": "^25.0.0", - "typescript": "^4.6.4" + "typescript": "~4.6.4" } } diff --git a/packages/create-docusaurus/bin/index.js b/packages/create-docusaurus/bin/index.js index 35e135ebc65c..be5e14f68965 100755 --- a/packages/create-docusaurus/bin/index.js +++ b/packages/create-docusaurus/bin/index.js @@ -47,12 +47,12 @@ program \`custom\`: enter your custom git clone command. We will prompt you for it.`, ) .description('Initialize website.') - .action((siteName, template, rootDir, options) => { + .action((siteName, template, rootDir, options) => // See https://github.com/facebook/docusaurus/pull/6860 - import('../lib/index.js').then(({default: init}) => { - init(path.resolve(rootDir ?? '.'), siteName, template, options); - }); - }); + import('../lib/index.js').then(({default: init}) => + init(path.resolve(rootDir ?? '.'), siteName, template, options), + ), + ); program.parse(process.argv); diff --git a/packages/create-docusaurus/package.json b/packages/create-docusaurus/package.json index f4ca79dcd026..9984e76be577 100755 --- a/packages/create-docusaurus/package.json +++ b/packages/create-docusaurus/package.json @@ -1,6 +1,6 @@ { "name": "create-docusaurus", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Create Docusaurus apps easily.", "type": "module", "repository": { @@ -22,8 +22,8 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", "commander": "^5.1.0", "fs-extra": "^10.1.0", "lodash": "^4.17.21", diff --git a/packages/create-docusaurus/templates/classic-typescript/package.json b/packages/create-docusaurus/templates/classic-typescript/package.json index 22520824356d..6f7971bf2757 100644 --- a/packages/create-docusaurus/templates/classic-typescript/package.json +++ b/packages/create-docusaurus/templates/classic-typescript/package.json @@ -1,6 +1,6 @@ { "name": "docusaurus-2-classic-typescript-template", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "private": true, "scripts": { "docusaurus": "docusaurus", @@ -15,8 +15,8 @@ "typecheck": "tsc" }, "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/preset-classic": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/preset-classic": "2.0.0-beta.21", "@mdx-js/react": "^1.6.22", "clsx": "^1.1.1", "prism-react-renderer": "^1.3.3", @@ -24,7 +24,7 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", "@tsconfig/docusaurus": "^1.0.5", "typescript": "^4.6.4" }, @@ -39,5 +39,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "engines": { + "node": ">=16.14" } } diff --git a/packages/create-docusaurus/templates/classic/package.json b/packages/create-docusaurus/templates/classic/package.json index c7be6e72caaa..b52e956acf66 100644 --- a/packages/create-docusaurus/templates/classic/package.json +++ b/packages/create-docusaurus/templates/classic/package.json @@ -1,6 +1,6 @@ { "name": "docusaurus-2-classic-template", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "private": true, "scripts": { "docusaurus": "docusaurus", @@ -14,8 +14,8 @@ "write-heading-ids": "docusaurus write-heading-ids" }, "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/preset-classic": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/preset-classic": "2.0.0-beta.21", "@mdx-js/react": "^1.6.22", "clsx": "^1.1.1", "prism-react-renderer": "^1.3.3", @@ -23,7 +23,7 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20" + "@docusaurus/module-type-aliases": "2.0.0-beta.21" }, "browserslist": { "production": [ @@ -36,5 +36,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "engines": { + "node": ">=16.14" } } diff --git a/packages/create-docusaurus/templates/facebook/package.json b/packages/create-docusaurus/templates/facebook/package.json index 63b947a05071..421b880a6c22 100644 --- a/packages/create-docusaurus/templates/facebook/package.json +++ b/packages/create-docusaurus/templates/facebook/package.json @@ -1,6 +1,6 @@ { "name": "docusaurus-2-facebook-template", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "private": true, "scripts": { "docusaurus": "docusaurus", @@ -18,15 +18,15 @@ "format:diff": "prettier --config .prettierrc --list-different \"**/*.{js,jsx,ts,tsx,md,mdx}\"" }, "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/preset-classic": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/preset-classic": "2.0.0-beta.21", "@mdx-js/react": "^1.6.22", "clsx": "^1.1.1", "react": "^17.0.2", "react-dom": "^17.0.2" }, "devDependencies": { - "@babel/eslint-parser": "^7.17.0", + "@babel/eslint-parser": "^7.18.2", "eslint": "^8.16.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.5.0", @@ -36,7 +36,7 @@ "eslint-plugin-react": "^7.30.0", "eslint-plugin-react-hooks": "^4.5.0", "prettier": "^2.6.2", - "stylelint": "^14.8.3" + "stylelint": "^14.8.5" }, "browserslist": { "production": [ @@ -49,5 +49,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "engines": { + "node": ">=16.14" } } diff --git a/packages/docusaurus-cssnano-preset/package.json b/packages/docusaurus-cssnano-preset/package.json index aec575bf1c3b..7e92802bbc20 100644 --- a/packages/docusaurus-cssnano-preset/package.json +++ b/packages/docusaurus-cssnano-preset/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/cssnano-preset", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Advanced cssnano preset for maximum optimization.", "main": "lib/index.js", "license": "MIT", diff --git a/packages/docusaurus-logger/package.json b/packages/docusaurus-logger/package.json index 2c6dcab1b1c8..6175c913da49 100644 --- a/packages/docusaurus-logger/package.json +++ b/packages/docusaurus-logger/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/logger", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "An encapsulated logger for semantically formatting console messages.", "main": "./lib/index.js", "repository": { diff --git a/packages/docusaurus-logger/src/index.ts b/packages/docusaurus-logger/src/index.ts index 768cb8f9a0c2..f430555b0e26 100644 --- a/packages/docusaurus-logger/src/index.ts +++ b/packages/docusaurus-logger/src/index.ts @@ -128,11 +128,11 @@ function newLine(): void { } const logger = { - red: chalk.red, - yellow: chalk.yellow, - green: chalk.green, - bold: chalk.bold, - dim: chalk.dim, + red: (msg: string | number): string => chalk.red(msg), + yellow: (msg: string | number): string => chalk.yellow(msg), + green: (msg: string | number): string => chalk.green(msg), + bold: (msg: string | number): string => chalk.bold(msg), + dim: (msg: string | number): string => chalk.dim(msg), path, url, name, diff --git a/packages/docusaurus-mdx-loader/package.json b/packages/docusaurus-mdx-loader/package.json index 36e190295f02..1efcee5eaf0e 100644 --- a/packages/docusaurus-mdx-loader/package.json +++ b/packages/docusaurus-mdx-loader/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/mdx-loader", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docusaurus Loader for MDX", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,10 +18,10 @@ }, "license": "MIT", "dependencies": { - "@babel/parser": "^7.18.0", - "@babel/traverse": "^7.18.0", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", + "@babel/parser": "^7.18.3", + "@babel/traverse": "^7.18.2", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", "@mdx-js/mdx": "^1.6.22", "escape-html": "^1.0.3", "file-loader": "^6.2.0", @@ -31,12 +31,13 @@ "remark-emoji": "^2.2.0", "stringify-object": "^3.3.0", "tslib": "^2.4.0", + "unified": "^9.2.2", "unist-util-visit": "^2.0.3", "url-loader": "^4.1.1", "webpack": "^5.72.1" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/types": "2.0.0-beta.21", "@types/escape-html": "^1.0.2", "@types/mdast": "^3.0.10", "@types/stringify-object": "^3.3.1", diff --git a/packages/docusaurus-mdx-loader/src/index.ts b/packages/docusaurus-mdx-loader/src/index.ts index 1b7f2be72344..ad7887dcc77c 100644 --- a/packages/docusaurus-mdx-loader/src/index.ts +++ b/packages/docusaurus-mdx-loader/src/index.ts @@ -21,7 +21,7 @@ export type LoadedMDXContent = { /** As provided by the content plugin. */ readonly metadata: Metadata; /** A list of TOC items (headings). */ - readonly toc?: readonly TOCItem[]; + readonly toc: readonly TOCItem[]; /** First h1 title before any content. */ readonly contentTitle: string | undefined; /** diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/no-heading-with-toc-export.md b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/no-heading-with-toc-export.md new file mode 100644 index 000000000000..900b8900c1f9 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/no-heading-with-toc-export.md @@ -0,0 +1,9 @@ +foo + +`bar` + +```js +baz +``` + +export const toc = 1; diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/no-heading.md b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/no-heading.md new file mode 100644 index 000000000000..d02f9a00f460 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__fixtures__/no-heading.md @@ -0,0 +1,7 @@ +foo + +`bar` + +```js +baz +``` diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap index b87c1cd50d75..ba71805a2ab5 100644 --- a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/__snapshots__/index.test.ts.snap @@ -1,5 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`toc remark plugin does not overwrite TOC var if no TOC 1`] = ` +"foo + +\`bar\` + +\`\`\`js +baz +\`\`\` + +export const toc = 1; +" +`; + exports[`toc remark plugin escapes inline code 1`] = ` "export const toc = [ { @@ -119,6 +132,19 @@ Content. " `; +exports[`toc remark plugin outputs empty array for no TOC 1`] = ` +"export const toc = []; + +foo + +\`bar\` + +\`\`\`js +baz +\`\`\` +" +`; + exports[`toc remark plugin works on non text phrasing content 1`] = ` "export const toc = [ { diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts index 43b627c8b1dc..6df3e94e672b 100644 --- a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts @@ -25,6 +25,19 @@ const processFixture = async (name: string) => { }; describe('toc remark plugin', () => { + it('outputs empty array for no TOC', async () => { + const result = await processFixture('no-heading'); + expect(result).toMatchSnapshot(); + }); + + // A very implicit API: we allow users to hand-write the toc variable. It will + // get overwritten in most cases, but until we find a better way, better keep + // supporting this + it('does not overwrite TOC var if no TOC', async () => { + const result = await processFixture('no-heading-with-toc-export'); + expect(result).toMatchSnapshot(); + }); + it('works on non text phrasing content', async () => { const result = await processFixture('non-text-content'); expect(result).toMatchSnapshot(); diff --git a/packages/docusaurus-mdx-loader/tsconfig.json b/packages/docusaurus-mdx-loader/tsconfig.json index 7807612b51a5..3cdfe2a88c91 100644 --- a/packages/docusaurus-mdx-loader/tsconfig.json +++ b/packages/docusaurus-mdx-loader/tsconfig.json @@ -8,7 +8,8 @@ "declarationMap": true, "module": "commonjs", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "types": [] }, "include": ["src"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-migrate/package.json b/packages/docusaurus-migrate/package.json index 2102cac885c8..efd00b2b2f2a 100644 --- a/packages/docusaurus-migrate/package.json +++ b/packages/docusaurus-migrate/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/migrate", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "A CLI tool to migrate from older versions of Docusaurus.", "license": "MIT", "engines": { @@ -22,9 +22,10 @@ "docusaurus-migrate": "bin/index.mjs" }, "dependencies": { - "@babel/preset-env": "^7.18.0", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", + "@babel/core": "^7.18.2", + "@babel/preset-env": "^7.18.2", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", "@mapbox/hast-util-to-jsx": "^2.0.0", "color": "^4.2.3", "commander": "^5.1.0", diff --git a/packages/docusaurus-migrate/src/index.ts b/packages/docusaurus-migrate/src/index.ts index f5bf38134bc0..bab7fd688222 100644 --- a/packages/docusaurus-migrate/src/index.ts +++ b/packages/docusaurus-migrate/src/index.ts @@ -8,7 +8,7 @@ import path from 'path'; import fs from 'fs-extra'; import logger from '@docusaurus/logger'; -import {Globby} from '@docusaurus/utils'; +import {Globby, DOCUSAURUS_VERSION} from '@docusaurus/utils'; import importFresh from 'import-fresh'; import Color from 'color'; @@ -23,9 +23,6 @@ import type { VersionTwoConfig, } from './types'; -const DOCUSAURUS_VERSION = (importFresh('../package.json') as {version: string}) - .version; - async function walk(dir: string): Promise { const results: string[] = []; const list = await fs.readdir(dir); @@ -82,7 +79,8 @@ export async function migrateDocusaurusProject( shouldMigratePages: boolean = false, ): Promise { async function createMigrationContext(): Promise { - const v1Config = importFresh(`${siteDir}/siteConfig`) as VersionOneConfig; + const v1Config = (await import(`${siteDir}/siteConfig`)) + .default as VersionOneConfig; logger.info('Starting migration from v1 to v2...'); const deps = { '@docusaurus/core': DOCUSAURUS_VERSION, @@ -444,9 +442,9 @@ async function migrateBlogFiles(context: MigrationContext) { async function handleVersioning(context: MigrationContext) { const {siteDir, newDir} = context; if (await fs.pathExists(path.join(siteDir, 'versions.json'))) { - const loadedVersions: string[] = await fs.readJSON( + const loadedVersions = (await fs.readJSON( path.join(siteDir, 'versions.json'), - ); + )) as string[]; await fs.copyFile( path.join(siteDir, 'versions.json'), path.join(newDir, 'versions.json'), @@ -488,7 +486,11 @@ async function migrateVersionedDocs( path.join(newDir, 'versioned_docs', `version-${version}`), ); await fs.copy( - path.join(newDir, 'versioned_docs', `version-${versions[index - 1]}`), + path.join( + newDir, + 'versioned_docs', + `version-${versions[index - 1]!}`, + ), path.join(newDir, 'versioned_docs', `version-${version}`), ); await fs.copy( @@ -497,7 +499,11 @@ async function migrateVersionedDocs( ); } catch { await fs.copy( - path.join(newDir, 'versioned_docs', `version-${versions[index - 1]}`), + path.join( + newDir, + 'versioned_docs', + `version-${versions[index - 1]!}`, + ), path.join(newDir, 'versioned_docs', `version-${version}`), ); } @@ -543,7 +549,7 @@ async function migrateVersionedSidebar( `version-${version}-sidebars.json`, ); try { - sidebarEntries = await fs.readJSON(sidebarPath); + sidebarEntries = (await fs.readJSON(sidebarPath)) as SidebarEntries; } catch { sidebars.push({version, entries: sidebars[i - 1]!.entries}); return; diff --git a/packages/docusaurus-module-type-aliases/package.json b/packages/docusaurus-module-type-aliases/package.json index daf13c265c7e..26d08a22247a 100644 --- a/packages/docusaurus-module-type-aliases/package.json +++ b/packages/docusaurus-module-type-aliases/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/module-type-aliases", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docusaurus module type aliases.", "types": "./src/index.d.ts", "publishConfig": { @@ -12,11 +12,14 @@ "directory": "packages/docusaurus-module-type-aliases" }, "dependencies": { - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/react-loadable": "5.5.2", + "@docusaurus/types": "2.0.0-beta.21", + "@types/history": "^4.7.11", "@types/react": "*", "@types/react-router-config": "*", "@types/react-router-dom": "*", - "react-helmet-async": "*" + "react-helmet-async": "*", + "react-loadable": "npm:@docusaurus/react-loadable@5.5.2" }, "peerDependencies": { "react": "*", diff --git a/packages/docusaurus-plugin-client-redirects/package.json b/packages/docusaurus-plugin-client-redirects/package.json index b0a378708339..57f3e138b7cb 100644 --- a/packages/docusaurus-plugin-client-redirects/package.json +++ b/packages/docusaurus-plugin-client-redirects/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-client-redirects", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Client redirects plugin for Docusaurus.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,18 +18,18 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-common": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-common": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "eta": "^1.12.3", "fs-extra": "^10.1.0", "lodash": "^4.17.21", "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index 85ce797f5e6e..f5bfcff31857 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-content-blog", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Blog plugin for Docusaurus.", "main": "lib/index.js", "types": "src/plugin-content-blog.d.ts", @@ -18,12 +18,13 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/mdx-loader": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-common": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/mdx-loader": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-common": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "cheerio": "^1.0.0-rc.11", "feed": "^4.2.2", "fs-extra": "^10.1.0", @@ -36,7 +37,7 @@ "webpack": "^5.72.1" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/types": "2.0.0-beta.21", "escape-string-regexp": "^4.0.0" }, "peerDependencies": { diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index 0a49a06e77ec..bc6a154f51b4 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-content-docs", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docs plugin for Docusaurus.", "main": "lib/index.js", "sideEffects": false, @@ -25,11 +25,14 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/mdx-loader": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/mdx-loader": "2.0.0-beta.21", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", + "@types/react-router-config": "^5.0.6", "combine-promises": "^1.1.0", "fs-extra": "^10.1.0", "import-fresh": "^3.3.0", @@ -41,15 +44,13 @@ "webpack": "^5.72.1" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20", - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/types": "2.0.0-beta.21", "@types/js-yaml": "^4.0.5", "@types/picomatch": "^2.3.0", "commander": "^5.1.0", "escape-string-regexp": "^4.0.0", "picomatch": "^2.3.1", - "shelljs": "^0.8.5", - "utility-types": "^3.10.0" + "shelljs": "^0.8.5" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/customLastUpdate.md b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/customLastUpdate.md new file mode 100644 index 000000000000..b8e37d4f8a9e --- /dev/null +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/customLastUpdate.md @@ -0,0 +1,8 @@ +--- +title: Custom Last Update +last_update: + author: Custom Author + date: 1/1/2000 +--- + +Custom last update \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/lastUpdateAuthorOnly.md b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/lastUpdateAuthorOnly.md new file mode 100644 index 000000000000..4929ed91a9c5 --- /dev/null +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/lastUpdateAuthorOnly.md @@ -0,0 +1,7 @@ +--- +title: Last Update Author Only +last_update: + author: Custom Author +--- + +Only custom author, so it will still use the date from Git \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/lastUpdateDateOnly.md b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/lastUpdateDateOnly.md new file mode 100644 index 000000000000..f9bfeb9759d9 --- /dev/null +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/docs/lastUpdateDateOnly.md @@ -0,0 +1,7 @@ +--- +title: Last Update Date Only +last_update: + date: 1/1/2000 +--- + +Only custom date, so it will still use the author from Git \ No newline at end of file diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap index f05c66e2aa21..69401a06a04c 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap @@ -3,13 +3,24 @@ exports[`simple site custom pagination 1`] = ` { "pagination": [ + { + "id": "customLastUpdate", + "next": { + "permalink": "/docs/doc with space", + "title": "Hoo hoo, if this path tricks you...", + }, + "prev": undefined, + }, { "id": "doc with space", "next": { "permalink": "/docs/doc-draft", "title": "doc-draft", }, - "prev": undefined, + "prev": { + "permalink": "/docs/customLastUpdate", + "title": "Custom Last Update", + }, }, { "id": "doc-draft", @@ -63,14 +74,36 @@ exports[`simple site custom pagination 1`] = ` { "id": "ipsum", "next": { - "permalink": "/docs/lorem", - "title": "lorem", + "permalink": "/docs/lastUpdateAuthorOnly", + "title": "Last Update Author Only", }, "prev": { "permalink": "/docs/", "title": "Hello sidebar_label", }, }, + { + "id": "lastUpdateAuthorOnly", + "next": { + "permalink": "/docs/lastUpdateDateOnly", + "title": "Last Update Date Only", + }, + "prev": { + "permalink": "/docs/ipsum", + "title": "ipsum", + }, + }, + { + "id": "lastUpdateDateOnly", + "next": { + "permalink": "/docs/lorem", + "title": "lorem", + }, + "prev": { + "permalink": "/docs/lastUpdateAuthorOnly", + "title": "Last Update Author Only", + }, + }, { "id": "lorem", "next": { @@ -78,8 +111,8 @@ exports[`simple site custom pagination 1`] = ` "title": "rootAbsoluteSlug", }, "prev": { - "permalink": "/docs/ipsum", - "title": "ipsum", + "permalink": "/docs/lastUpdateDateOnly", + "title": "Last Update Date Only", }, }, { @@ -170,6 +203,10 @@ exports[`simple site custom pagination 1`] = ` ], "sidebars": { "defaultSidebar": [ + { + "id": "customLastUpdate", + "type": "doc", + }, { "id": "doc with space", "type": "doc", @@ -208,6 +245,14 @@ exports[`simple site custom pagination 1`] = ` "id": "ipsum", "type": "doc", }, + { + "id": "lastUpdateAuthorOnly", + "type": "doc", + }, + { + "id": "lastUpdateDateOnly", + "type": "doc", + }, { "id": "lorem", "type": "doc", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap index c8b0408c5ee1..c428a6c55e86 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/index.test.ts.snap @@ -22,6 +22,7 @@ These sidebar document ids do not exist: - nonExistent Available document ids are: +- customLastUpdate - doc with space - doc-draft - foo/bar @@ -29,6 +30,8 @@ Available document ids are: - headingAsTitle - hello - ipsum +- lastUpdateAuthorOnly +- lastUpdateDateOnly - lorem - rootAbsoluteSlug - rootRelativeSlug @@ -267,6 +270,11 @@ exports[`simple website content 5`] = ` "versions": [ { "docs": [ + { + "id": "customLastUpdate", + "path": "/docs/customLastUpdate", + "sidebar": undefined, + }, { "id": "doc with space", "path": "/docs/doc with space", @@ -302,6 +310,16 @@ exports[`simple website content 5`] = ` "path": "/docs/ipsum", "sidebar": undefined, }, + { + "id": "lastUpdateAuthorOnly", + "path": "/docs/lastUpdateAuthorOnly", + "sidebar": undefined, + }, + { + "id": "lastUpdateDateOnly", + "path": "/docs/lastUpdateDateOnly", + "sidebar": undefined, + }, { "id": "lorem", "path": "/docs/lorem", @@ -390,6 +408,26 @@ exports[`simple website content: data 1`] = ` "permalink": "/docs/rootAbsoluteSlug" } } +}", + "site-docs-custom-last-update-md-b8d.json": "{ + "unversionedId": "customLastUpdate", + "id": "customLastUpdate", + "title": "Custom Last Update", + "description": "Custom last update", + "source": "@site/docs/customLastUpdate.md", + "sourceDirName": ".", + "slug": "/customLastUpdate", + "permalink": "/docs/customLastUpdate", + "draft": false, + "tags": [], + "version": "current", + "frontMatter": { + "title": "Custom Last Update", + "last_update": { + "author": "Custom Author", + "date": "1/1/2000" + } + } }", "site-docs-doc-draft-md-584.json": "{ "unversionedId": "doc-draft", @@ -563,6 +601,44 @@ exports[`simple website content: data 1`] = ` "frontMatter": { "custom_edit_url": null } +}", + "site-docs-last-update-author-only-md-352.json": "{ + "unversionedId": "lastUpdateAuthorOnly", + "id": "lastUpdateAuthorOnly", + "title": "Last Update Author Only", + "description": "Only custom author, so it will still use the date from Git", + "source": "@site/docs/lastUpdateAuthorOnly.md", + "sourceDirName": ".", + "slug": "/lastUpdateAuthorOnly", + "permalink": "/docs/lastUpdateAuthorOnly", + "draft": false, + "tags": [], + "version": "current", + "frontMatter": { + "title": "Last Update Author Only", + "last_update": { + "author": "Custom Author" + } + } +}", + "site-docs-last-update-date-only-md-987.json": "{ + "unversionedId": "lastUpdateDateOnly", + "id": "lastUpdateDateOnly", + "title": "Last Update Date Only", + "description": "Only custom date, so it will still use the author from Git", + "source": "@site/docs/lastUpdateDateOnly.md", + "sourceDirName": ".", + "slug": "/lastUpdateDateOnly", + "permalink": "/docs/lastUpdateDateOnly", + "draft": false, + "tags": [], + "version": "current", + "frontMatter": { + "title": "Last Update Date Only", + "last_update": { + "date": "1/1/2000" + } + } }", "site-docs-lorem-md-b27.json": "{ "unversionedId": "lorem", @@ -924,6 +1000,11 @@ exports[`simple website content: data 1`] = ` ] }, "docs": { + "customLastUpdate": { + "id": "customLastUpdate", + "title": "Custom Last Update", + "description": "Custom last update" + }, "doc with space": { "id": "doc with space", "title": "Hoo hoo, if this path tricks you...", @@ -963,6 +1044,16 @@ exports[`simple website content: data 1`] = ` "title": "ipsum", "description": "Lorem ipsum." }, + "lastUpdateAuthorOnly": { + "id": "lastUpdateAuthorOnly", + "title": "Last Update Author Only", + "description": "Only custom author, so it will still use the date from Git" + }, + "lastUpdateDateOnly": { + "id": "lastUpdateDateOnly", + "title": "Last Update Date Only", + "description": "Only custom date, so it will still use the author from Git" + }, "lorem": { "id": "lorem", "title": "lorem", @@ -1026,6 +1117,11 @@ exports[`simple website content: global data 1`] = ` "versions": [ { "docs": [ + { + "id": "customLastUpdate", + "path": "/docs/customLastUpdate", + "sidebar": undefined, + }, { "id": "doc with space", "path": "/docs/doc with space", @@ -1061,6 +1157,16 @@ exports[`simple website content: global data 1`] = ` "path": "/docs/ipsum", "sidebar": undefined, }, + { + "id": "lastUpdateAuthorOnly", + "path": "/docs/lastUpdateAuthorOnly", + "sidebar": undefined, + }, + { + "id": "lastUpdateDateOnly", + "path": "/docs/lastUpdateDateOnly", + "sidebar": undefined, + }, { "id": "lorem", "path": "/docs/lorem", @@ -1202,6 +1308,14 @@ exports[`simple website content: route config 1`] = ` "path": "/docs/category/slugs", "sidebar": "docs", }, + { + "component": "@theme/DocItem", + "exact": true, + "modules": { + "content": "@site/docs/customLastUpdate.md", + }, + "path": "/docs/customLastUpdate", + }, { "component": "@theme/DocItem", "exact": true, @@ -1262,6 +1376,22 @@ exports[`simple website content: route config 1`] = ` }, "path": "/docs/ipsum", }, + { + "component": "@theme/DocItem", + "exact": true, + "modules": { + "content": "@site/docs/lastUpdateAuthorOnly.md", + }, + "path": "/docs/lastUpdateAuthorOnly", + }, + { + "component": "@theme/DocItem", + "exact": true, + "modules": { + "content": "@site/docs/lastUpdateDateOnly.md", + }, + "path": "/docs/lastUpdateDateOnly", + }, { "component": "@theme/DocItem", "exact": true, diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts index 9a338c5bf9d2..88b74733f7ce 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -57,7 +57,6 @@ ${markdown} return { source, content, - lastUpdate: {}, contentPath: 'docs', filePath: source, }; @@ -79,7 +78,7 @@ function createTestUtils({ env = 'production', }: TestUtilsArg) { async function readDoc(docFileSource: string) { - return readDocFile(versionMetadata, docFileSource, options); + return readDocFile(versionMetadata, docFileSource); } async function processDocFile(docFileArg: DocFile | string) { const docFile: DocFile = @@ -119,7 +118,7 @@ function createTestUtils({ async function testSlug(docFileSource: string, expectedPermalink: string) { const docFile = await readDoc(docFileSource); - const metadata = processDocMetadata({ + const metadata = await processDocMetadata({ docFile, versionMetadata, context, @@ -137,14 +136,16 @@ function createTestUtils({ }[]; sidebars: Sidebars; }> { - const rawDocs = docFiles.map((docFile) => - processDocMetadata({ - docFile, - versionMetadata, - context, - options, - env: 'production', - }), + const rawDocs = await Promise.all( + docFiles.map(async (docFile) => + processDocMetadata({ + docFile, + versionMetadata, + context, + options, + env: 'production', + }), + ), ); const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, { sidebarItemsGenerator: ({defaultSidebarItemsGenerator, ...args}) => @@ -230,6 +231,9 @@ describe('simple site', () => { 'headingAsTitle.md', 'doc with space.md', 'doc-draft.md', + 'customLastUpdate.md', + 'lastUpdateAuthorOnly.md', + 'lastUpdateDateOnly.md', 'foo/bar.md', 'foo/baz.md', 'slugs/absoluteSlug.md', @@ -481,6 +485,164 @@ describe('simple site', () => { }); }); + it('docs with last_update front matter', async () => { + const {siteDir, context, options, currentVersion, createTestUtilsPartial} = + await loadSite({ + options: { + showLastUpdateAuthor: true, + showLastUpdateTime: true, + }, + }); + + const testUtilsLocal = createTestUtilsPartial({ + siteDir, + context, + options, + versionMetadata: currentVersion, + }); + + await testUtilsLocal.testMeta('customLastUpdate.md', { + version: 'current', + id: 'customLastUpdate', + unversionedId: 'customLastUpdate', + sourceDirName: '.', + permalink: '/docs/customLastUpdate', + slug: '/customLastUpdate', + title: 'Custom Last Update', + description: 'Custom last update', + frontMatter: { + last_update: { + author: 'Custom Author', + date: '1/1/2000', + }, + title: 'Custom Last Update', + }, + lastUpdatedAt: new Date('1/1/2000').getTime() / 1000, + formattedLastUpdatedAt: '1/1/2000', + lastUpdatedBy: 'Custom Author', + sidebarPosition: undefined, + tags: [], + }); + }); + + it('docs with only last_update author front matter', async () => { + const {siteDir, context, options, currentVersion, createTestUtilsPartial} = + await loadSite({ + options: { + showLastUpdateAuthor: true, + showLastUpdateTime: true, + }, + }); + + const testUtilsLocal = createTestUtilsPartial({ + siteDir, + context, + options, + versionMetadata: currentVersion, + }); + + await testUtilsLocal.testMeta('lastUpdateAuthorOnly.md', { + version: 'current', + id: 'lastUpdateAuthorOnly', + unversionedId: 'lastUpdateAuthorOnly', + sourceDirName: '.', + permalink: '/docs/lastUpdateAuthorOnly', + slug: '/lastUpdateAuthorOnly', + title: 'Last Update Author Only', + description: 'Only custom author, so it will still use the date from Git', + frontMatter: { + last_update: { + author: 'Custom Author', + }, + title: 'Last Update Author Only', + }, + lastUpdatedAt: 1539502055, + formattedLastUpdatedAt: '10/14/2018', + lastUpdatedBy: 'Custom Author', + sidebarPosition: undefined, + tags: [], + }); + }); + + it('docs with only last_update date front matter', async () => { + const {siteDir, context, options, currentVersion, createTestUtilsPartial} = + await loadSite({ + options: { + showLastUpdateAuthor: true, + showLastUpdateTime: true, + }, + }); + + const testUtilsLocal = createTestUtilsPartial({ + siteDir, + context, + options, + versionMetadata: currentVersion, + }); + + await testUtilsLocal.testMeta('lastUpdateDateOnly.md', { + version: 'current', + id: 'lastUpdateDateOnly', + unversionedId: 'lastUpdateDateOnly', + sourceDirName: '.', + permalink: '/docs/lastUpdateDateOnly', + slug: '/lastUpdateDateOnly', + title: 'Last Update Date Only', + description: 'Only custom date, so it will still use the author from Git', + frontMatter: { + last_update: { + date: '1/1/2000', + }, + title: 'Last Update Date Only', + }, + lastUpdatedAt: new Date('1/1/2000').getTime() / 1000, + formattedLastUpdatedAt: '1/1/2000', + lastUpdatedBy: 'Author', + sidebarPosition: undefined, + tags: [], + }); + }); + + it('docs with last_update front matter disabled', async () => { + const {siteDir, context, options, currentVersion, createTestUtilsPartial} = + await loadSite({ + options: { + showLastUpdateAuthor: false, + showLastUpdateTime: false, + }, + }); + + const testUtilsLocal = createTestUtilsPartial({ + siteDir, + context, + options, + versionMetadata: currentVersion, + }); + + await testUtilsLocal.testMeta('customLastUpdate.md', { + version: 'current', + id: 'customLastUpdate', + unversionedId: 'customLastUpdate', + sourceDirName: '.', + permalink: '/docs/customLastUpdate', + slug: '/customLastUpdate', + title: 'Custom Last Update', + description: 'Custom last update', + frontMatter: { + last_update: { + author: 'Custom Author', + date: '1/1/2000', + }, + title: 'Custom Last Update', + }, + lastUpdatedAt: undefined, + formattedLastUpdatedAt: undefined, + lastUpdatedBy: undefined, + sidebarPosition: undefined, + tags: [], + }); + }); + it('docs with slugs', async () => { const {defaultTestUtils} = await loadSite(); diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts index 81eedbf13b9a..55da1682c725 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts @@ -396,3 +396,52 @@ describe('validateDocFrontMatter draft', () => { ], }); }); + +describe('validateDocFrontMatter last_update', () => { + testField({ + prefix: 'last_update', + validFrontMatters: [ + {last_update: undefined}, + {last_update: {author: 'test author', date: undefined}}, + {last_update: {author: undefined, date: '1/1/2000'}}, + {last_update: {author: undefined, date: new Date('1/1/2000')}}, + {last_update: {author: 'test author', date: '1/1/2000'}}, + {last_update: {author: 'test author', date: '1995-12-17T03:24:00'}}, + {last_update: {author: undefined, date: 'December 17, 1995 03:24:00'}}, + ], + invalidFrontMatters: [ + [ + {last_update: null}, + 'does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).', + ], + [ + {last_update: {}}, + 'does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).', + ], + [ + {last_update: ''}, + 'does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).', + ], + [ + {last_update: {invalid: 'key'}}, + 'does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).', + ], + [ + {last_update: {author: 'test author', date: 'I am not a date :('}}, + 'must be a valid date', + ], + [ + {last_update: {author: 'test author', date: '2011-10-45'}}, + 'must be a valid date', + ], + [ + {last_update: {author: 'test author', date: '2011-0-10'}}, + 'must be a valid date', + ], + [ + {last_update: {author: 'test author', date: ''}}, + 'must be a valid date', + ], + ], + }); +}); diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 2ea127f99fbb..580d90101740 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -37,6 +37,7 @@ import type { VersionMetadata, DocFrontMatter, LoadedVersion, + FileChange, } from '@docusaurus/plugin-content-docs'; import type {LoadContext} from '@docusaurus/types'; import type {SidebarsUtils} from './sidebars/utils'; @@ -50,9 +51,21 @@ type LastUpdateOptions = Pick< async function readLastUpdateData( filePath: string, options: LastUpdateOptions, + lastUpdateFrontMatter: FileChange | undefined, ): Promise { const {showLastUpdateAuthor, showLastUpdateTime} = options; if (showLastUpdateAuthor || showLastUpdateTime) { + const frontMatterTimestamp = lastUpdateFrontMatter?.date + ? new Date(lastUpdateFrontMatter.date).getTime() / 1000 + : undefined; + + if (lastUpdateFrontMatter?.author && lastUpdateFrontMatter.date) { + return { + lastUpdatedAt: frontMatterTimestamp, + lastUpdatedBy: lastUpdateFrontMatter.author, + }; + } + // Use fake data in dev for faster development. const fileLastUpdateData = process.env.NODE_ENV === 'production' @@ -61,14 +74,16 @@ async function readLastUpdateData( author: 'Author', timestamp: 1539502055, }; - - if (fileLastUpdateData) { - const {author, timestamp} = fileLastUpdateData; - return { - lastUpdatedAt: showLastUpdateTime ? timestamp : undefined, - lastUpdatedBy: showLastUpdateAuthor ? author : undefined, - }; - } + const {author, timestamp} = fileLastUpdateData ?? {}; + + return { + lastUpdatedBy: showLastUpdateAuthor + ? lastUpdateFrontMatter?.author ?? author + : undefined, + lastUpdatedAt: showLastUpdateTime + ? frontMatterTimestamp ?? timestamp + : undefined, + }; } return {}; @@ -80,7 +95,6 @@ export async function readDocFile( 'contentPath' | 'contentPathLocalized' >, source: string, - options: LastUpdateOptions, ): Promise { const contentPath = await getFolderContainingFile( getContentPathList(versionMetadata), @@ -89,11 +103,8 @@ export async function readDocFile( const filePath = path.join(contentPath, source); - const [content, lastUpdate] = await Promise.all([ - fs.readFile(filePath, 'utf-8'), - readLastUpdateData(filePath, options), - ]); - return {source, content, lastUpdate, contentPath, filePath}; + const content = await fs.readFile(filePath, 'utf-8'); + return {source, content, contentPath, filePath}; } export async function readVersionDocs( @@ -108,7 +119,7 @@ export async function readVersionDocs( ignore: options.exclude, }); return Promise.all( - sources.map((source) => readDocFile(versionMetadata, source, options)), + sources.map((source) => readDocFile(versionMetadata, source)), ); } @@ -125,7 +136,7 @@ function isDraftForEnvironment({ return (env === 'production' && frontMatter.draft) ?? false; } -function doProcessDocMetadata({ +async function doProcessDocMetadata({ docFile, versionMetadata, context, @@ -137,8 +148,8 @@ function doProcessDocMetadata({ context: LoadContext; options: MetadataOptions; env: DocEnv; -}): DocMetadataBase { - const {source, content, lastUpdate, contentPath, filePath} = docFile; +}): Promise { + const {source, content, contentPath, filePath} = docFile; const {siteDir, i18n} = context; const { @@ -155,8 +166,15 @@ function doProcessDocMetadata({ // (01-MyFolder/01-MyDoc.md => MyFolder/MyDoc) // but allow to disable this behavior with front matter parse_number_prefixes: parseNumberPrefixes = true, + last_update: lastUpdateFrontMatter, } = frontMatter; + const lastUpdate = await readLastUpdateData( + filePath, + options, + lastUpdateFrontMatter, + ); + // E.g. api/plugins/myDoc -> myDoc; myDoc -> myDoc const sourceFileNameWithoutExtension = path.basename( source, @@ -287,7 +305,7 @@ export function processDocMetadata(args: { context: LoadContext; options: MetadataOptions; env: DocEnv; -}): DocMetadataBase { +}): Promise { try { return doProcessDocMetadata(args); } catch (err) { diff --git a/packages/docusaurus-plugin-content-docs/src/frontMatter.ts b/packages/docusaurus-plugin-content-docs/src/frontMatter.ts index de944a6b1716..9d210a831b25 100644 --- a/packages/docusaurus-plugin-content-docs/src/frontMatter.ts +++ b/packages/docusaurus-plugin-content-docs/src/frontMatter.ts @@ -14,6 +14,9 @@ import { } from '@docusaurus/utils-validation'; import type {DocFrontMatter} from '@docusaurus/plugin-content-docs'; +const FrontMatterLastUpdateErrorMessage = + '{{#label}} does not look like a valid front matter FileChange object. Please use a FileChange object (with an author and/or date).'; + // NOTE: we don't add any default value on purpose here // We don't want default values to magically appear in doc metadata and props // While the user did not provide those values explicitly @@ -42,6 +45,15 @@ const DocFrontMatterSchema = Joi.object({ pagination_prev: Joi.string().allow(null), draft: Joi.boolean(), ...FrontMatterTOCHeadingLevels, + last_update: Joi.object({ + author: Joi.string(), + date: Joi.date().raw(), + }) + .or('author', 'date') + .messages({ + 'object.missing': FrontMatterLastUpdateErrorMessage, + 'object.base': FrontMatterLastUpdateErrorMessage, + }), }).unknown(); export function validateDocFrontMatter(frontMatter: { diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index afbb809fb718..a8557542430f 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -100,9 +100,9 @@ export default async function pluginContentDocs( .command(command) .arguments('') .description(commandDescription) - .action((version: unknown) => { - cliDocsVersionCommand(version, options, context); - }); + .action((version: unknown) => + cliDocsVersionCommand(version, options, context), + ); }, getTranslationFiles({content}) { diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index 1d7be06b74dc..835c87204375 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -23,6 +23,14 @@ declare module '@docusaurus/plugin-content-docs' { image?: string; }; + export type FileChange = { + author?: string; + /** Date can be any + * [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse). + */ + date?: Date | string; + }; + /** * Custom callback for parsing number prefixes from file/folder names. */ @@ -371,6 +379,8 @@ declare module '@docusaurus/plugin-content-docs' { pagination_prev?: string | null; /** Should this doc be excluded from production builds? */ draft?: boolean; + /** Allows overriding the last updated author and/or date. */ + last_update?: FileChange; }; export type LastUpdateData = { diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index cb4506b20d1a..4c4568517fbb 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -8,7 +8,6 @@ import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils'; import type { VersionMetadata, - LastUpdateData, LoadedVersion, CategoryGeneratedIndexMetadata, } from '@docusaurus/plugin-content-docs'; @@ -19,7 +18,6 @@ export type DocFile = { filePath: string; // /!\ may be localized source: string; content: string; - lastUpdate: LastUpdateData; }; export type SourceToPermalink = { diff --git a/packages/docusaurus-plugin-content-pages/package.json b/packages/docusaurus-plugin-content-pages/package.json index 4ec059c3cfef..c9167e386d3a 100644 --- a/packages/docusaurus-plugin-content-pages/package.json +++ b/packages/docusaurus-plugin-content-pages/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-content-pages", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Pages plugin for Docusaurus.", "main": "lib/index.js", "types": "src/plugin-content-pages.d.ts", @@ -18,17 +18,18 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/mdx-loader": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/mdx-loader": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "fs-extra": "^10.1.0", "remark-admonitions": "^1.2.1", "tslib": "^2.4.0", "webpack": "^5.72.1" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-debug/package.json b/packages/docusaurus-plugin-debug/package.json index 98f9c72f08cf..d9e1cb136ad8 100644 --- a/packages/docusaurus-plugin-debug/package.json +++ b/packages/docusaurus-plugin-debug/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-debug", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Debug plugin for Docusaurus.", "main": "lib/index.js", "types": "src/plugin-debug.d.ts", @@ -20,14 +20,15 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", "fs-extra": "^10.1.0", "react-json-view": "^1.21.3", "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-google-analytics/package.json b/packages/docusaurus-plugin-google-analytics/package.json index d97f66f979a6..e4247fa62587 100644 --- a/packages/docusaurus-plugin-google-analytics/package.json +++ b/packages/docusaurus-plugin-google-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-google-analytics", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Global analytics (analytics.js) plugin for Docusaurus.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,12 +18,13 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-google-gtag/package.json b/packages/docusaurus-plugin-google-gtag/package.json index 146b913d71da..f00b672e394c 100644 --- a/packages/docusaurus-plugin-google-gtag/package.json +++ b/packages/docusaurus-plugin-google-gtag/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-google-gtag", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Global Site Tag (gtag.js) plugin for Docusaurus.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,12 +18,13 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-google-gtag/src/gtag.ts b/packages/docusaurus-plugin-google-gtag/src/gtag.ts index dab90146d1fc..2122511126a8 100644 --- a/packages/docusaurus-plugin-google-gtag/src/gtag.ts +++ b/packages/docusaurus-plugin-google-gtag/src/gtag.ts @@ -15,16 +15,23 @@ const {trackingID} = globalData['docusaurus-plugin-google-gtag']! const clientModule: ClientModule = { onRouteDidUpdate({location, previousLocation}) { if (previousLocation && location.pathname !== previousLocation.pathname) { - // Always refer to the variable on window in case it gets overridden - // elsewhere. - window.gtag('config', trackingID, { - page_path: location.pathname, - page_title: document.title, - }); - window.gtag('event', 'page_view', { - page_title: document.title, - page_location: window.location.href, - page_path: location.pathname, + // Normally, the document title is updated in the next tick due to how + // `react-helmet-async` updates it. We want to send the current document's + // title to gtag instead of the old one's, so we use `setTimeout` to defer + // execution to the next tick. + // See: https://github.com/facebook/docusaurus/issues/7420 + setTimeout(() => { + // Always refer to the variable on window in case it gets overridden + // elsewhere. + window.gtag('config', trackingID, { + page_path: location.pathname, + page_title: document.title, + }); + window.gtag('event', 'page_view', { + page_title: document.title, + page_location: window.location.href, + page_path: location.pathname, + }); }); } }, diff --git a/packages/docusaurus-plugin-ideal-image/package.json b/packages/docusaurus-plugin-ideal-image/package.json index 582127cb4bc9..cf79146b19ee 100644 --- a/packages/docusaurus-plugin-ideal-image/package.json +++ b/packages/docusaurus-plugin-ideal-image/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-ideal-image", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder).", "main": "lib/index.js", "types": "src/plugin-ideal-image.d.ts", @@ -20,20 +20,21 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/lqip-loader": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/lqip-loader": "2.0.0-beta.21", "@docusaurus/responsive-loader": "^1.7.0", - "@docusaurus/theme-translations": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/theme-translations": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "@endiliey/react-ideal-image": "^0.0.11", "react-waypoint": "^10.1.0", - "sharp": "^0.30.4", + "sharp": "^0.30.5", "tslib": "^2.4.0", "webpack": "^5.72.1" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20", - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", "fs-extra": "^10.1.0" }, "peerDependencies": { diff --git a/packages/docusaurus-plugin-pwa/package.json b/packages/docusaurus-plugin-pwa/package.json index 429ae3f1b186..9048db7d4d0a 100644 --- a/packages/docusaurus-plugin-pwa/package.json +++ b/packages/docusaurus-plugin-pwa/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-pwa", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docusaurus Plugin to add PWA support.", "main": "lib/index.js", "types": "src/plugin-pwa.d.ts", @@ -20,16 +20,17 @@ }, "license": "MIT", "dependencies": { - "@babel/core": "^7.18.0", - "@babel/preset-env": "^7.18.0", - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/theme-common": "2.0.0-beta.20", - "@docusaurus/theme-translations": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@babel/core": "^7.18.2", + "@babel/preset-env": "^7.18.2", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/theme-common": "2.0.0-beta.21", + "@docusaurus/theme-translations": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "babel-loader": "^8.2.5", "clsx": "^1.1.1", - "core-js": "^3.22.5", + "core-js": "^3.22.7", "terser-webpack-plugin": "^5.3.1", "tslib": "^2.4.0", "webpack": "^5.72.1", @@ -39,7 +40,7 @@ "workbox-window": "^6.5.3" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", "fs-extra": "^10.1.0" }, "peerDependencies": { diff --git a/packages/docusaurus-plugin-pwa/src/index.ts b/packages/docusaurus-plugin-pwa/src/index.ts index 448e7d2f9917..895dc56f4013 100644 --- a/packages/docusaurus-plugin-pwa/src/index.ts +++ b/packages/docusaurus-plugin-pwa/src/index.ts @@ -52,7 +52,6 @@ export default function pluginPWA( debug, offlineModeActivationStrategies, injectManifestConfig, - reloadPopup, pwaHead, swCustom, swRegister, @@ -94,7 +93,6 @@ export default function pluginPWA( ), PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES: offlineModeActivationStrategies, - PWA_RELOAD_POPUP: reloadPopup, }), ], }; diff --git a/packages/docusaurus-plugin-pwa/src/options.ts b/packages/docusaurus-plugin-pwa/src/options.ts index 8517028f9f20..0332a26707a6 100644 --- a/packages/docusaurus-plugin-pwa/src/options.ts +++ b/packages/docusaurus-plugin-pwa/src/options.ts @@ -20,7 +20,6 @@ const DEFAULT_OPTIONS = { pwaHead: [], swCustom: undefined, swRegister: './registerSw.js', - reloadPopup: '@theme/PwaReloadPopup', }; const optionsSchema = Joi.object({ @@ -49,9 +48,11 @@ const optionsSchema = Joi.object({ swRegister: Joi.alternatives() .try(Joi.string(), Joi.bool().valid(false)) .default(DEFAULT_OPTIONS.swRegister), - reloadPopup: Joi.alternatives() - .try(Joi.string(), Joi.bool().valid(false)) - .default(DEFAULT_OPTIONS.reloadPopup), + // @ts-expect-error: forbidden + reloadPopup: Joi.any().forbidden().messages({ + 'any.unknown': + 'The reloadPopup option is removed in favor of swizzling. See https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-pwa#customizing-reload-popup for how to customize the reload popup using swizzling.', + }), }); export function validateOptions({ diff --git a/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts b/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts index 9633e9e4e43a..85d6aa088441 100644 --- a/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts +++ b/packages/docusaurus-plugin-pwa/src/plugin-pwa.d.ts @@ -46,16 +46,6 @@ declare module '@docusaurus/plugin-pwa' { * @see https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.injectManifest */ injectManifestConfig: InjectManifestOptions; - /** - * Module path to reload popup component. This popup is rendered when a new - * service worker is waiting to be installed, and we suggest a reload to - * the user. - * - * Passing `false` will disable the popup, but this is not recommended: - * users won't have a way to get up-to-date content. - * @see {@link @theme/PwaReloadPopup} - */ - reloadPopup: string | false; /** * Array of objects containing `tagName` and key-value pairs for attributes * to inject into the `` tag. Technically you can inject any head tag diff --git a/packages/docusaurus-plugin-pwa/src/registerSw.ts b/packages/docusaurus-plugin-pwa/src/registerSw.ts index d48e7b29b2f7..7ccb4a56a233 100644 --- a/packages/docusaurus-plugin-pwa/src/registerSw.ts +++ b/packages/docusaurus-plugin-pwa/src/registerSw.ts @@ -10,7 +10,6 @@ import {createStorageSlot} from '@docusaurus/theme-common'; // First: read the env variables (provided by Webpack) /* eslint-disable prefer-destructuring */ const PWA_SERVICE_WORKER_URL = process.env.PWA_SERVICE_WORKER_URL!; -const PWA_RELOAD_POPUP = process.env.PWA_RELOAD_POPUP; const PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES = process.env .PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES as unknown as (keyof typeof OfflineModeActivationStrategiesImplementations)[]; const PWA_DEBUG = process.env.PWA_DEBUG; @@ -170,7 +169,7 @@ async function registerSW() { // Immediately load new service worker when files aren't cached if (!offlineMode) { sendSkipWaiting(); - } else if (PWA_RELOAD_POPUP) { + } else { const renderReloadPopup = (await import('./renderReloadPopup')).default; await renderReloadPopup({ onReload() { diff --git a/packages/docusaurus-plugin-pwa/src/renderReloadPopup.tsx b/packages/docusaurus-plugin-pwa/src/renderReloadPopup.tsx index d4cac3601736..2958a7dee833 100644 --- a/packages/docusaurus-plugin-pwa/src/renderReloadPopup.tsx +++ b/packages/docusaurus-plugin-pwa/src/renderReloadPopup.tsx @@ -7,6 +7,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import type {Props} from '@theme/PwaReloadPopup'; const POPUP_CONTAINER_ID = 'pwa-popup-container'; @@ -19,10 +20,8 @@ const createContainer = () => { return container; }; -export default async function renderReloadPopup(props: { - onReload: () => void; -}): Promise { - const container = getContainer() || createContainer(); - const {default: ReloadPopup} = await import(process.env.PWA_RELOAD_POPUP!); +export default async function renderReloadPopup(props: Props): Promise { + const container = getContainer() ?? createContainer(); + const ReloadPopup = (await import('@theme/PwaReloadPopup')).default; ReactDOM.render(, container); } diff --git a/packages/docusaurus-plugin-sitemap/package.json b/packages/docusaurus-plugin-sitemap/package.json index f6fd11b8921b..2b9a9430eeae 100644 --- a/packages/docusaurus-plugin-sitemap/package.json +++ b/packages/docusaurus-plugin-sitemap/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/plugin-sitemap", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Simple sitemap generation plugin for Docusaurus.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,17 +18,18 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-common": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-common": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "fs-extra": "^10.1.0", "sitemap": "^7.1.1", "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-plugin-sitemap/src/__tests__/createSitemap.test.ts b/packages/docusaurus-plugin-sitemap/src/__tests__/createSitemap.test.ts index bc34ee51d87f..b033a0cc7243 100644 --- a/packages/docusaurus-plugin-sitemap/src/__tests__/createSitemap.test.ts +++ b/packages/docusaurus-plugin-sitemap/src/__tests__/createSitemap.test.ts @@ -23,6 +23,7 @@ describe('createSitemap', () => { changefreq: EnumChangefreq.DAILY, priority: 0.7, ignorePatterns: [], + filename: 'sitemap.xml', }, ); expect(sitemap).toContain( @@ -49,6 +50,7 @@ describe('createSitemap', () => { changefreq: EnumChangefreq.DAILY, priority: 0.7, ignorePatterns: [], + filename: 'sitemap.xml', }, ); expect(sitemap).not.toContain('404'); @@ -70,6 +72,7 @@ describe('createSitemap', () => { // Deep ignore '/tags/**', ], + filename: 'sitemap.xml', }, ); expect(sitemap).not.toContain('/search/'); @@ -89,6 +92,7 @@ describe('createSitemap', () => { changefreq: EnumChangefreq.DAILY, priority: 0.7, ignorePatterns: [], + filename: 'sitemap.xml', }, ); @@ -110,6 +114,7 @@ describe('createSitemap', () => { changefreq: EnumChangefreq.DAILY, priority: 0.7, ignorePatterns: [], + filename: 'sitemap.xml', }, ); @@ -131,6 +136,7 @@ describe('createSitemap', () => { changefreq: EnumChangefreq.DAILY, priority: 0.7, ignorePatterns: [], + filename: 'sitemap.xml', }, ); diff --git a/packages/docusaurus-plugin-sitemap/src/index.ts b/packages/docusaurus-plugin-sitemap/src/index.ts index 9d9f75a442c5..3044f1feff8b 100644 --- a/packages/docusaurus-plugin-sitemap/src/index.ts +++ b/packages/docusaurus-plugin-sitemap/src/index.ts @@ -32,7 +32,7 @@ export default function pluginSitemap( ); // Write sitemap file. - const sitemapPath = path.join(outDir, 'sitemap.xml'); + const sitemapPath = path.join(outDir, options.filename); try { await fs.outputFile(sitemapPath, generatedSitemap); } catch (err) { diff --git a/packages/docusaurus-plugin-sitemap/src/options.ts b/packages/docusaurus-plugin-sitemap/src/options.ts index 365f60156eaf..9cc1fe1b8cc1 100644 --- a/packages/docusaurus-plugin-sitemap/src/options.ts +++ b/packages/docusaurus-plugin-sitemap/src/options.ts @@ -19,6 +19,11 @@ export type PluginOptions = { * sitemap. Note that you may need to include the base URL in here. */ ignorePatterns: string[]; + /** + * The path to the created sitemap file, relative to the output directory. + * Useful if you have two plugin instances outputting two files. + */ + filename: string; }; export type Options = Partial; @@ -27,6 +32,7 @@ export const DEFAULT_OPTIONS: PluginOptions = { changefreq: EnumChangefreq.WEEKLY, priority: 0.5, ignorePatterns: [], + filename: 'sitemap.xml', }; const PluginOptionSchema = Joi.object({ @@ -46,6 +52,7 @@ const PluginOptionSchema = Joi.object({ 'any.unknown': 'Please use the new Docusaurus global trailingSlash config instead, and the sitemaps plugin will use it.', }), + filename: Joi.string().default(DEFAULT_OPTIONS.filename), }); export function validateOptions({ diff --git a/packages/docusaurus-preset-classic/package.json b/packages/docusaurus-preset-classic/package.json index 40a209675956..7a1cccb25234 100644 --- a/packages/docusaurus-preset-classic/package.json +++ b/packages/docusaurus-preset-classic/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/preset-classic", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Classic preset for Docusaurus.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -18,17 +18,18 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/plugin-content-blog": "2.0.0-beta.20", - "@docusaurus/plugin-content-docs": "2.0.0-beta.20", - "@docusaurus/plugin-content-pages": "2.0.0-beta.20", - "@docusaurus/plugin-debug": "2.0.0-beta.20", - "@docusaurus/plugin-google-analytics": "2.0.0-beta.20", - "@docusaurus/plugin-google-gtag": "2.0.0-beta.20", - "@docusaurus/plugin-sitemap": "2.0.0-beta.20", - "@docusaurus/theme-classic": "2.0.0-beta.20", - "@docusaurus/theme-common": "2.0.0-beta.20", - "@docusaurus/theme-search-algolia": "2.0.0-beta.20" + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/plugin-content-blog": "2.0.0-beta.21", + "@docusaurus/plugin-content-docs": "2.0.0-beta.21", + "@docusaurus/plugin-content-pages": "2.0.0-beta.21", + "@docusaurus/plugin-debug": "2.0.0-beta.21", + "@docusaurus/plugin-google-analytics": "2.0.0-beta.21", + "@docusaurus/plugin-google-gtag": "2.0.0-beta.21", + "@docusaurus/plugin-sitemap": "2.0.0-beta.21", + "@docusaurus/theme-classic": "2.0.0-beta.21", + "@docusaurus/theme-common": "2.0.0-beta.21", + "@docusaurus/theme-search-algolia": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-remark-plugin-npm2yarn/package.json b/packages/docusaurus-remark-plugin-npm2yarn/package.json index 0c9c44fdc3a2..3f2ab9582005 100644 --- a/packages/docusaurus-remark-plugin-npm2yarn/package.json +++ b/packages/docusaurus-remark-plugin-npm2yarn/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/remark-plugin-npm2yarn", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Remark plugin for converting npm commands to Yarn commands as tabs.", "main": "lib/index.js", "publishConfig": { diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index 9439db4a2c40..265f41be2a66 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/theme-classic", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Classic theme for Docusaurus", "main": "lib/index.js", "types": "src/theme-classic.d.ts", @@ -20,15 +20,18 @@ "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch" }, "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/plugin-content-blog": "2.0.0-beta.20", - "@docusaurus/plugin-content-docs": "2.0.0-beta.20", - "@docusaurus/plugin-content-pages": "2.0.0-beta.20", - "@docusaurus/theme-common": "2.0.0-beta.20", - "@docusaurus/theme-translations": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-common": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/mdx-loader": "2.0.0-beta.21", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", + "@docusaurus/plugin-content-blog": "2.0.0-beta.21", + "@docusaurus/plugin-content-docs": "2.0.0-beta.21", + "@docusaurus/plugin-content-pages": "2.0.0-beta.21", + "@docusaurus/theme-common": "2.0.0-beta.21", + "@docusaurus/theme-translations": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-common": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "@mdx-js/react": "^1.6.22", "clsx": "^1.1.1", "copy-text-to-clipboard": "^3.0.1", @@ -40,11 +43,12 @@ "prismjs": "^1.28.0", "react-router-dom": "^5.3.3", "rtlcss": "^3.5.0", - "tslib": "^2.4.0" + "tslib": "^2.4.0", + "utility-types": "^3.10.0" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20", - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", "@types/mdx-js__react": "^1.5.5", "@types/nprogress": "^0.2.0", "@types/prismjs": "^1.26.0", diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index 1986158d8e22..f182ba6470ac 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -328,8 +328,6 @@ declare module '@theme/DocSidebar' { readonly sidebar: readonly PropSidebarItem[]; readonly onCollapse: () => void; readonly isHidden: boolean; - // MobileSecondaryFilter expects Record - readonly [key: string]: unknown; } export default function DocSidebar(props: Props): JSX.Element; diff --git a/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx index 3d47fc4dd379..d09c589f305c 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx @@ -65,9 +65,7 @@ function BlogPostPageContent(props: Props): JSX.Element { 0 ? ( + !hideTableOfContents && BlogPostContents.toc.length > 0 ? ( {filterItems(items).map((item, index) => (
- +
))} diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx index fa75f1c162e5..5e1e9debcf44 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx @@ -55,8 +55,7 @@ function DocItemContent(props: Props): JSX.Element { const windowSize = useWindowSize(); - const canRenderTOC = - !hideTableOfContents && DocContent.toc && DocContent.toc.length > 0; + const canRenderTOC = !hideTableOfContents && DocContent.toc.length > 0; const renderTocDesktop = canRenderTOC && (windowSize === 'desktop' || windowSize === 'ssr'); diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Code.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Code.tsx index 4d5680ed0adb..c1977000be7c 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Code.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Code.tsx @@ -11,7 +11,7 @@ import CodeBlock from '@theme/CodeBlock'; import type {Props} from '@theme/MDXComponents/Code'; export default function MDXCode(props: Props): JSX.Element { - const inlineElements = [ + const inlineElements: (string | undefined)[] = [ 'a', 'b', 'big', @@ -26,7 +26,10 @@ export default function MDXCode(props: Props): JSX.Element { const shouldBeInline = React.Children.toArray(props.children).every( (el) => (typeof el === 'string' && !el.includes('\n')) || - (isValidElement(el) && inlineElements.includes(el.props.mdxType)), + (isValidElement(el) && + inlineElements.includes( + (el.props as {mdxType: string} | null)?.mdxType, + )), ); return shouldBeInline ? ( diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Details.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Details.tsx index c99fdc2a6adb..08ddaf1a1fee 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Details.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Details.tsx @@ -15,7 +15,8 @@ export default function MDXDetails(props: Props): JSX.Element { // Details theme component const summary = items.find( (item): item is ReactElement> => - React.isValidElement(item) && item.props?.mdxType === 'summary', + React.isValidElement(item) && + (item.props as {mdxType: string} | null)?.mdxType === 'summary', ); const children = <>{items.filter((item) => item !== summary)}; diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Head.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Head.tsx index bf8867f409ba..3b8924c0ed6d 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Head.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Head.tsx @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import React, {type ReactElement, type ComponentProps} from 'react'; -import Head from '@docusaurus/Head'; +import React, {type ReactElement} from 'react'; +import Head, {type Props as HeadProps} from '@docusaurus/Head'; import type {Props} from '@theme/MDXComponents/Head'; // MDX elements are wrapped through the MDX pragma. In some cases (notably usage @@ -25,7 +25,5 @@ export default function MDXHead(props: Props): JSX.Element { const unwrappedChildren = React.Children.map(props.children, (child) => React.isValidElement(child) ? unwrapMDXElement(child) : child, ); - return ( - )}>{unwrappedChildren} - ); + return {unwrappedChildren}; } diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Pre.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Pre.tsx index 75e64c997171..cde1899da83e 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Pre.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Pre.tsx @@ -14,7 +14,8 @@ export default function MDXPre(props: Props): JSX.Element { diff --git a/packages/docusaurus-theme-classic/src/theme/MDXPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/MDXPage/index.tsx index 64bb180a5634..e0fbca8fcf8d 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXPage/index.tsx @@ -42,7 +42,7 @@ export default function MDXPage(props: Props): JSX.Element { - {!hideTableOfContents && MDXPageContent.toc && ( + {!hideTableOfContents && MDXPageContent.toc.length > 0 && (
void | false; * will be blocked/cancelled. */ function useHistoryActionHandler(handler: HistoryBlockHandler): void { - const {block} = useHistory(); + const history = useHistory(); const stableHandler = useDynamicCallback(handler); useEffect( // See https://github.com/remix-run/history/blob/main/docs/blocking-transitions.md - () => block((location, action) => stableHandler(location, action)), - [block, stableHandler], + () => history.block((location, action) => stableHandler(location, action)), + [history, stableHandler], ); } diff --git a/packages/docusaurus-theme-live-codeblock/package.json b/packages/docusaurus-theme-live-codeblock/package.json index 4454d741c479..1f4bbe657f24 100644 --- a/packages/docusaurus-theme-live-codeblock/package.json +++ b/packages/docusaurus-theme-live-codeblock/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/theme-live-codeblock", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docusaurus live code block component.", "main": "lib/index.js", "types": "src/theme-live-codeblock.d.ts", @@ -23,10 +23,10 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/theme-common": "2.0.0-beta.20", - "@docusaurus/theme-translations": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/theme-common": "2.0.0-beta.21", + "@docusaurus/theme-translations": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "@philpl/buble": "^0.19.7", "clsx": "^1.1.1", "fs-extra": "^10.1.0", @@ -34,7 +34,7 @@ "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/types": "2.0.0-beta.21", "@types/buble": "^0.20.1" }, "peerDependencies": { diff --git a/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts b/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts index 5bb5e51d2d26..b4dd299705cd 100644 --- a/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts +++ b/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts @@ -5,6 +5,9 @@ * LICENSE file in the root directory of this source tree. */ +/// +/// + declare module '@docusaurus/theme-live-codeblock' { export type ThemeConfig = { liveCodeBlock: { @@ -14,9 +17,12 @@ declare module '@docusaurus/theme-live-codeblock' { } declare module '@theme/Playground' { + import type {Props as BaseProps} from '@theme/CodeBlock'; import type {LiveProviderProps} from 'react-live'; - export interface Props extends LiveProviderProps { + type CodeBlockProps = Omit; + + export interface Props extends CodeBlockProps, LiveProviderProps { children: string; } export default function Playground(props: LiveProviderProps): JSX.Element; diff --git a/packages/docusaurus-theme-live-codeblock/src/theme/Playground/index.tsx b/packages/docusaurus-theme-live-codeblock/src/theme/Playground/index.tsx index ef5c0f0f4ff9..81fa2ea65b0a 100644 --- a/packages/docusaurus-theme-live-codeblock/src/theme/Playground/index.tsx +++ b/packages/docusaurus-theme-live-codeblock/src/theme/Playground/index.tsx @@ -93,11 +93,14 @@ export default function Playground({ } = themeConfig as ThemeConfig; const prismTheme = usePrismTheme(); + const noInline = props.metastring?.includes('noInline') ?? false; + return (
{/* @ts-expect-error: type incompatibility with refs */} `${code};`)} theme={prismTheme} {...props}> diff --git a/packages/docusaurus-theme-search-algolia/package.json b/packages/docusaurus-theme-search-algolia/package.json index 518e0836e599..0a397b2ffc26 100644 --- a/packages/docusaurus-theme-search-algolia/package.json +++ b/packages/docusaurus-theme-search-algolia/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/theme-search-algolia", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Algolia search component for Docusaurus.", "main": "lib/index.js", "sideEffects": [ @@ -28,13 +28,13 @@ }, "dependencies": { "@docsearch/react": "^3.1.0", - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/plugin-content-docs": "2.0.0-beta.20", - "@docusaurus/theme-common": "2.0.0-beta.20", - "@docusaurus/theme-translations": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/plugin-content-docs": "2.0.0-beta.21", + "@docusaurus/theme-common": "2.0.0-beta.21", + "@docusaurus/theme-translations": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", "algoliasearch": "^4.13.1", "algoliasearch-helper": "^3.8.2", "clsx": "^1.1.1", @@ -45,7 +45,7 @@ "utility-types": "^3.10.0" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20" + "@docusaurus/module-type-aliases": "2.0.0-beta.21" }, "peerDependencies": { "react": "^16.8.4 || ^17.0.0", diff --git a/packages/docusaurus-theme-translations/package.json b/packages/docusaurus-theme-translations/package.json index 5b10cbf18e24..3e4d47626f8b 100644 --- a/packages/docusaurus-theme-translations/package.json +++ b/packages/docusaurus-theme-translations/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/theme-translations", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Docusaurus theme translations.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -23,8 +23,8 @@ "tslib": "^2.4.0" }, "devDependencies": { - "@docusaurus/core": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", + "@docusaurus/core": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", "lodash": "^4.17.21" }, "engines": { diff --git a/packages/docusaurus-types/package.json b/packages/docusaurus-types/package.json index 051f1625c8ff..4415cf4a1c37 100644 --- a/packages/docusaurus-types/package.json +++ b/packages/docusaurus-types/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/types", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Common types for Docusaurus packages.", "types": "./src/index.d.ts", "publishConfig": { @@ -13,8 +13,8 @@ }, "license": "MIT", "dependencies": { + "@types/history": "^4.7.11", "commander": "^5.1.0", - "history": "^4.9.0", "joi": "^17.6.0", "react-helmet-async": "^1.3.0", "utility-types": "^3.10.0", diff --git a/packages/docusaurus-utils-common/package.json b/packages/docusaurus-utils-common/package.json index 9bdb0b8d122c..50ea22d1d835 100644 --- a/packages/docusaurus-utils-common/package.json +++ b/packages/docusaurus-utils-common/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/utils-common", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Common (Node/Browser) utility functions for Docusaurus packages.", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -21,8 +21,13 @@ "dependencies": { "tslib": "^2.4.0" }, - "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20" + "peerDependencies": { + "@docusaurus/types": "*" + }, + "peerDependenciesMeta": { + "@docusaurus/types": { + "optional": true + } }, "engines": { "node": ">=16.14" diff --git a/packages/docusaurus-utils-validation/package.json b/packages/docusaurus-utils-validation/package.json index 9059249d9b04..7c98f611dda3 100644 --- a/packages/docusaurus-utils-validation/package.json +++ b/packages/docusaurus-utils-validation/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/utils-validation", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Node validation utility functions for Docusaurus packages.", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -18,8 +18,8 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/utils": "2.0.0-beta.20", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/utils": "2.0.0-beta.21", "joi": "^17.6.0", "js-yaml": "^4.1.0", "tslib": "^2.4.0" diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index 4a460a57d648..f4c1f954d68a 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/utils", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Node utility functions for Docusaurus packages.", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -18,7 +18,7 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/logger": "2.0.0-beta.20", + "@docusaurus/logger": "2.0.0-beta.21", "@svgr/webpack": "^6.2.1", "file-loader": "^6.2.0", "fs-extra": "^10.1.0", @@ -38,11 +38,19 @@ "node": ">=16.14" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/types": "2.0.0-beta.21", "@types/dedent": "^0.7.0", "@types/github-slugger": "^1.3.0", "@types/micromatch": "^4.0.2", - "@types/react-dom": "^18.0.4", + "@types/react-dom": "^18.0.5", "dedent": "^0.7.0" + }, + "peerDependencies": { + "@docusaurus/types": "*" + }, + "peerDependenciesMeta": { + "@docusaurus/types": { + "optional": true + } } } diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index 664fd9977dbd..fcc26af6e257 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -1,7 +1,7 @@ { "name": "@docusaurus/core", "description": "Easy to Maintain Open Source Documentation Websites", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "license": "MIT", "publishConfig": { "access": "public" @@ -33,28 +33,28 @@ "url": "https://github.com/facebook/docusaurus/issues" }, "dependencies": { - "@babel/core": "^7.18.0", - "@babel/generator": "^7.18.0", + "@babel/core": "^7.18.2", + "@babel/generator": "^7.18.2", "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "@babel/plugin-transform-runtime": "^7.18.0", - "@babel/preset-env": "^7.18.0", + "@babel/plugin-transform-runtime": "^7.18.2", + "@babel/preset-env": "^7.18.2", "@babel/preset-react": "^7.17.12", "@babel/preset-typescript": "^7.17.12", - "@babel/runtime": "^7.18.0", - "@babel/runtime-corejs3": "^7.18.0", - "@babel/traverse": "^7.18.0", - "@docusaurus/cssnano-preset": "2.0.0-beta.20", - "@docusaurus/logger": "2.0.0-beta.20", - "@docusaurus/mdx-loader": "2.0.0-beta.20", + "@babel/runtime": "^7.18.3", + "@babel/runtime-corejs3": "^7.18.3", + "@babel/traverse": "^7.18.2", + "@docusaurus/cssnano-preset": "2.0.0-beta.21", + "@docusaurus/logger": "2.0.0-beta.21", + "@docusaurus/mdx-loader": "2.0.0-beta.21", "@docusaurus/react-loadable": "5.5.2", - "@docusaurus/utils": "2.0.0-beta.20", - "@docusaurus/utils-common": "2.0.0-beta.20", - "@docusaurus/utils-validation": "2.0.0-beta.20", - "@slorber/static-site-generator-webpack-plugin": "^4.0.4", + "@docusaurus/utils": "2.0.0-beta.21", + "@docusaurus/utils-common": "2.0.0-beta.21", + "@docusaurus/utils-validation": "2.0.0-beta.21", + "@slorber/static-site-generator-webpack-plugin": "^4.0.7", "@svgr/webpack": "^6.2.1", "autoprefixer": "^10.4.7", "babel-loader": "^8.2.5", - "babel-plugin-dynamic-import-node": "2.3.0", + "babel-plugin-dynamic-import-node": "^2.3.3", "boxen": "^6.2.1", "chalk": "^4.1.2", "chokidar": "^3.5.3", @@ -62,12 +62,12 @@ "cli-table3": "^0.6.2", "combine-promises": "^1.1.0", "commander": "^5.1.0", - "copy-webpack-plugin": "^10.2.4", - "core-js": "^3.22.5", + "copy-webpack-plugin": "^11.0.0", + "core-js": "^3.22.7", "css-loader": "^6.7.1", - "css-minimizer-webpack-plugin": "^3.4.1", + "css-minimizer-webpack-plugin": "^4.0.0", "cssnano": "^5.1.9", - "del": "^6.1.0", + "del": "^6.1.1", "detect-port": "^1.3.0", "escape-html": "^1.0.3", "eta": "^1.12.3", @@ -81,7 +81,7 @@ "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.6.0", "postcss": "^8.4.14", - "postcss-loader": "^6.2.1", + "postcss-loader": "^7.0.0", "prompts": "^2.4.2", "react-dev-utils": "^12.0.1", "react-helmet-async": "^1.3.0", @@ -107,10 +107,10 @@ "webpackbar": "^5.0.2" }, "devDependencies": { - "@docusaurus/module-type-aliases": "2.0.0-beta.20", - "@docusaurus/types": "2.0.0-beta.20", + "@docusaurus/module-type-aliases": "2.0.0-beta.21", + "@docusaurus/types": "2.0.0-beta.21", "@types/detect-port": "^1.3.2", - "@types/react-dom": "^18.0.4", + "@types/react-dom": "^18.0.5", "@types/react-router-config": "^5.0.6", "@types/rtl-detect": "^1.0.0", "@types/serve-handler": "^6.1.1", diff --git a/packages/docusaurus/src/client/.eslintrc.js b/packages/docusaurus/src/client/.eslintrc.js deleted file mode 100644 index cbef5af73663..000000000000 --- a/packages/docusaurus/src/client/.eslintrc.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -module.exports = { - rules: { - 'no-restricted-imports': [ - 'error', - { - patterns: [ - // Prevent importing lodash in client bundle for bundle size - 'lodash', - 'lodash.**', - 'lodash/**', - // Prevent importing server code in client bundle - '**/../babel/**', - '**/../server/**', - '**/../commands/**', - '**/../webpack/**', - ], - }, - ], - }, -}; diff --git a/packages/docusaurus/src/client/SiteMetadataDefaults.tsx b/packages/docusaurus/src/client/SiteMetadataDefaults.tsx index bd2f953aab3e..e3ba631fbbe5 100644 --- a/packages/docusaurus/src/client/SiteMetadataDefaults.tsx +++ b/packages/docusaurus/src/client/SiteMetadataDefaults.tsx @@ -12,15 +12,17 @@ import useBaseUrl from '@docusaurus/useBaseUrl'; export default function SiteMetadataDefaults(): JSX.Element { const { - siteConfig: {favicon, tagline, title}, + siteConfig: {favicon, title}, i18n: {currentLocale, localeConfigs}, } = useDocusaurusContext(); const faviconUrl = useBaseUrl(favicon); const {htmlLang, direction: htmlDir} = localeConfigs[currentLocale]!; return ( - + + {title} + {favicon && } ); diff --git a/packages/docusaurus/src/client/exports/ErrorBoundary.tsx b/packages/docusaurus/src/client/exports/ErrorBoundary.tsx index 0d188d4da44b..c29a33a9ca32 100644 --- a/packages/docusaurus/src/client/exports/ErrorBoundary.tsx +++ b/packages/docusaurus/src/client/exports/ErrorBoundary.tsx @@ -18,6 +18,7 @@ type State = { error: Error | null; }; +// eslint-disable-next-line react/function-component-definition const DefaultFallback: FallbackFunction = (params) => ( ); diff --git a/packages/docusaurus/src/deps.d.ts b/packages/docusaurus/src/deps.d.ts index 57de485ea0ce..c70f6b8b54b4 100644 --- a/packages/docusaurus/src/deps.d.ts +++ b/packages/docusaurus/src/deps.d.ts @@ -64,6 +64,7 @@ declare module '@slorber/static-site-generator-webpack-plugin' { paths: string[]; preferFoldersOutput?: boolean; globals: {[key: string]: unknown}; + concurrency?: number; }); apply(compiler: Compiler): void; } diff --git a/packages/docusaurus/src/webpack/server.ts b/packages/docusaurus/src/webpack/server.ts index 7f93c86a4bb9..4942ed5c0c76 100644 --- a/packages/docusaurus/src/webpack/server.ts +++ b/packages/docusaurus/src/webpack/server.ts @@ -90,6 +90,12 @@ export default async function createServerConfig({ // has any importance for this plugin, just using an empty string to // avoid the error. See https://github.com/facebook/docusaurus/issues/4922 globals: {__filename: ''}, + + // Secret way to set SSR plugin concurrency option + // Waiting for feedback before documenting this officially? + concurrency: process.env.DOCUSAURUS_SSR_CONCURRENCY + ? parseInt(process.env.DOCUSAURUS_SSR_CONCURRENCY, 10) + : undefined, }), // Show compilation progress bar. diff --git a/packages/eslint-plugin/.eslintrc.js b/packages/eslint-plugin/.eslintrc.js deleted file mode 100644 index 81bfbca20171..000000000000 --- a/packages/eslint-plugin/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -module.exports = { - extends: ['../../.eslintrc.js', 'plugin:eslint-plugin/recommended'], -}; diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 8dca637d064b..f8a2e7e1c7cf 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/eslint-plugin", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "ESLint plugin to enforce best Docusaurus practices.", "main": "lib/index.js", "keywords": [ @@ -21,7 +21,7 @@ "build": "tsc" }, "dependencies": { - "@typescript-eslint/utils": "^5.25.0", + "@typescript-eslint/utils": "^5.26.0", "tslib": "^2.4.0" }, "devDependencies": { diff --git a/packages/lqip-loader/package.json b/packages/lqip-loader/package.json index 1311e978db16..1ada06e07f96 100644 --- a/packages/lqip-loader/package.json +++ b/packages/lqip-loader/package.json @@ -1,6 +1,6 @@ { "name": "@docusaurus/lqip-loader", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Low Quality Image Placeholders (LQIP) loader for webpack.", "main": "lib/index.js", "publishConfig": { @@ -17,10 +17,10 @@ }, "license": "MIT", "dependencies": { - "@docusaurus/logger": "2.0.0-beta.20", + "@docusaurus/logger": "2.0.0-beta.21", "file-loader": "^6.2.0", "lodash": "^4.17.21", - "sharp": "^0.30.4", + "sharp": "^0.30.5", "tslib": "^2.4.0" }, "engines": { diff --git a/packages/stylelint-copyright/package.json b/packages/stylelint-copyright/package.json index 795992466776..b859ae13d44a 100644 --- a/packages/stylelint-copyright/package.json +++ b/packages/stylelint-copyright/package.json @@ -1,6 +1,6 @@ { "name": "stylelint-copyright", - "version": "2.0.0-beta.20", + "version": "2.0.0-beta.21", "description": "Stylelint plugin to check CSS files for a copyright header.", "main": "lib/index.js", "license": "MIT", @@ -14,7 +14,7 @@ "directory": "packages/stylelint-copyright" }, "dependencies": { - "stylelint": "^14.8.3", + "stylelint": "^14.8.5", "tslib": "^2.4.0" } } diff --git a/website/_dogfooding/_docs tests/doc-with-last-update.md b/website/_dogfooding/_docs tests/doc-with-last-update.md new file mode 100644 index 000000000000..34c1cb0c7cb6 --- /dev/null +++ b/website/_dogfooding/_docs tests/doc-with-last-update.md @@ -0,0 +1,7 @@ +--- +last_update: + author: custom author + date: 1/1/2000 +--- + +# Doc With Last Update Front Matter diff --git a/website/_dogfooding/clientModuleExample.ts b/website/_dogfooding/clientModuleExample.ts index 01b2d8250631..cd61e5a99e81 100644 --- a/website/_dogfooding/clientModuleExample.ts +++ b/website/_dogfooding/clientModuleExample.ts @@ -13,10 +13,16 @@ function logPage( location: Location, previousLocation: Location | null, ): void { - console.log(`${event} -Previous location: ${previousLocation?.pathname} -Current location: ${location.pathname} -Current heading: ${document.getElementsByTagName('h1')[0]?.innerText}`); + console.log(event, location.pathname, { + location, + prevLocation: previousLocation, + heading: document.getElementsByTagName('h1')[0]?.innerText, + title: document.title, + description: ( + document.querySelector('meta[name="description"]') as HTMLMetaElement + )?.content, + htmlClassName: document.getElementsByTagName('html')[0]?.className, + }); } export function onRouteUpdate({ diff --git a/website/_dogfooding/docs-tests-sidebars.js b/website/_dogfooding/docs-tests-sidebars.js index e7ebb55ce1a5..0c2783feeda3 100644 --- a/website/_dogfooding/docs-tests-sidebars.js +++ b/website/_dogfooding/docs-tests-sidebars.js @@ -22,6 +22,7 @@ const sidebars = { 'test-draft', 'doc-without-sidebar', 'doc-with-another-sidebar', + 'doc-with-last-update', { type: 'category', label: 'Tests', diff --git a/website/_dogfooding/dogfooding.config.js b/website/_dogfooding/dogfooding.config.js index b6239f787b42..f8a4e7007f0e 100644 --- a/website/_dogfooding/dogfooding.config.js +++ b/website/_dogfooding/dogfooding.config.js @@ -30,6 +30,7 @@ const dogfoodingPluginInstances = [ // Using a _ prefix to test against an edge case regarding MDX partials: https://github.com/facebook/docusaurus/discussions/5181#discussioncomment-1018079 path: '_dogfooding/_docs tests', showLastUpdateTime: true, + showLastUpdateAuthor: true, sidebarItemsGenerator(args) { return args.defaultSidebarItemsGenerator({ ...args, diff --git a/website/docs/advanced/ssg.md b/website/docs/advanced/ssg.md index 0a394f9179b4..dbd104d78a95 100644 --- a/website/docs/advanced/ssg.md +++ b/website/docs/advanced/ssg.md @@ -8,12 +8,14 @@ description: Docusaurus statically renders your React code into HTML, allowing f In [architecture](architecture.md), we mentioned that the theme is run in Webpack. But beware: that doesn't mean it always has access to browser globals! The theme is built twice: - During **server-side rendering**, the theme is compiled in a sandbox called [React DOM Server](https://reactjs.org/docs/react-dom-server.html). You can see this as a "headless browser", where there is no `window` or `document`, only React. SSR produces static HTML pages. -- During **client-side rendering**, the theme is compiled with standard React DOM, and has access to browser variables. CSR produces dynamic JavaScript. +- During **client-side rendering**, the theme is compiled to JavaScript that gets eventually executed in the browser, so it has access to browser variables. :::info SSR or SSG? _Server-side rendering_ and _static site generation_ can be different concepts, but we use them interchangeably. +Strictly speaking, Docusaurus is a static site generator, because there's no server-side runtime—we statically render to HTML files that are deployed on a CDN, instead of dynamically pre-rendering on each request. This differs from the working model of [Next.js](https://nextjs.org/). + ::: Therefore, while you probably know not to access Node globals like `process` ([or can we?](#node-env)) or the `'fs'` module, you can't freely access browser globals either. diff --git a/website/docs/api/docusaurus.config.js.md b/website/docs/api/docusaurus.config.js.md index 9910ddb5220a..0b0a6ecf8832 100644 --- a/website/docs/api/docusaurus.config.js.md +++ b/website/docs/api/docusaurus.config.js.md @@ -1,6 +1,5 @@ --- sidebar_position: 0 -id: docusaurus.config.js description: API reference for Docusaurus configuration file. slug: /api/docusaurus-config --- @@ -426,7 +425,7 @@ module.exports = { ### `scripts` {#scripts} -An array of scripts to load. The values can be either strings or plain objects of attribute-value maps. The `