Skip to content

Commit

Permalink
fix(v2): fix docs homepage permalink issues (#2905)
Browse files Browse the repository at this point in the history
* better fixes for docs homepage

* fix tests

* create special route for docs homepage + cleanup existing code

* no need to create multiple docs parent paths

* useful comment

* add test for slug + doc home usage at the same time error

* remove confusing variable name

* fix tests by using same suffix as before for docs base metadata path

* metadata: use homePageId correctly for nested docs: the full docId (including /) should be used to compare against homePageId

* add folder/testNested test doc

* refactor a bit processMetadata, the home should be handled correctly for all versions

* Workaround to fix issue when parent layout route (DocPage) has same path as the child route (DocItem): see #2917

* revert homePageId

* remove test doc

* remove test doc

* add useful comment
  • Loading branch information
slorber authored Jun 17, 2020
1 parent a3f54d7 commit f6b1c85
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 218 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
slug: docWithSlug.html
---

Lorem
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Object {
"type": "link",
},
Object {
"href": "/docs",
"href": "/docs/",
"label": "Hello, World !",
"type": "link",
},
Expand All @@ -41,7 +41,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs",
"href": "/docs/",
"label": "Hello, World !",
"type": "link",
},
Expand All @@ -57,21 +57,21 @@ exports[`simple website content 2`] = `
Array [
Object {
"component": "@theme/DocPage",
"exact": true,
"modules": Object {
"content": "@site/docs/hello.md",
"docsMetadata": "~docs/site-docs-hello-md-9df-base.json",
},
"path": "/docs",
},
Object {
"component": "@theme/DocPage",
"exact": false,
"modules": Object {
"docsMetadata": "~docs/docs-route-ff2.json",
},
"path": "/docs/:route",
"path": "/docs",
"priority": undefined,
"routes": Array [
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/hello.md",
},
"path": "/docs/",
},
Object {
"component": "@theme/DocItem",
"exact": true,
Expand Down Expand Up @@ -123,39 +123,21 @@ exports[`versioned website content 1`] = `
Array [
Object {
"component": "@theme/DocPage",
"exact": true,
"modules": Object {
"content": "@site/versioned_docs/version-1.0.1/hello.md",
"docsMetadata": "~docs/site-versioned-docs-version-1-0-1-hello-md-0c7-base.json",
},
"path": "/docs",
},
Object {
"component": "@theme/DocPage",
"exact": true,
"modules": Object {
"content": "@site/versioned_docs/version-1.0.0/hello.md",
"docsMetadata": "~docs/site-versioned-docs-version-1-0-0-hello-md-3ef-base.json",
},
"path": "/docs/1.0.0",
},
Object {
"component": "@theme/DocPage",
"exact": true,
"modules": Object {
"content": "@site/docs/hello.md",
"docsMetadata": "~docs/site-docs-hello-md-9df-base.json",
},
"path": "/docs/next",
},
Object {
"component": "@theme/DocPage",
"exact": false,
"modules": Object {
"docsMetadata": "~docs/docs-1-0-0-route-660.json",
},
"path": "/docs/1.0.0/:route",
"path": "/docs/1.0.0",
"priority": undefined,
"routes": Array [
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/versioned_docs/version-1.0.0/hello.md",
},
"path": "/docs/1.0.0/",
},
Object {
"component": "@theme/DocItem",
"exact": true,
Expand All @@ -176,12 +158,21 @@ Array [
},
Object {
"component": "@theme/DocPage",
"exact": false,
"modules": Object {
"docsMetadata": "~docs/docs-next-route-1c8.json",
},
"path": "/docs/next/:route",
"path": "/docs/next",
"priority": undefined,
"routes": Array [
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/hello.md",
},
"path": "/docs/next/",
},
Object {
"component": "@theme/DocItem",
"exact": true,
Expand All @@ -194,12 +185,21 @@ Array [
},
Object {
"component": "@theme/DocPage",
"exact": false,
"modules": Object {
"docsMetadata": "~docs/docs-route-ff2.json",
},
"path": "/docs/:route",
"path": "/docs",
"priority": -1,
"routes": Array [
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/versioned_docs/version-1.0.1/hello.md",
},
"path": "/docs/",
},
Object {
"component": "@theme/DocItem",
"exact": true,
Expand Down Expand Up @@ -232,7 +232,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/next",
"href": "/docs/next/",
"label": "hello",
"type": "link",
},
Expand Down Expand Up @@ -263,7 +263,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/1.0.0",
"href": "/docs/1.0.0/",
"label": "hello",
"type": "link",
},
Expand All @@ -289,7 +289,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs",
"href": "/docs/",
"label": "hello",
"type": "link",
},
Expand Down Expand Up @@ -326,7 +326,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/1.0.0",
"href": "/docs/1.0.0/",
"label": "hello",
"type": "link",
},
Expand All @@ -337,9 +337,9 @@ Object {
],
},
"permalinkToSidebar": Object {
"/docs/1.0.0/": "version-1.0.0/docs",
"/docs/1.0.0/foo/barSlug": "version-1.0.0/docs",
"/docs/1.0.0/foo/baz": "version-1.0.0/docs",
"/docs/1.0.0/hello": "version-1.0.0/docs",
},
"version": "1.0.0",
}
Expand All @@ -365,7 +365,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs",
"href": "/docs/",
"label": "hello",
"type": "link",
},
Expand All @@ -376,8 +376,8 @@ Object {
],
},
"permalinkToSidebar": Object {
"/docs/": "version-1.0.1/docs",
"/docs/foo/bar": "version-1.0.1/docs",
"/docs/hello": "version-1.0.1/docs",
},
"version": "1.0.1",
}
Expand All @@ -403,7 +403,7 @@ Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/next",
"href": "/docs/next/",
"label": "hello",
"type": "link",
},
Expand All @@ -414,8 +414,8 @@ Object {
],
},
"permalinkToSidebar": Object {
"/docs/next/": "docs",
"/docs/next/foo/barSlug": "docs",
"/docs/next/hello": "docs",
},
"version": "next",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ describe('simple website', () => {
expect(versionToSidebars).toEqual({});
expect(docsMetadata.hello).toEqual({
id: 'hello',
permalink: '/docs/hello',
isDocsHomePage: true,
permalink: '/docs/',
previous: {
title: 'baz',
permalink: '/docs/foo/bazSlug.html',
Expand All @@ -168,6 +169,7 @@ describe('simple website', () => {

expect(docsMetadata['foo/bar']).toEqual({
id: 'foo/bar',
isDocsHomePage: false,
next: {
title: 'baz',
permalink: '/docs/foo/bazSlug.html',
Expand Down Expand Up @@ -296,6 +298,7 @@ describe('versioned website', () => {
expect(docsMetadata['version-1.0.1/foo/baz']).toBeUndefined();
expect(docsMetadata['foo/bar']).toEqual({
id: 'foo/bar',
isDocsHomePage: false,
permalink: '/docs/next/foo/barSlug',
source: path.join('@site', routeBasePath, 'foo', 'bar.md'),
title: 'bar',
Expand All @@ -304,12 +307,13 @@ describe('versioned website', () => {
sidebar: 'docs',
next: {
title: 'hello',
permalink: '/docs/next/hello',
permalink: '/docs/next/',
},
});
expect(docsMetadata['hello']).toEqual({
id: 'hello',
permalink: '/docs/next/hello',
isDocsHomePage: true,
permalink: '/docs/next/',
source: path.join('@site', routeBasePath, 'hello.md'),
title: 'hello',
description: 'Hello next !',
Expand All @@ -322,7 +326,8 @@ describe('versioned website', () => {
});
expect(docsMetadata['version-1.0.1/hello']).toEqual({
id: 'version-1.0.1/hello',
permalink: '/docs/hello',
isDocsHomePage: true,
permalink: '/docs/',
source: path.join(
'@site',
path.relative(siteDir, versionedDir),
Expand All @@ -341,6 +346,7 @@ describe('versioned website', () => {
});
expect(docsMetadata['version-1.0.0/foo/baz']).toEqual({
id: 'version-1.0.0/foo/baz',
isDocsHomePage: false,
permalink: '/docs/1.0.0/foo/baz',
source: path.join(
'@site',
Expand All @@ -356,7 +362,7 @@ describe('versioned website', () => {
sidebar: 'version-1.0.0/docs',
next: {
title: 'hello',
permalink: '/docs/1.0.0/hello',
permalink: '/docs/1.0.0/',
},
previous: {
title: 'bar',
Expand Down
Loading

0 comments on commit f6b1c85

Please sign in to comment.