From 2bceabcb8e623570540493e2f1d956adf45c99e7 Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Tue, 4 Aug 2020 02:17:03 -0700 Subject: [PATCH] fix: fallback page should use path not file location (#1301) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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). * fix: use router.getFile to resolve fallback url * specs: add cypress test for fallbackLanguages Co-authored-by: 沈唁 <52o@qq52o.cn> --- cypress/fixtures/tpl/docs.index.html | 3 ++- cypress/integration/routing/fallback.spec.js | 9 +++++++++ src/core/fetch/index.js | 6 ++++-- 3 files changed, 15 insertions(+), 3 deletions(-) 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'); + }) +}); diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 9d2769b84..6bf592c96 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); } ); @@ -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(