diff --git a/.circleci/config.yml b/.circleci/config.yml index 987f4b8674df..2e96bb55ae5e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ aliases: defaults: &defaults working_directory: ~/docusaurus docker: - - image: circleci/node:10 + - image: circleci/node:12 resource_class: large version: 2 diff --git a/.github/workflows/canary-releases.yml b/.github/workflows/canary-releases.yml index 111ac516a976..d003a7fa4d92 100644 --- a/.github/workflows/canary-releases.yml +++ b/.github/workflows/canary-releases.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [10.x] + node-version: [12.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index e3404970d12e..00fa9f9d5402 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['10'] + node: ['12'] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node }} diff --git a/.github/workflows/migration-cli-e2e-test.yml b/.github/workflows/migration-cli-e2e-test.yml index 136e197ee535..80aa06852d37 100644 --- a/.github/workflows/migration-cli-e2e-test.yml +++ b/.github/workflows/migration-cli-e2e-test.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['10'] + node: ['12'] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node }} diff --git a/.github/workflows/nodejs-windows.yml b/.github/workflows/nodejs-windows.yml index d2bb701d35ff..5baf5a8906c6 100644 --- a/.github/workflows/nodejs-windows.yml +++ b/.github/workflows/nodejs-windows.yml @@ -10,7 +10,7 @@ jobs: runs-on: windows-latest strategy: matrix: - node: ['10'] + node: ['12'] steps: - uses: actions/checkout@v2 - uses: dorny/paths-filter@v2 diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 000000000000..c9cdc63b0701 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000000..12ac3025e490 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +yarn lint-staged --allow-empty diff --git a/.nvmrc b/.nvmrc index 1047f696810d..47c0a98a1131 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -10.15.1 +12.13.0 diff --git a/examples/classic/package.json b/examples/classic/package.json index c1c1c68aef96..c51d1adc1959 100644 --- a/examples/classic/package.json +++ b/examples/classic/package.json @@ -33,4 +33,4 @@ ] }, "description": "Docusaurus example project" -} \ No newline at end of file +} diff --git a/examples/facebook/package.json b/examples/facebook/package.json index 29652ef2f7a8..eb2a153c591e 100644 --- a/examples/facebook/package.json +++ b/examples/facebook/package.json @@ -50,4 +50,4 @@ ] }, "description": "Docusaurus example project (facebook template)" -} \ No newline at end of file +} diff --git a/package.json b/package.json index 2443c5274d5a..9a04ca75b978 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,9 @@ "canary:bumpVersion": "yarn lerna version 2.0.0-alpha.`git rev-parse --short HEAD` --exact --no-push --yes", "canary:publish": "yarn lerna publish from-package --dist-tag canary --yes --no-verify-access", "changelog": "lerna-changelog", - "postinstall": "yarn lock:update && yarn build:packages", + "postinstall": "run-p postinstall:**", + "postinstall:main": "yarn lock:update && yarn build:packages", + "postinstall:dev": "is-ci || husky install", "prettier": "prettier --config .prettierrc --write \"**/*.{js,jsx,ts,tsx}\"", "prettier:diff": "prettier --config .prettierrc --list-different \"**/*.{js,jsx,ts,tsx}\"", "prettier-docs": "prettier --config .prettierrc --write \"**/*.md\"", @@ -62,16 +64,16 @@ "lock:update": "npx yarn-deduplicate" }, "devDependencies": { - "@babel/cli": "^7.12.1", - "@babel/core": "^7.12.3", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1", - "@babel/plugin-proposal-optional-chaining": "^7.12.1", - "@babel/plugin-transform-modules-commonjs": "^7.12.1", - "@babel/preset-typescript": "^7.12.1", - "@crowdin/cli": "^3.5.2", + "@babel/cli": "^7.12.16", + "@babel/core": "^7.12.16", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13", + "@babel/plugin-proposal-optional-chaining": "^7.12.16", + "@babel/plugin-transform-modules-commonjs": "^7.12.13", + "@babel/preset-typescript": "^7.12.16", + "@crowdin/cli": "^3.5.3", "@types/express": "^4.17.2", "@types/fs-extra": "^9.0.6", - "@types/jest": "^25.2.1", + "@types/jest": "^26.0.20", "@types/loader-utils": "^1.1.3", "@types/lodash.camelcase": "^4.3.6", "@types/lodash.flatmap": "^4.5.6", @@ -86,7 +88,7 @@ "@types/node": "^14.14.22", "@types/prismjs": "^1.16.2", "@types/prompts": "^2.0.9", - "@types/react": "^16.9.52", + "@types/react": "^17.0.2", "@types/react-dev-utils": "^9.0.1", "@types/react-helmet": "^6.0.0", "@types/react-loadable": "^5.5.3", @@ -102,9 +104,7 @@ "babel-eslint": "^10.0.3", "concurrently": "^5.3.0", "cross-env": "^7.0.3", - "enzyme": "^3.10.0", - "enzyme-adapter-react-16": "^1.15.1", - "eslint": "^7.13.0", + "eslint": "^7.20.0", "eslint-config-airbnb": "^18.2.1", "eslint-config-prettier": "^6.15.0", "eslint-plugin-header": "^3.0.0", @@ -113,19 +113,21 @@ "eslint-plugin-react": "^7.21.5", "eslint-plugin-react-hooks": "^4.2.0", "glob": "^7.1.6", - "husky": "^4.2.3", - "jest": "^25.2.7", + "husky": "^5.0.9", + "is-ci": "^2.0.0", + "jest": "^26.6.3", "lerna": "^3.22.1", "lerna-changelog": "^1.0.1", - "lint-staged": "^10.1.2", + "lint-staged": "^10.5.4", "netlify-cli": "^2.58.0", "nodemon": "^2.0.7", - "prettier": "^2.0.2", - "react": "^16.8.4", - "react-dom": "^16.8.4", + "npm-run-all": "^4.1.5", + "prettier": "^2.2.1", + "react": "^17.0.1", + "react-dom": "^17.0.1", "rimraf": "^3.0.2", "serve": "^11.3.2", - "stylelint": "^13.2.1", + "stylelint": "^13.10.0", "typescript": "^3.9.5" }, "lint-staged": { @@ -137,12 +139,7 @@ "prettier --write" ] }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-1.x/.eslintrc.js b/packages/docusaurus-1.x/.eslintrc.js index 5bbfd2ece892..5247faea97d1 100644 --- a/packages/docusaurus-1.x/.eslintrc.js +++ b/packages/docusaurus-1.x/.eslintrc.js @@ -42,6 +42,7 @@ module.exports = { 'react/forbid-prop-types': OFF, // 1 'react/require-default-props': OFF, // 1 'jsx-a11y/control-has-associated-label': OFF, // 1 + 'react/jsx-no-target-blank': OFF, // 1 'react/jsx-props-no-spreading': OFF, // 2 'max-classes-per-file': OFF, // 2 'prefer-object-spread': OFF, // 5 diff --git a/packages/docusaurus-1.x/package.json b/packages/docusaurus-1.x/package.json index 6d48c8a6ed94..9be14fcf89be 100644 --- a/packages/docusaurus-1.x/package.json +++ b/packages/docusaurus-1.x/package.json @@ -45,6 +45,8 @@ "commander": "^4.0.1", "crowdin-cli": "^0.3.0", "cssnano": "^4.1.10", + "enzyme": "^3.10.0", + "enzyme-adapter-react-16": "^1.15.1", "escape-string-regexp": "^2.0.0", "express": "^4.17.1", "feed": "^4.2.1", diff --git a/packages/docusaurus-cssnano-preset/index.js b/packages/docusaurus-cssnano-preset/index.js index 8c48b12fd5a1..924ede8bbdc4 100644 --- a/packages/docusaurus-cssnano-preset/index.js +++ b/packages/docusaurus-cssnano-preset/index.js @@ -6,14 +6,12 @@ */ const advancedBasePreset = require('cssnano-preset-advanced'); -const postCssCombineDuplicatedSelectors = require('postcss-combine-duplicated-selectors'); const postCssSortMediaQueries = require('postcss-sort-media-queries'); const postCssRemoveOverriddenCustomProperties = require('./src/remove-overridden-custom-properties'); const preset = advancedBasePreset({autoprefixer: {add: true}}); preset.plugins.unshift( - [postCssCombineDuplicatedSelectors, {removeDuplicatedValues: true}], [postCssSortMediaQueries], [postCssRemoveOverriddenCustomProperties], ); diff --git a/packages/docusaurus-cssnano-preset/package.json b/packages/docusaurus-cssnano-preset/package.json index 3ea9656e00a0..900a08d21372 100644 --- a/packages/docusaurus-cssnano-preset/package.json +++ b/packages/docusaurus-cssnano-preset/package.json @@ -15,7 +15,6 @@ "dependencies": { "cssnano-preset-advanced": "^4.0.7", "postcss": "^7.0.2", - "postcss-combine-duplicated-selectors": "^9.1.0", "postcss-sort-media-queries": "^1.7.26" }, "devDependencies": { diff --git a/packages/docusaurus-init/package.json b/packages/docusaurus-init/package.json index 97369118e13d..6928c5a4195c 100644 --- a/packages/docusaurus-init/package.json +++ b/packages/docusaurus-init/package.json @@ -31,6 +31,6 @@ "shelljs": "^0.8.4" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-init/templates/bootstrap/package.json b/packages/docusaurus-init/templates/bootstrap/package.json index 3d17e73b2357..f052f6488f58 100644 --- a/packages/docusaurus-init/templates/bootstrap/package.json +++ b/packages/docusaurus-init/templates/bootstrap/package.json @@ -17,8 +17,8 @@ "@docusaurus/preset-bootstrap": "2.0.0-alpha.70", "@mdx-js/react": "^1.5.8", "classnames": "^2.2.6", - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^17.0.1", + "react-dom": "^17.0.1" }, "browserslist": { "production": [ diff --git a/packages/docusaurus-init/templates/classic/package.json b/packages/docusaurus-init/templates/classic/package.json index 1b747864aa1f..24f338dfe4ec 100644 --- a/packages/docusaurus-init/templates/classic/package.json +++ b/packages/docusaurus-init/templates/classic/package.json @@ -17,8 +17,8 @@ "@docusaurus/preset-classic": "2.0.0-alpha.70", "@mdx-js/react": "^1.6.21", "clsx": "^1.1.1", - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^17.0.1", + "react-dom": "^17.0.1" }, "browserslist": { "production": [ diff --git a/packages/docusaurus-init/templates/facebook/package.json b/packages/docusaurus-init/templates/facebook/package.json index 2e172de7cbf9..abd540bf827a 100644 --- a/packages/docusaurus-init/templates/facebook/package.json +++ b/packages/docusaurus-init/templates/facebook/package.json @@ -21,8 +21,8 @@ "@docusaurus/preset-classic": "2.0.0-alpha.70", "@mdx-js/react": "^1.6.21", "clsx": "^1.1.1", - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^17.0.1", + "react-dom": "^17.0.1" }, "devDependencies": { "babel-eslint": "^10.0.3", diff --git a/packages/docusaurus-mdx-loader/package.json b/packages/docusaurus-mdx-loader/package.json index b966ce25a4b1..3ec7467c84c7 100644 --- a/packages/docusaurus-mdx-loader/package.json +++ b/packages/docusaurus-mdx-loader/package.json @@ -16,8 +16,8 @@ }, "license": "MIT", "dependencies": { - "@babel/parser": "^7.12.5", - "@babel/traverse": "^7.12.5", + "@babel/parser": "^7.12.16", + "@babel/traverse": "^7.12.13", "@docusaurus/core": "2.0.0-alpha.70", "@docusaurus/utils": "2.0.0-alpha.70", "@mdx-js/mdx": "^1.6.21", @@ -41,13 +41,13 @@ "remark-mdx": "^1.6.21", "to-vfile": "^6.0.0", "unist-builder": "^2.0.3", - "unist-util-remove-position": "^2.0.1" + "unist-util-remove-position": "^3.0.0" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-migrate/package.json b/packages/docusaurus-migrate/package.json index 02848ffcfbae..84334010ee4f 100644 --- a/packages/docusaurus-migrate/package.json +++ b/packages/docusaurus-migrate/package.json @@ -23,7 +23,7 @@ "docusaurus-migrate": "bin/index.js" }, "dependencies": { - "@babel/preset-env": "^7.1.6", + "@babel/preset-env": "^7.12.16", "@mapbox/hast-util-to-jsx": "^1.0.0", "chalk": "^4.1.0", "color": "^3.1.3", diff --git a/packages/docusaurus-migrate/src/index.ts b/packages/docusaurus-migrate/src/index.ts index c39b668d9852..d41387d7655c 100644 --- a/packages/docusaurus-migrate/src/index.ts +++ b/packages/docusaurus-migrate/src/index.ts @@ -106,8 +106,8 @@ export async function migrateDocusaurusProject( '@docusaurus/core': DOCUSAURUS_VERSION, '@docusaurus/preset-classic': DOCUSAURUS_VERSION, clsx: '^1.1.1', - react: '^16.10.2', - 'react-dom': '^16.10.2', + react: '^17.0.1', + 'react-dom': '^17.0.1', }; try { createClientRedirects(siteConfig, deps, config); @@ -592,9 +592,9 @@ function migrateVersionedSidebar( acc: {[key: string]: Array | string>}, val, ) => { - acc[val[0].replace(versionRegex, '')] = (val[1] as Array< - any - >).map((item) => { + acc[ + val[0].replace(versionRegex, '') + ] = (val[1] as Array).map((item) => { if (typeof item === 'string') { return item.replace(versionRegex, ''); } diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index a40b0cdd7f77..96203f53b8f2 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -52,7 +52,7 @@ declare module '@generated/i18n' { defaultLocale: string; locales: [string, ...string[]]; currentLocale: string; - localeConfigs: Record; + localeConfigs: Record; }; export default i18n; } diff --git a/packages/docusaurus-plugin-client-redirects/package.json b/packages/docusaurus-plugin-client-redirects/package.json index 4416588d1a16..deae908fa70e 100644 --- a/packages/docusaurus-plugin-client-redirects/package.json +++ b/packages/docusaurus-plugin-client-redirects/package.json @@ -25,12 +25,12 @@ "eta": "^1.11.0", "fs-extra": "^9.0.1", "globby": "^11.0.2", - "joi": "^17.2.1", + "joi": "^17.4.0", "lodash": "^4.17.20" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { "node": ">=10.9.0" diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index 35a6e92758e6..c43187155c05 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -27,7 +27,7 @@ "feed": "^4.2.2", "fs-extra": "^9.1.0", "globby": "^11.0.2", - "joi": "^17.2.1", + "joi": "^17.4.0", "loader-utils": "^1.2.3", "lodash": "^4.17.20", "reading-time": "^1.3.0", @@ -35,10 +35,10 @@ "webpack": "^4.44.1" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index e1956f36d8cc..c7fa72811bdb 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -184,26 +184,31 @@ describe('loadBlog', () => { expect(editUrlFunction).toHaveBeenCalledWith({ blogDirPath: 'blog', blogPath: 'date-matter.md', + permalink: '/blog/date-matter', locale: 'en', }); expect(editUrlFunction).toHaveBeenCalledWith({ blogDirPath: 'blog', blogPath: 'draft.md', + permalink: '/blog/draft', locale: 'en', }); expect(editUrlFunction).toHaveBeenCalledWith({ blogDirPath: 'blog', blogPath: 'complex-slug.md', + permalink: '/blog/hey/my super path/héllô', locale: 'en', }); expect(editUrlFunction).toHaveBeenCalledWith({ blogDirPath: 'blog', blogPath: 'simple-slug.md', + permalink: '/blog/simple/slug', locale: 'en', }); expect(editUrlFunction).toHaveBeenCalledWith({ blogDirPath: 'i18n/en/docusaurus-plugin-content-blog', blogPath: '2018-12-14-Happy-First-Birthday-Slash.md', + permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash', locale: 'en', }); }); diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 07a69803aeec..cbb0b869bcd9 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -108,7 +108,7 @@ export async function generateBlogPosts( routeBasePath, truncateMarker, showReadingTime, - editUrl: siteEditUrl, + editUrl, } = options; if (!fs.existsSync(contentPaths.contentPath)) { @@ -136,37 +136,6 @@ export async function generateBlogPosts( const blogFileName = path.basename(blogSourceFile); - function getBlogEditUrl() { - const blogPathRelative = path.relative( - blogDirPath, - path.resolve(source), - ); - - if (typeof siteEditUrl === 'function') { - return siteEditUrl({ - blogDirPath: posixPath(path.relative(siteDir, blogDirPath)), - blogPath: posixPath(blogPathRelative), - locale: i18n.currentLocale, - }); - } else if (typeof siteEditUrl === 'string') { - const isLocalized = blogDirPath === contentPaths.contentPathLocalized; - const fileContentPath = - isLocalized && options.editLocalizedFiles - ? contentPaths.contentPathLocalized - : contentPaths.contentPath; - - const contentPathEditUrl = normalizeUrl([ - siteEditUrl, - posixPath(path.relative(siteDir, fileContentPath)), - ]); - - return getEditUrl(blogPathRelative, contentPathEditUrl); - } else { - return undefined; - } - } - const editBlogUrl = getBlogEditUrl(); - const {frontMatter, content, excerpt} = await parseMarkdownFile(source); if (frontMatter.draft && process.env.NODE_ENV === 'production') { @@ -204,11 +173,44 @@ export async function generateBlogPosts( frontMatter.slug || (match ? toUrl({date, link: linkName}) : linkName); frontMatter.title = frontMatter.title || linkName; + const permalink = normalizeUrl([baseUrl, routeBasePath, slug]); + + function getBlogEditUrl() { + const blogPathRelative = path.relative( + blogDirPath, + path.resolve(source), + ); + + if (typeof editUrl === 'function') { + return editUrl({ + blogDirPath: posixPath(path.relative(siteDir, blogDirPath)), + blogPath: posixPath(blogPathRelative), + permalink, + locale: i18n.currentLocale, + }); + } else if (typeof editUrl === 'string') { + const isLocalized = blogDirPath === contentPaths.contentPathLocalized; + const fileContentPath = + isLocalized && options.editLocalizedFiles + ? contentPaths.contentPathLocalized + : contentPaths.contentPath; + + const contentPathEditUrl = normalizeUrl([ + editUrl, + posixPath(path.relative(siteDir, fileContentPath)), + ]); + + return getEditUrl(blogPathRelative, contentPathEditUrl); + } else { + return undefined; + } + } + blogPosts.push({ id: frontMatter.slug || frontMatter.title, metadata: { - permalink: normalizeUrl([baseUrl, routeBasePath, slug]), - editUrl: editBlogUrl, + permalink, + editUrl: getBlogEditUrl(), source: aliasedSource, description: frontMatter.description || excerpt, date, diff --git a/packages/docusaurus-plugin-content-blog/src/types.ts b/packages/docusaurus-plugin-content-blog/src/types.ts index bd09792addc7..c83c68e5cb90 100644 --- a/packages/docusaurus-plugin-content-blog/src/types.ts +++ b/packages/docusaurus-plugin-content-blog/src/types.ts @@ -27,6 +27,7 @@ export type FeedType = 'rss' | 'atom'; export type EditUrlFunction = (editUrlParams: { blogDirPath: string; blogPath: string; + permalink: string; locale: string; }) => string | undefined; diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index 1c879d77608a..ff5fea271632 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -30,11 +30,11 @@ "@docusaurus/utils": "2.0.0-alpha.70", "@docusaurus/utils-validation": "2.0.0-alpha.70", "chalk": "^4.1.0", - "execa": "^3.4.0", + "execa": "^5.0.0", "fs-extra": "^9.1.0", "globby": "^11.0.2", "import-fresh": "^3.2.2", - "joi": "^17.2.1", + "joi": "^17.4.0", "loader-utils": "^1.2.3", "lodash": "^4.17.19", "lodash.flatmap": "^4.5.0", @@ -48,10 +48,10 @@ "webpack": "^4.44.1" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } 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 1991569ff0aa..3bee62a9d3ae 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -321,6 +321,7 @@ describe('simple site', () => { version: 'current', versionDocsDirPath: 'docs', docPath: path.posix.join('foo', 'baz.md'), + permalink: '/docs/foo/bazSlug.html', locale: 'en', }); }); @@ -672,6 +673,7 @@ describe('versioned site', () => { version: '1.0.0', versionDocsDirPath: 'versioned_docs/version-1.0.0', docPath: path.join('hello.md'), + permalink: '/docs/1.0.0/hello', locale: 'en', }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts index 6c106ded9a49..8b44ce8fd9cd 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/lastUpdate.test.ts @@ -38,10 +38,8 @@ describe('lastUpdate', () => { ); expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull(); expect(consoleMock).toHaveBeenCalledTimes(1); - expect(consoleMock).toHaveBeenCalledWith( - new Error( - `Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFilePath}`, - ), + expect(consoleMock.mock.calls[0][0].message).toContain( + `Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFilePath}`, ); expect(await getFileLastUpdate(null)).toBeNull(); expect(await getFileLastUpdate(undefined)).toBeNull(); diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index a818ba8054e3..dbc1a5bd04f6 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -119,32 +119,6 @@ export function processDocMetadata({ // ex: myDoc -> . const docsFileDirName = path.dirname(source); - const relativeFilePath = path.relative(docsDirPath, filePath); - - function getDocEditUrl() { - if (typeof options.editUrl === 'function') { - return options.editUrl({ - version: versionMetadata.versionName, - versionDocsDirPath: posixPath( - path.relative(siteDir, versionMetadata.docsDirPath), - ), - docPath: posixPath(relativeFilePath), - locale: context.i18n.currentLocale, - }); - } else if (typeof options.editUrl === 'string') { - const isLocalized = docsDirPath === versionMetadata.docsDirPathLocalized; - const baseVersionEditUrl = - isLocalized && options.editLocalizedFiles - ? versionMetadata.versionEditUrlLocalized - : versionMetadata.versionEditUrl; - return getEditUrl(relativeFilePath, baseVersionEditUrl); - } else { - return undefined; - } - } - - const docsEditUrl = getDocEditUrl(); - const {frontMatter = {}, excerpt} = parseMarkdownString(content); const {sidebar_label, custom_edit_url} = frontMatter; @@ -194,6 +168,31 @@ export function processDocMetadata({ const permalink = normalizeUrl([versionMetadata.versionPath, docSlug]); + function getDocEditUrl() { + const relativeFilePath = path.relative(docsDirPath, filePath); + + if (typeof options.editUrl === 'function') { + return options.editUrl({ + version: versionMetadata.versionName, + versionDocsDirPath: posixPath( + path.relative(siteDir, versionMetadata.docsDirPath), + ), + docPath: posixPath(relativeFilePath), + permalink, + locale: context.i18n.currentLocale, + }); + } else if (typeof options.editUrl === 'string') { + const isLocalized = docsDirPath === versionMetadata.docsDirPathLocalized; + const baseVersionEditUrl = + isLocalized && options.editLocalizedFiles + ? versionMetadata.versionEditUrlLocalized + : versionMetadata.versionEditUrl; + return getEditUrl(relativeFilePath, baseVersionEditUrl); + } else { + return undefined; + } + } + // Assign all of object properties during instantiation (if possible) for // NodeJS optimization. // Adding properties to object after instantiation will cause hidden @@ -207,7 +206,7 @@ export function processDocMetadata({ source: aliasedSitePath(filePath, siteDir), slug: docSlug, permalink, - editUrl: custom_edit_url !== undefined ? custom_edit_url : docsEditUrl, + editUrl: custom_edit_url !== undefined ? custom_edit_url : getDocEditUrl(), version: versionMetadata.versionName, lastUpdatedBy: lastUpdate.lastUpdatedBy, lastUpdatedAt: lastUpdate.lastUpdatedAt, 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 48e5726ddde3..258b9b22c285 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 @@ -106,3 +106,15 @@ declare module '@theme/DocPage' { const DocPage: (props: Props) => JSX.Element; export default DocPage; } + +declare module '@theme/Seo' { + export type Props = { + readonly title?: string; + readonly description?: string; + readonly keywords?: readonly string[] | string; + readonly image?: string; + }; + + const Seo: (props: Props) => JSX.Element; + export default Seo; +} diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index c905a1dc4b1e..be171ee7793f 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -35,6 +35,7 @@ export type EditUrlFunction = (editUrlParams: { version: string; versionDocsDirPath: string; docPath: string; + permalink: string; locale: string; }) => string | undefined; diff --git a/packages/docusaurus-plugin-content-pages/package.json b/packages/docusaurus-plugin-content-pages/package.json index 54e1673d6ab4..a4eeaf7438a1 100644 --- a/packages/docusaurus-plugin-content-pages/package.json +++ b/packages/docusaurus-plugin-content-pages/package.json @@ -24,7 +24,7 @@ "@docusaurus/utils": "2.0.0-alpha.70", "@docusaurus/utils-validation": "2.0.0-alpha.70", "globby": "^11.0.2", - "joi": "^17.2.1", + "joi": "^17.4.0", "loader-utils": "^1.2.3", "lodash": "^4.17.19", "minimatch": "^3.0.4", @@ -33,10 +33,10 @@ "webpack": "^4.44.1" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-plugin-debug/package.json b/packages/docusaurus-plugin-debug/package.json index 5493fe788df1..e875d945b070 100644 --- a/packages/docusaurus-plugin-debug/package.json +++ b/packages/docusaurus-plugin-debug/package.json @@ -20,13 +20,13 @@ "@docusaurus/core": "2.0.0-alpha.70", "@docusaurus/types": "2.0.0-alpha.70", "@docusaurus/utils": "2.0.0-alpha.70", - "react-json-view": "^1.20.4" + "react-json-view": "^1.21.1" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-plugin-google-analytics/package.json b/packages/docusaurus-plugin-google-analytics/package.json index a1484beb9045..6db67d3d7cf4 100644 --- a/packages/docusaurus-plugin-google-analytics/package.json +++ b/packages/docusaurus-plugin-google-analytics/package.json @@ -16,10 +16,10 @@ "@docusaurus/core": "2.0.0-alpha.70" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-plugin-google-gtag/package.json b/packages/docusaurus-plugin-google-gtag/package.json index 7b17f86c4046..5b30a7197948 100644 --- a/packages/docusaurus-plugin-google-gtag/package.json +++ b/packages/docusaurus-plugin-google-gtag/package.json @@ -16,10 +16,10 @@ "@docusaurus/core": "2.0.0-alpha.70" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-plugin-ideal-image/package.json b/packages/docusaurus-plugin-ideal-image/package.json index c88b5d57f3a8..7fc733fb6bdc 100644 --- a/packages/docusaurus-plugin-ideal-image/package.json +++ b/packages/docusaurus-plugin-ideal-image/package.json @@ -30,10 +30,10 @@ "webpack": "^4.44.1" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" }, "engines": { - "node": ">=10.15.1" + "node": ">=12.13.0" } } diff --git a/packages/docusaurus-plugin-pwa/package.json b/packages/docusaurus-plugin-pwa/package.json index a8f6a95f8d02..a4826cc3bc55 100644 --- a/packages/docusaurus-plugin-pwa/package.json +++ b/packages/docusaurus-plugin-pwa/package.json @@ -13,23 +13,23 @@ }, "license": "MIT", "dependencies": { - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1", - "@babel/plugin-proposal-optional-chaining": "^7.12.1", - "@babel/preset-env": "^7.12.1", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13", + "@babel/plugin-proposal-optional-chaining": "^7.12.16", + "@babel/preset-env": "^7.12.16", "@docusaurus/core": "2.0.0-alpha.70", - "babel-loader": "^8.2.1", + "babel-loader": "^8.2.2", "clsx": "^1.1.1", "core-js": "^2.6.5", - "joi": "^17.2.1", + "joi": "^17.4.0", "terser-webpack-plugin": "^4.1.0", "webpack": "^4.44.1", "webpack-merge": "^4.2.2", - "workbox-build": "^6.0.2", - "workbox-precaching": "^6.0.2", - "workbox-window": "^6.0.2" + "workbox-build": "^6.1.0", + "workbox-precaching": "^6.1.0", + "workbox-window": "^6.1.0" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": "^16.8.4 || ^17.0.0", + "react-dom": "^16.8.4 || ^17.0.0" } } diff --git a/packages/docusaurus-plugin-pwa/src/theme/PwaReloadPopup/index.js b/packages/docusaurus-plugin-pwa/src/theme/PwaReloadPopup/index.js index 3324cb87c0d5..0e270892b52d 100644 --- a/packages/docusaurus-plugin-pwa/src/theme/PwaReloadPopup/index.js +++ b/packages/docusaurus-plugin-pwa/src/theme/PwaReloadPopup/index.js @@ -7,6 +7,7 @@ import React, {useState} from 'react'; import clsx from 'clsx'; +import Translate, {translate} from '@docusaurus/Translate'; import styles from './styles.module.css'; @@ -16,7 +17,13 @@ export default function PwaReloadPopup({onReload}) { return ( isVisible && (
-

New version available

+

+ + New version available + +

) : null} diff --git a/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx index ab708bd076a8..5e46342d638e 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogListPaginator/index.tsx @@ -7,7 +7,7 @@ import React from 'react'; import Link from '@docusaurus/Link'; -import Translate from '@docusaurus/Translate'; +import Translate, {translate} from '@docusaurus/Translate'; import type {Metadata} from '@theme/BlogListPage'; function BlogListPaginator(props: {readonly metadata: Metadata}): JSX.Element { @@ -15,14 +15,20 @@ function BlogListPaginator(props: {readonly metadata: Metadata}): JSX.Element { const {previousPage, nextPage} = metadata; return ( -