From 3864761029551a56b845b146b549252b78a4a28d Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Wed, 22 Jul 2020 17:31:56 +0300 Subject: [PATCH 1/3] fix: fallback page should use path not file location When resolving fallback page for the path (`fallbackLanguages` option), we should consider the original path, not the file location (which could be different when aliases are used). --- src/core/fetch/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 9d2769b84..923dc3e90 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -123,7 +123,7 @@ export function fetchMixin(proto) { this._loadSideAndNav(path, qs, loadSidebar, cb) ), _ => { - this._fetchFallbackPage(file, qs, cb) || this._fetch404(file, qs, cb); + this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb); } ); From f87d9a56042e3c36c60ffe30f1c0d75400ccd31d Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Wed, 22 Jul 2020 17:38:23 +0300 Subject: [PATCH 2/3] fix: use router.getFile to resolve fallback url --- src/core/fetch/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 923dc3e90..6bf592c96 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -209,7 +209,9 @@ export function fetchMixin(proto) { return false; } - const newPath = path.replace(new RegExp(`^/${local}`), ''); + const newPath = this.router.getFile( + path.replace(new RegExp(`^/${local}`), '') + ); const req = request(newPath + qs, true, requestHeaders); req.then( From 190de35f62a4bbe2d76c543a53d159e91e1f7c58 Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Mon, 27 Jul 2020 16:42:52 +0300 Subject: [PATCH 3/3] specs: add cypress test for fallbackLanguages --- cypress/fixtures/tpl/docs.index.html | 3 ++- cypress/integration/routing/fallback.spec.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 cypress/integration/routing/fallback.spec.js diff --git a/cypress/fixtures/tpl/docs.index.html b/cypress/fixtures/tpl/docs.index.html index a4b4c831f..3ffe35230 100644 --- a/cypress/fixtures/tpl/docs.index.html +++ b/cypress/fixtures/tpl/docs.index.html @@ -28,7 +28,7 @@ alias: { '.*?/awesome': 'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md', - '.*?/changelog': + '/changelog': 'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md', '/.*/_navbar.md': '/_navbar.md', '/zh-cn/(.*)': @@ -40,6 +40,7 @@ '/es/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1' }, + fallbackLanguages: ['es'], auto2top: true, coverpage: true, executeScript: true, diff --git a/cypress/integration/routing/fallback.spec.js b/cypress/integration/routing/fallback.spec.js new file mode 100644 index 000000000..2e9951102 --- /dev/null +++ b/cypress/integration/routing/fallback.spec.js @@ -0,0 +1,9 @@ +context('config.fallbackLanguages', () => { + it('fallbacks respecting aliases', () => { + cy.visit('http://localhost:3000/#/es/'); + + cy.get('.sidebar-nav').contains('Changelog').click(); + + cy.get('#main').should('contain', 'Bug Fixes'); + }) +});