Skip to content

Commit f0244fa

Browse files
committed
reinstate a simplified findPage()
1 parent d5eee9d commit f0244fa

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

lib/find-page.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { getLanguageCode } = require('./patterns')
2+
3+
module.exports = function findPage (href, pageMap, redirects) {
4+
// remove any fragments
5+
href = href.replace(/#.*$/, '')
6+
7+
// find the page
8+
const page = pageMap[href] || pageMap[redirects[href]]
9+
if (page) return page
10+
11+
// get the current language
12+
const currentLang = getLanguageCode.test(href) ? href.match(getLanguageCode)[1] : 'en'
13+
14+
// try to fall back to English if the translated page can't be found
15+
const englishHref = href.replace(`/${currentLang}/`, '/en/')
16+
return pageMap[englishHref] || pageMap[redirects[englishHref]]
17+
}

0 commit comments

Comments
 (0)