From 19301c9d43bdbf834e87a71e161b18faad44cec5 Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Wed, 10 Jun 2020 11:47:42 +0530 Subject: [PATCH 01/21] feat(v2): add metadata to indicate the document is old --- packages/docusaurus-plugin-content-docs/src/metadata.ts | 4 ++++ packages/docusaurus-plugin-content-docs/src/types.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index 66225d8918aa..8bea038c5a84 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -87,6 +87,9 @@ export default async function processMetadata({ const versionPath = version && version !== versioning.latestVersion ? version : ''; + const isOld = + version && version !== 'next' ? version !== versioning.latestVersion : true; + const relativePath = path.relative(siteDir, filePath); const docsEditUrl = getEditUrl(relativePath, editUrl); @@ -145,6 +148,7 @@ export default async function processMetadata({ lastUpdatedBy, lastUpdatedAt, sidebar_label, + isOld, }; return metadata; diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index d9c4608bbdeb..d2793f3662c9 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -118,6 +118,7 @@ export interface MetadataRaw extends LastUpdateData { sidebar_label?: string; editUrl?: string; version?: string; + isOld?: boolean; } export interface Paginator { From fb3e311318b136baed65f56e0ea9d761508e1cd8 Mon Sep 17 00:00:00 2001 From: teikjun Date: Wed, 10 Jun 2020 15:18:30 +0800 Subject: [PATCH 02/21] feat(v2): add badge that links old versions to latest version --- .../docusaurus-theme-classic/src/theme/DocItem/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 8d0c4c880f84..923e0f2bd9dd 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -68,6 +68,7 @@ function DocItem(props) { lastUpdatedAt, lastUpdatedBy, version, + isOld, } = metadata; const { frontMatter: { @@ -115,7 +116,12 @@ function DocItem(props) { Version: {version} - + {isOld ? ( + + Go to latest version + + ) : null} + )} {!hideTitle && (
From 4358f793ed4e35cb978739fd6af3b6fee8941414 Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Wed, 10 Jun 2020 13:22:27 +0530 Subject: [PATCH 03/21] feat(v2): fix test related to metadata --- .../src/__tests__/index.test.ts | 6 ++++++ .../src/__tests__/metadata.test.ts | 12 ++++++++++++ .../docusaurus-plugin-content-docs/src/metadata.ts | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index 11b6fb649946..eb13facdd559 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -163,6 +163,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'hello.md'), title: 'Hello, World !', description: 'Hi, Endilie here :)', + isOld:false }); expect(docsMetadata['foo/bar']).toEqual({ @@ -176,6 +177,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'foo', 'bar.md'), title: 'Bar', description: 'This is custom description', + isOld:false }); expect(docsSidebars).toMatchSnapshot(); @@ -304,6 +306,7 @@ describe('versioned website', () => { title: 'hello', permalink: '/docs/next/hello', }, + isOld:false }); expect(docsMetadata['hello']).toEqual({ id: 'hello', @@ -317,6 +320,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/next/foo/barSlug', }, + isOld:false }); expect(docsMetadata['version-1.0.1/hello']).toEqual({ id: 'version-1.0.1/hello', @@ -335,6 +339,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/foo/bar', }, + isOld:false }); expect(docsMetadata['version-1.0.0/foo/baz']).toEqual({ id: 'version-1.0.0/foo/baz', @@ -359,6 +364,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/1.0.0/foo/barSlug', }, + isOld:true }); expect(docsSidebars).toMatchSnapshot('all sidebars'); 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 d54dbd8f33a0..05bea80ff60e 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -50,6 +50,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceA), title: 'Bar', description: 'This is custom description', + isOld:false }); expect(dataB).toEqual({ id: 'hello', @@ -57,6 +58,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceB), title: 'Hello, World !', description: `Hi, Endilie here :)`, + isOld:false }); }); @@ -85,6 +87,7 @@ describe('simple site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md', description: 'Images', + isOld:false }); }); @@ -109,6 +112,7 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', + isOld:false }); // unrelated frontmatter is not part of metadata @@ -140,6 +144,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', + isOld:false }); }); @@ -168,6 +173,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', + isOld:false }); }); @@ -249,6 +255,7 @@ describe('versioned site', () => { title: 'bar', description: 'This is next version of bar.', version: 'next', + isOld:false }); expect(dataB).toEqual({ id: 'hello', @@ -257,6 +264,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello next !', version: 'next', + isOld:false }); }); @@ -307,6 +315,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.0 !', version: '1.0.0', + isOld:true }); expect(dataB).toEqual({ id: 'version-1.0.0/hello', @@ -315,6 +324,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.0 !', version: '1.0.0', + isOld:true }); expect(dataC).toEqual({ id: 'version-1.0.1/foo/bar', @@ -323,6 +333,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.1 !', version: '1.0.1', + isOld:false }); expect(dataD).toEqual({ id: 'version-1.0.1/hello', @@ -331,6 +342,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.1 !', version: '1.0.1', + isOld:false }); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index 8bea038c5a84..d4837a73cf11 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -88,7 +88,7 @@ export default async function processMetadata({ version && version !== versioning.latestVersion ? version : ''; const isOld = - version && version !== 'next' ? version !== versioning.latestVersion : true; + version && version !== 'next' ? version !== versioning.latestVersion : false; const relativePath = path.relative(siteDir, filePath); From 8aef76d04a4b892944077b4c57a5328b4b61303c Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Wed, 10 Jun 2020 13:27:21 +0530 Subject: [PATCH 04/21] feat(v2): fix formatting --- .../src/__tests__/index.test.ts | 12 +++++----- .../src/__tests__/metadata.test.ts | 24 +++++++++---------- .../src/metadata.ts | 4 +++- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index eb13facdd559..df767489c174 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -163,7 +163,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'hello.md'), title: 'Hello, World !', description: 'Hi, Endilie here :)', - isOld:false + isOld: false, }); expect(docsMetadata['foo/bar']).toEqual({ @@ -177,7 +177,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'foo', 'bar.md'), title: 'Bar', description: 'This is custom description', - isOld:false + isOld: false, }); expect(docsSidebars).toMatchSnapshot(); @@ -306,7 +306,7 @@ describe('versioned website', () => { title: 'hello', permalink: '/docs/next/hello', }, - isOld:false + isOld: false, }); expect(docsMetadata['hello']).toEqual({ id: 'hello', @@ -320,7 +320,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/next/foo/barSlug', }, - isOld:false + isOld: false, }); expect(docsMetadata['version-1.0.1/hello']).toEqual({ id: 'version-1.0.1/hello', @@ -339,7 +339,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/foo/bar', }, - isOld:false + isOld: false, }); expect(docsMetadata['version-1.0.0/foo/baz']).toEqual({ id: 'version-1.0.0/foo/baz', @@ -364,7 +364,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/1.0.0/foo/barSlug', }, - isOld:true + isOld: true, }); expect(docsSidebars).toMatchSnapshot('all sidebars'); 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 05bea80ff60e..d97ecbf57eee 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -50,7 +50,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceA), title: 'Bar', description: 'This is custom description', - isOld:false + isOld: false, }); expect(dataB).toEqual({ id: 'hello', @@ -58,7 +58,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceB), title: 'Hello, World !', description: `Hi, Endilie here :)`, - isOld:false + isOld: false, }); }); @@ -87,7 +87,7 @@ describe('simple site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md', description: 'Images', - isOld:false + isOld: false, }); }); @@ -112,7 +112,7 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', - isOld:false + isOld: false, }); // unrelated frontmatter is not part of metadata @@ -144,7 +144,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - isOld:false + isOld: false, }); }); @@ -173,7 +173,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - isOld:false + isOld: false, }); }); @@ -255,7 +255,7 @@ describe('versioned site', () => { title: 'bar', description: 'This is next version of bar.', version: 'next', - isOld:false + isOld: false, }); expect(dataB).toEqual({ id: 'hello', @@ -264,7 +264,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello next !', version: 'next', - isOld:false + isOld: false, }); }); @@ -315,7 +315,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.0 !', version: '1.0.0', - isOld:true + isOld: true, }); expect(dataB).toEqual({ id: 'version-1.0.0/hello', @@ -324,7 +324,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.0 !', version: '1.0.0', - isOld:true + isOld: true, }); expect(dataC).toEqual({ id: 'version-1.0.1/foo/bar', @@ -333,7 +333,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.1 !', version: '1.0.1', - isOld:false + isOld: false, }); expect(dataD).toEqual({ id: 'version-1.0.1/hello', @@ -342,7 +342,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.1 !', version: '1.0.1', - isOld:false + isOld: false, }); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index d4837a73cf11..e6321c503938 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -88,7 +88,9 @@ export default async function processMetadata({ version && version !== versioning.latestVersion ? version : ''; const isOld = - version && version !== 'next' ? version !== versioning.latestVersion : false; + version && version !== 'next' + ? version !== versioning.latestVersion + : false; const relativePath = path.relative(siteDir, filePath); From 1629d9246d6e331373102574e1f409e893876b0d Mon Sep 17 00:00:00 2001 From: teikjun Date: Wed, 10 Jun 2020 16:29:06 +0800 Subject: [PATCH 05/21] feat(v2): fix formatting --- packages/docusaurus-theme-classic/src/theme/DocItem/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 923e0f2bd9dd..04a136fbad09 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -121,7 +121,7 @@ function DocItem(props) { Go to latest version ) : null} - + )} {!hideTitle && (
From 3239dffbdbe1343343db4f704aa26c9435add30c Mon Sep 17 00:00:00 2001 From: teikjun Date: Wed, 10 Jun 2020 17:32:47 +0800 Subject: [PATCH 06/21] feat(v2): use Link component instead of anchor tag --- packages/docusaurus-theme-classic/src/theme/DocItem/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 04a136fbad09..5251b73426b5 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -12,6 +12,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; import DocPaginator from '@theme/DocPaginator'; import useTOCHighlight from '@theme/hooks/useTOCHighlight'; +import Link from '@docusaurus/Link'; import clsx from 'clsx'; import styles from './styles.module.css'; @@ -118,7 +119,7 @@ function DocItem(props) { {isOld ? ( - Go to latest version + Go to latest version ) : null} From 79164689640a641868fe010c7d83ca128ecdc9d9 Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Wed, 10 Jun 2020 17:11:27 +0530 Subject: [PATCH 07/21] feat(v2): add pramlink to latest docs --- packages/docusaurus-plugin-content-docs/src/index.ts | 6 ++++++ .../docusaurus-plugin-content-docs/src/metadata.ts | 12 ++++++------ packages/docusaurus-plugin-content-docs/src/types.ts | 2 +- .../src/theme/DocItem/index.js | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 4459e295e573..8a19b5a71ece 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -384,6 +384,12 @@ Available document ids= homePageDocsRoutePath, versionDocsPathPrefix, ]); + if (metadataItem.latestPermalink) { + metadataItem.latestPermalink = normalizeUrl([ + baseUrl, + homePageDocsRoutePath, + ]); + } const docsBaseMetadataPath = await createData( `${docuHash(metadataItem.source)}-base.json`, JSON.stringify(docsBaseMetadata, null, 2), diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index e6321c503938..b118f5faeda4 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -87,11 +87,6 @@ export default async function processMetadata({ const versionPath = version && version !== versioning.latestVersion ? version : ''; - const isOld = - version && version !== 'next' - ? version !== versioning.latestVersion - : false; - const relativePath = path.relative(siteDir, filePath); const docsEditUrl = getEditUrl(relativePath, editUrl); @@ -133,6 +128,11 @@ export default async function processMetadata({ routePath, ]); + const latestPermalink = + version && version !== versioning.latestVersion + ? normalizeUrl([baseUrl, routeBasePath, routePath]) + : undefined; + const {lastUpdatedAt, lastUpdatedBy} = await lastUpdatedPromise; // Assign all of object properties during instantiation (if possible) for @@ -150,7 +150,7 @@ export default async function processMetadata({ lastUpdatedBy, lastUpdatedAt, sidebar_label, - isOld, + latestPermalink, }; return metadata; diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index d2793f3662c9..42ef28946c75 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -118,7 +118,7 @@ export interface MetadataRaw extends LastUpdateData { sidebar_label?: string; editUrl?: string; version?: string; - isOld?: boolean; + latestPermalink?: string; } export interface Paginator { diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 5251b73426b5..94dc05928ece 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -69,7 +69,7 @@ function DocItem(props) { lastUpdatedAt, lastUpdatedBy, version, - isOld, + latestPermalink } = metadata; const { frontMatter: { @@ -117,9 +117,9 @@ function DocItem(props) { Version: {version} - {isOld ? ( + {latestPermalink ? ( - Go to latest version + Go to latest version ) : null} From 2e89fde0f586955ae6f5d1ed43caa49cb6ae0613 Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Wed, 10 Jun 2020 17:28:51 +0530 Subject: [PATCH 08/21] feat(v2): add more vibrant warning message --- .../src/theme/DocItem/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 94dc05928ece..9670da6f0f03 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -69,7 +69,7 @@ function DocItem(props) { lastUpdatedAt, lastUpdatedBy, version, - latestPermalink + latestPermalink, } = metadata; const { frontMatter: { @@ -105,6 +105,16 @@ function DocItem(props) {
+ {latestPermalink && ( + + )}
Version: {version} - {latestPermalink ? ( - - Go to latest version - - ) : null}
)} {!hideTitle && ( From c4b1159a32d019e2c2809572f4e027f7b5a5ba4f Mon Sep 17 00:00:00 2001 From: teikjun Date: Wed, 10 Jun 2020 20:47:08 +0800 Subject: [PATCH 09/21] feat(v2): position the banner above the article --- .../src/theme/DocItem/index.js | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 9670da6f0f03..b33ec22cbe02 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -105,21 +105,28 @@ function DocItem(props) {
- {latestPermalink && ( - - )}
+ {latestPermalink && ( +
+
+ This is archived documentation for Docusaurus{' '} + {version}, which is no longer actively + maintained. +
+
+ For up-to-date documentation, see the{' '} + + latest version. + +
+
+ )}
{version && ( From 85ea598818f73a53a42ffe69d91015c522196752 Mon Sep 17 00:00:00 2001 From: teikjun Date: Thu, 11 Jun 2020 17:05:35 +0800 Subject: [PATCH 10/21] feat(v2): link latest version to intro page --- .../src/index.ts | 7 +------ .../src/metadata.ts | 2 +- .../src/theme/DocItem/index.js | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 8a19b5a71ece..a16300bc1e26 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -384,12 +384,7 @@ Available document ids= homePageDocsRoutePath, versionDocsPathPrefix, ]); - if (metadataItem.latestPermalink) { - metadataItem.latestPermalink = normalizeUrl([ - baseUrl, - homePageDocsRoutePath, - ]); - } + const docsBaseMetadataPath = await createData( `${docuHash(metadataItem.source)}-base.json`, JSON.stringify(docsBaseMetadata, null, 2), diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index b118f5faeda4..4da1a8bda12b 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -130,7 +130,7 @@ export default async function processMetadata({ const latestPermalink = version && version !== versioning.latestVersion - ? normalizeUrl([baseUrl, routeBasePath, routePath]) + ? normalizeUrl([baseUrl, routeBasePath]) : undefined; const {lastUpdatedAt, lastUpdatedBy} = await lastUpdatedPromise; diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index b33ec22cbe02..ea360d22db1b 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -114,12 +114,19 @@ function DocItem(props) {
-
- This is archived documentation for Docusaurus{' '} - {version}, which is no longer actively - maintained. -
-
+ {version === 'next' ? ( +
+ This is unreleased documentation for {siteTitle}{' '} + {version} version. +
+ ) : ( +
+ This is archived documentation for {siteTitle}{' '} + v{version}, which is no longer actively + maintained. +
+ )} +
For up-to-date documentation, see the{' '} latest version. From 2d70251a73fa6acc83b4b76c08a7923cca662d5f Mon Sep 17 00:00:00 2001 From: teikjun Date: Thu, 11 Jun 2020 17:20:43 +0800 Subject: [PATCH 11/21] fix(v2): fix some test cases --- .../src/__tests__/index.test.ts | 12 +++++----- .../src/__tests__/metadata.test.ts | 24 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index df767489c174..3c751b2f32b0 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -163,7 +163,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'hello.md'), title: 'Hello, World !', description: 'Hi, Endilie here :)', - isOld: false, + latestPermaLink: undefined, }); expect(docsMetadata['foo/bar']).toEqual({ @@ -177,7 +177,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'foo', 'bar.md'), title: 'Bar', description: 'This is custom description', - isOld: false, + latestPermaLink: undefined, }); expect(docsSidebars).toMatchSnapshot(); @@ -306,7 +306,7 @@ describe('versioned website', () => { title: 'hello', permalink: '/docs/next/hello', }, - isOld: false, + latestPermaLink: undefined, }); expect(docsMetadata['hello']).toEqual({ id: 'hello', @@ -320,7 +320,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/next/foo/barSlug', }, - isOld: false, + latestPermaLink: undefined, }); expect(docsMetadata['version-1.0.1/hello']).toEqual({ id: 'version-1.0.1/hello', @@ -339,7 +339,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/foo/bar', }, - isOld: false, + latestPermaLink: undefined, }); expect(docsMetadata['version-1.0.0/foo/baz']).toEqual({ id: 'version-1.0.0/foo/baz', @@ -364,7 +364,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/1.0.0/foo/barSlug', }, - isOld: true, + latestPermaLink: '@site/docs', }); expect(docsSidebars).toMatchSnapshot('all sidebars'); 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 d97ecbf57eee..baaf74eb1b57 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -50,7 +50,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceA), title: 'Bar', description: 'This is custom description', - isOld: false, + latestPermaLink: undefined, }); expect(dataB).toEqual({ id: 'hello', @@ -58,7 +58,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceB), title: 'Hello, World !', description: `Hi, Endilie here :)`, - isOld: false, + latestPermaLink: undefined, }); }); @@ -87,7 +87,7 @@ describe('simple site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md', description: 'Images', - isOld: false, + latestPermaLink: undefined, }); }); @@ -112,7 +112,7 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', - isOld: false, + latestPermaLink: undefined, }); // unrelated frontmatter is not part of metadata @@ -144,7 +144,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - isOld: false, + latestPermaLink: undefined, }); }); @@ -173,7 +173,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - isOld: false, + latestPermaLink: undefined, }); }); @@ -255,7 +255,7 @@ describe('versioned site', () => { title: 'bar', description: 'This is next version of bar.', version: 'next', - isOld: false, + latestPermaLink: undefined, }); expect(dataB).toEqual({ id: 'hello', @@ -264,7 +264,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello next !', version: 'next', - isOld: false, + latestPermaLink: undefined, }); }); @@ -315,7 +315,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.0 !', version: '1.0.0', - isOld: true, + latestPermaLink: '@site/docs', }); expect(dataB).toEqual({ id: 'version-1.0.0/hello', @@ -324,7 +324,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.0 !', version: '1.0.0', - isOld: true, + latestPermaLink: '@site/docs', }); expect(dataC).toEqual({ id: 'version-1.0.1/foo/bar', @@ -333,7 +333,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.1 !', version: '1.0.1', - isOld: false, + latestPermaLink: undefined, }); expect(dataD).toEqual({ id: 'version-1.0.1/hello', @@ -342,7 +342,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.1 !', version: '1.0.1', - isOld: false, + latestPermaLink: undefined, }); }); }); From 20b222fcf5cd082ce7c06684f1dca81cd661ee4c Mon Sep 17 00:00:00 2001 From: Anshul Goyal Date: Thu, 11 Jun 2020 15:14:23 +0530 Subject: [PATCH 12/21] feat(v2): fix tests --- .../src/__tests__/index.test.ts | 12 +++++----- .../src/__tests__/metadata.test.ts | 24 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index 3c751b2f32b0..f88fdfaf2f33 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -163,7 +163,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'hello.md'), title: 'Hello, World !', description: 'Hi, Endilie here :)', - latestPermaLink: undefined, + latestPermalink: undefined, }); expect(docsMetadata['foo/bar']).toEqual({ @@ -177,7 +177,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'foo', 'bar.md'), title: 'Bar', description: 'This is custom description', - latestPermaLink: undefined, + latestPermalink: undefined, }); expect(docsSidebars).toMatchSnapshot(); @@ -306,7 +306,7 @@ describe('versioned website', () => { title: 'hello', permalink: '/docs/next/hello', }, - latestPermaLink: undefined, + latestPermalink: '/docs', }); expect(docsMetadata['hello']).toEqual({ id: 'hello', @@ -320,7 +320,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/next/foo/barSlug', }, - latestPermaLink: undefined, + latestPermalink: '/docs', }); expect(docsMetadata['version-1.0.1/hello']).toEqual({ id: 'version-1.0.1/hello', @@ -339,7 +339,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/foo/bar', }, - latestPermaLink: undefined, + latestPermalink: undefined, }); expect(docsMetadata['version-1.0.0/foo/baz']).toEqual({ id: 'version-1.0.0/foo/baz', @@ -364,7 +364,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/1.0.0/foo/barSlug', }, - latestPermaLink: '@site/docs', + latestPermalink: '/docs', }); expect(docsSidebars).toMatchSnapshot('all sidebars'); 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 baaf74eb1b57..e92ec62a7603 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -50,7 +50,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceA), title: 'Bar', description: 'This is custom description', - latestPermaLink: undefined, + latestPermalink: undefined, }); expect(dataB).toEqual({ id: 'hello', @@ -58,7 +58,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceB), title: 'Hello, World !', description: `Hi, Endilie here :)`, - latestPermaLink: undefined, + latestPermalink: undefined, }); }); @@ -87,7 +87,7 @@ describe('simple site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md', description: 'Images', - latestPermaLink: undefined, + latestPermalink: undefined, }); }); @@ -112,7 +112,7 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', - latestPermaLink: undefined, + latestPermalink: undefined, }); // unrelated frontmatter is not part of metadata @@ -144,7 +144,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - latestPermaLink: undefined, + latestPermalink: undefined, }); }); @@ -173,7 +173,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - latestPermaLink: undefined, + latestPermalink: undefined, }); }); @@ -255,7 +255,7 @@ describe('versioned site', () => { title: 'bar', description: 'This is next version of bar.', version: 'next', - latestPermaLink: undefined, + latestPermalink: '/docs', }); expect(dataB).toEqual({ id: 'hello', @@ -264,7 +264,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello next !', version: 'next', - latestPermaLink: undefined, + latestPermalink: '/docs', }); }); @@ -315,7 +315,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.0 !', version: '1.0.0', - latestPermaLink: '@site/docs', + latestPermalink: '/docs', }); expect(dataB).toEqual({ id: 'version-1.0.0/hello', @@ -324,7 +324,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.0 !', version: '1.0.0', - latestPermaLink: '@site/docs', + latestPermalink: '/docs', }); expect(dataC).toEqual({ id: 'version-1.0.1/foo/bar', @@ -333,7 +333,7 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.1 !', version: '1.0.1', - latestPermaLink: undefined, + latestPermalink: undefined, }); expect(dataD).toEqual({ id: 'version-1.0.1/hello', @@ -342,7 +342,7 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.1 !', version: '1.0.1', - latestPermaLink: undefined, + latestPermalink: undefined, }); }); }); From f4a2fcdbf9f26b2cfbc0ad4d4a0870415b74acc0 Mon Sep 17 00:00:00 2001 From: teikjun Date: Thu, 11 Jun 2020 18:42:53 +0800 Subject: [PATCH 13/21] feat(v2): change banner to warning orange --- packages/docusaurus-theme-classic/src/theme/DocItem/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index ea360d22db1b..b856e8048925 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -112,7 +112,7 @@ function DocItem(props) { })}> {latestPermalink && (
{version === 'next' ? (
From 32b7b0764e217167ac457026e55766721933fc2f Mon Sep 17 00:00:00 2001 From: anshul Date: Thu, 11 Jun 2020 20:21:50 +0530 Subject: [PATCH 14/21] feat(v2): compute root route from sidebar --- .../src/__tests__/index.test.ts | 4 +--- .../src/__tests__/metadata.test.ts | 6 ----- .../src/index.ts | 24 +++++++++++++++++-- .../src/metadata.ts | 6 ----- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index f88fdfaf2f33..a327b6c12a98 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -306,7 +306,7 @@ describe('versioned website', () => { title: 'hello', permalink: '/docs/next/hello', }, - latestPermalink: '/docs', + }); expect(docsMetadata['hello']).toEqual({ id: 'hello', @@ -320,7 +320,6 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/next/foo/barSlug', }, - latestPermalink: '/docs', }); expect(docsMetadata['version-1.0.1/hello']).toEqual({ id: 'version-1.0.1/hello', @@ -364,7 +363,6 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/1.0.0/foo/barSlug', }, - latestPermalink: '/docs', }); expect(docsSidebars).toMatchSnapshot('all sidebars'); 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 e92ec62a7603..0e5b7e94c4a8 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -255,7 +255,6 @@ describe('versioned site', () => { title: 'bar', description: 'This is next version of bar.', version: 'next', - latestPermalink: '/docs', }); expect(dataB).toEqual({ id: 'hello', @@ -264,7 +263,6 @@ describe('versioned site', () => { title: 'hello', description: 'Hello next !', version: 'next', - latestPermalink: '/docs', }); }); @@ -315,7 +313,6 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.0 !', version: '1.0.0', - latestPermalink: '/docs', }); expect(dataB).toEqual({ id: 'version-1.0.0/hello', @@ -324,7 +321,6 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.0 !', version: '1.0.0', - latestPermalink: '/docs', }); expect(dataC).toEqual({ id: 'version-1.0.1/foo/bar', @@ -333,7 +329,6 @@ describe('versioned site', () => { title: 'bar', description: 'Bar 1.0.1 !', version: '1.0.1', - latestPermalink: undefined, }); expect(dataD).toEqual({ id: 'version-1.0.1/hello', @@ -342,7 +337,6 @@ describe('versioned site', () => { title: 'hello', description: 'Hello 1.0.1 !', version: '1.0.1', - latestPermalink: undefined, }); }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index a16300bc1e26..c6f40c318894 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -65,6 +65,18 @@ const DEFAULT_OPTIONS: PluginOptions = { admonitions: {}, }; +function getHrefFromSideBar(sidebarItems: DocsSidebarItem[]): string | null { + for (let sidebarItem of sidebarItems) { + if (sidebarItem.type === 'category') { + const url = getHrefFromSideBar(sidebarItem.items); + if (url) return url; + } else { + return sidebarItem.href; + } + } + return null; +} + export default function pluginContentDocs( context: LoadContext, opts: Partial, @@ -320,7 +332,6 @@ Available document ids= }, {}, ); - return { docsMetadata, docsDir, @@ -368,7 +379,6 @@ Available document ids= const isDocsHomePage = metadataItem.id.replace(versionsRegex, '').replace(/^\//, '') === options.homePageId; - if (isDocsHomePage) { const versionDocsPathPrefix = (metadataItem?.version === versioning.latestVersion @@ -462,6 +472,16 @@ Available document ids= Object.values(content.docsMetadata), 'version', ); + const rootUrl = getHrefFromSideBar( + content.docsSidebars[`version-${versioning.latestVersion}/docs`], + ); + if (!rootUrl) { + throw new Error('Bad sidebars file. No document linked'); + } + Object.values(content.docsMetadata).forEach((docMetadata) => { + if (docMetadata.version !== versioning.latestVersion) + docMetadata.latestPermalink = rootUrl; + }); await Promise.all( Object.keys(docsMetadataByVersion).map(async (version) => { const routes: RouteConfig[] = await genRoutes( diff --git a/packages/docusaurus-plugin-content-docs/src/metadata.ts b/packages/docusaurus-plugin-content-docs/src/metadata.ts index 4da1a8bda12b..66225d8918aa 100644 --- a/packages/docusaurus-plugin-content-docs/src/metadata.ts +++ b/packages/docusaurus-plugin-content-docs/src/metadata.ts @@ -128,11 +128,6 @@ export default async function processMetadata({ routePath, ]); - const latestPermalink = - version && version !== versioning.latestVersion - ? normalizeUrl([baseUrl, routeBasePath]) - : undefined; - const {lastUpdatedAt, lastUpdatedBy} = await lastUpdatedPromise; // Assign all of object properties during instantiation (if possible) for @@ -150,7 +145,6 @@ export default async function processMetadata({ lastUpdatedBy, lastUpdatedAt, sidebar_label, - latestPermalink, }; return metadata; From 711dba8b6c0088606abb40d1183f47c5bb9ad22b Mon Sep 17 00:00:00 2001 From: teikjun Date: Fri, 12 Jun 2020 00:44:19 +0800 Subject: [PATCH 15/21] style(v2): fix formatting --- .../docusaurus-plugin-content-docs/src/__tests__/index.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index a327b6c12a98..9fcc117bb301 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -306,7 +306,6 @@ describe('versioned website', () => { title: 'hello', permalink: '/docs/next/hello', }, - }); expect(docsMetadata['hello']).toEqual({ id: 'hello', From d0f1ff3eb1ff108f3b0a62a0c3f557dcfb023af3 Mon Sep 17 00:00:00 2001 From: anshul Date: Fri, 12 Jun 2020 21:22:43 +0530 Subject: [PATCH 16/21] feat(v2): use homeid if provided to compute base route --- packages/docusaurus-plugin-content-docs/src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index c6f40c318894..f767a738a236 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -472,9 +472,11 @@ Available document ids= Object.values(content.docsMetadata), 'version', ); - const rootUrl = getHrefFromSideBar( - content.docsSidebars[`version-${versioning.latestVersion}/docs`], - ); + const rootUrl = options.homePageId + ? normalizeUrl([baseUrl, homePageDocsRoutePath]) + : getHrefFromSideBar( + content.docsSidebars[`version-${versioning.latestVersion}/docs`], + ); if (!rootUrl) { throw new Error('Bad sidebars file. No document linked'); } From 17c7e3a45e69df6d63fc354fe0a668cf93debf20 Mon Sep 17 00:00:00 2001 From: anshul Date: Fri, 12 Jun 2020 22:35:38 +0530 Subject: [PATCH 17/21] feat(v2): rename functions and fix a corner case --- .../src/__tests__/index.test.ts | 6 +++--- .../src/__tests__/metadata.test.ts | 12 ++++++------ .../src/index.ts | 19 +++++++++++-------- .../src/types.ts | 2 +- .../src/theme/DocItem/index.js | 6 +++--- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index 9fcc117bb301..2daea9fe1272 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -163,7 +163,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'hello.md'), title: 'Hello, World !', description: 'Hi, Endilie here :)', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); expect(docsMetadata['foo/bar']).toEqual({ @@ -177,7 +177,7 @@ describe('simple website', () => { source: path.join('@site', pluginPath, 'foo', 'bar.md'), title: 'Bar', description: 'This is custom description', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); expect(docsSidebars).toMatchSnapshot(); @@ -337,7 +337,7 @@ describe('versioned website', () => { title: 'bar', permalink: '/docs/foo/bar', }, - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); expect(docsMetadata['version-1.0.0/foo/baz']).toEqual({ id: 'version-1.0.0/foo/baz', 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 0e5b7e94c4a8..17759bff68ab 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/metadata.test.ts @@ -50,7 +50,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceA), title: 'Bar', description: 'This is custom description', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); expect(dataB).toEqual({ id: 'hello', @@ -58,7 +58,7 @@ describe('simple site', () => { source: path.join('@site', routeBasePath, sourceB), title: 'Hello, World !', description: `Hi, Endilie here :)`, - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); }); @@ -87,7 +87,7 @@ describe('simple site', () => { editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/docs/foo/baz.md', description: 'Images', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); }); @@ -112,7 +112,7 @@ describe('simple site', () => { title: 'lorem', editUrl: 'https://github.com/customUrl/docs/lorem.md', description: 'Lorem ipsum.', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); // unrelated frontmatter is not part of metadata @@ -144,7 +144,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); }); @@ -173,7 +173,7 @@ describe('simple site', () => { description: 'Lorem ipsum.', lastUpdatedAt: 1539502055, lastUpdatedBy: 'Author', - latestPermalink: undefined, + latestVersionMainDocPermalink: undefined, }); }); diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index f767a738a236..c0843fb3b067 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -65,10 +65,10 @@ const DEFAULT_OPTIONS: PluginOptions = { admonitions: {}, }; -function getHrefFromSideBar(sidebarItems: DocsSidebarItem[]): string | null { +function getFirstDocLinkOfSidebar(sidebarItems: DocsSidebarItem[]): string | null { for (let sidebarItem of sidebarItems) { if (sidebarItem.type === 'category') { - const url = getHrefFromSideBar(sidebarItem.items); + const url = getFirstDocLinkOfSidebar(sidebarItem.items); if (url) return url; } else { return sidebarItem.href; @@ -472,17 +472,20 @@ Available document ids= Object.values(content.docsMetadata), 'version', ); - const rootUrl = options.homePageId - ? normalizeUrl([baseUrl, homePageDocsRoutePath]) - : getHrefFromSideBar( - content.docsSidebars[`version-${versioning.latestVersion}/docs`], - ); + const rootUrl = + options.homePageId && content.docsMetadata[options.homePageId] + ? content.docsMetadata[options.homePageId].permalink + : getFirstDocLinkOfSidebar( + content.docsSidebars[ + `version-${versioning.latestVersion}/docs` + ], + ); if (!rootUrl) { throw new Error('Bad sidebars file. No document linked'); } Object.values(content.docsMetadata).forEach((docMetadata) => { if (docMetadata.version !== versioning.latestVersion) - docMetadata.latestPermalink = rootUrl; + docMetadata.latestVersionMainDocPermalink = rootUrl; }); await Promise.all( Object.keys(docsMetadataByVersion).map(async (version) => { diff --git a/packages/docusaurus-plugin-content-docs/src/types.ts b/packages/docusaurus-plugin-content-docs/src/types.ts index 42ef28946c75..2b7b8b89a295 100644 --- a/packages/docusaurus-plugin-content-docs/src/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/types.ts @@ -118,7 +118,7 @@ export interface MetadataRaw extends LastUpdateData { sidebar_label?: string; editUrl?: string; version?: string; - latestPermalink?: string; + latestVersionMainDocPermalink?: string; } export interface Paginator { diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index b856e8048925..1c3c59f427b0 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -69,7 +69,7 @@ function DocItem(props) { lastUpdatedAt, lastUpdatedBy, version, - latestPermalink, + latestVersionMainDocPermalink, } = metadata; const { frontMatter: { @@ -110,7 +110,7 @@ function DocItem(props) { className={clsx('col', { [styles.docItemCol]: !hideTableOfContents, })}> - {latestPermalink && ( + {latestVersionMainDocPermalink && (
@@ -129,7 +129,7 @@ function DocItem(props) {
For up-to-date documentation, see the{' '} - latest version. + latest version.
From 4dfc06e2772007060656d393fa381a268777360b Mon Sep 17 00:00:00 2001 From: anshul Date: Fri, 12 Jun 2020 22:37:18 +0530 Subject: [PATCH 18/21] feat(v2): fix formating --- packages/docusaurus-plugin-content-docs/src/index.ts | 4 +++- packages/docusaurus-theme-classic/src/theme/DocItem/index.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index c0843fb3b067..575db3bfb9f8 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -65,7 +65,9 @@ const DEFAULT_OPTIONS: PluginOptions = { admonitions: {}, }; -function getFirstDocLinkOfSidebar(sidebarItems: DocsSidebarItem[]): string | null { +function getFirstDocLinkOfSidebar( + sidebarItems: DocsSidebarItem[], +): string | null { for (let sidebarItem of sidebarItems) { if (sidebarItem.type === 'category') { const url = getFirstDocLinkOfSidebar(sidebarItem.items); diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 1c3c59f427b0..1d15429de753 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -129,7 +129,10 @@ function DocItem(props) {
For up-to-date documentation, see the{' '} - latest version. + + latest version + + .
From 10e7dd7c10cd72f18ec3b93da86f560623d67357 Mon Sep 17 00:00:00 2001 From: anshul Date: Fri, 12 Jun 2020 22:55:56 +0530 Subject: [PATCH 19/21] feat(v2): compute homepageurl --- packages/docusaurus-plugin-content-docs/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 575db3bfb9f8..cbb452a96c4d 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -476,7 +476,7 @@ Available document ids= ); const rootUrl = options.homePageId && content.docsMetadata[options.homePageId] - ? content.docsMetadata[options.homePageId].permalink + ? normalizeUrl([baseUrl, routeBasePath]) : getFirstDocLinkOfSidebar( content.docsSidebars[ `version-${versioning.latestVersion}/docs` From 373baf546a61af50e0bb99915f2a0233e6415572 Mon Sep 17 00:00:00 2001 From: teikjun Date: Sun, 14 Jun 2020 19:15:21 +0800 Subject: [PATCH 20/21] style(v2): improve code quality --- packages/docusaurus-plugin-content-docs/src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index cbb452a96c4d..614abda44bc9 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -71,7 +71,9 @@ function getFirstDocLinkOfSidebar( for (let sidebarItem of sidebarItems) { if (sidebarItem.type === 'category') { const url = getFirstDocLinkOfSidebar(sidebarItem.items); - if (url) return url; + if (url) { + return url; + } } else { return sidebarItem.href; } @@ -486,8 +488,9 @@ Available document ids= throw new Error('Bad sidebars file. No document linked'); } Object.values(content.docsMetadata).forEach((docMetadata) => { - if (docMetadata.version !== versioning.latestVersion) + if (docMetadata.version !== versioning.latestVersion) { docMetadata.latestVersionMainDocPermalink = rootUrl; + } }); await Promise.all( Object.keys(docsMetadataByVersion).map(async (version) => { From 12ef01094f8c9a5a49055609251a67c51cc12df3 Mon Sep 17 00:00:00 2001 From: teikjun Date: Sun, 14 Jun 2020 19:23:00 +0800 Subject: [PATCH 21/21] style(v2): unbold fullstop for consistency --- packages/docusaurus-theme-classic/src/theme/DocItem/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 1d15429de753..655747f999f1 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -132,8 +132,8 @@ function DocItem(props) { latest version - .
+ .
)}