From 6a3efd5f3de1c3f6eddf803543ee111899c56927 Mon Sep 17 00:00:00 2001 From: Endi Date: Mon, 11 Nov 2019 21:24:04 +0700 Subject: [PATCH] breaking(v2): editUrl should point to website instead of docsDir to support editUrl in versioning/trans (#1958) --- .../src/__tests__/metadata.test.ts | 2 +- packages/docusaurus-plugin-content-docs/src/metadata.ts | 7 +++++-- website/docs/advanced-plugins.md | 4 ++-- website/docs/migrating-from-v1-to-v2.md | 6 ++++-- website/docusaurus.config.js | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts index 1caaab4a17cf..b67bdccf5a9b 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -80,7 +80,7 @@ describe('processMetadata', () => { test('docs with editUrl', async () => { const editUrl = - 'https://github.com/facebook/docusaurus/edit/master/website/docs/'; + 'https://github.com/facebook/docusaurus/edit/master/website'; const source = path.join('foo', 'baz.md'); const data = await processMetadata({ source, diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index 70287ab9d423..654f97b25716 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -7,7 +7,7 @@ import fs from 'fs-extra'; import path from 'path'; -import {parse, normalizeUrl} from '@docusaurus/utils'; +import {parse, normalizeUrl, posixPath} from '@docusaurus/utils'; import {DocusaurusConfig} from '@docusaurus/types'; import lastUpdate from './lastUpdate'; @@ -100,7 +100,10 @@ export default async function processMetadata({ } if (editUrl) { - metadata.editUrl = normalizeUrl([editUrl, source]); + metadata.editUrl = normalizeUrl([ + editUrl, + posixPath(path.relative(siteDir, filePath)), + ]); } if (metadata.custom_edit_url) { diff --git a/website/docs/advanced-plugins.md b/website/docs/advanced-plugins.md index ebfbba43d089..885c15f08af6 100644 --- a/website/docs/advanced-plugins.md +++ b/website/docs/advanced-plugins.md @@ -131,9 +131,9 @@ module.exports = { */ path: 'docs', /** - * URL for editing docs, example: 'https://github.com/facebook/docusaurus/edit/master/website/docs/' + * URL for editing website repo, example: 'https://github.com/facebook/docusaurus/edit/master/website/' */ - editUrl: 'https://github.com/repo/project/website/docs/', + editUrl: 'https://github.com/repo/project/website/', /** * URL route for the blog section of your site * do not include trailing slash diff --git a/website/docs/migrating-from-v1-to-v2.md b/website/docs/migrating-from-v1-to-v2.md index 4c08143036f8..dc9cc6f035da 100644 --- a/website/docs/migrating-from-v1-to-v2.md +++ b/website/docs/migrating-from-v1-to-v2.md @@ -274,6 +274,8 @@ Deprecated. Create a `CNAME` file in your `static` folder instead with your cust #### `customDocsPath`, `docsUrl`, `editUrl`, `enableUpdateBy`, `enableUpdateTime` +**BREAKING**: `editUrl` should point to (website) docusaurus project instead of `docs` directory. + Deprecated. Pass it as an option to `@docusaurus/preset-classic` docs instead: ```jsx {9-22} @@ -287,9 +289,9 @@ module.exports = { docs: { // Equivalent to `customDocsPath`. path: 'docs', - // Equivalent to `editUrl` + // Equivalent to `editUrl` but should point to `website` dir instead of `website/docs` editUrl: - 'https://github.com/facebook/docusaurus/edit/master/website/docs/', + 'https://github.com/facebook/docusaurus/edit/master/website', // Equivalent to `docsUrl`. routeBasePath: 'docs', // Remark and Rehype plugins passed to MDX. Replaces `markdownOptions` and `markdownPlugins`. diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index c10dbd541009..890fd5098565 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -33,7 +33,7 @@ module.exports = { path: 'docs', sidebarPath: require.resolve('./sidebars.js'), editUrl: - 'https://github.com/facebook/docusaurus/edit/master/website/docs/', + 'https://github.com/facebook/docusaurus/edit/master/website/', showLastUpdateAuthor: true, showLastUpdateTime: true, },