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 9fcc117bb3010..2daea9fe12728 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 0e5b7e94c4a86..17759bff68ab0 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 f767a738a2367..c0843fb3b067b 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 42ef28946c75b..2b7b8b89a2958 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 b856e80489257..1c3c59f427b0c 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.
diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 25781444366fc..9cceea15b5b8c 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -36,7 +36,7 @@ module.exports = { '@docusaurus/preset-classic', { docs: { - homePageId: 'introduction', + homePageId: 'ding', path: 'docs', sidebarPath: require.resolve('./sidebars.js'), editUrl: