We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d5eee9d commit f0244faCopy full SHA for f0244fa
1 file changed
lib/find-page.js
@@ -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