docs/lib/find-page.js

18 строки
593 B
JavaScript

import { getLanguageCode } from './patterns.js'
export default function findPage(href, pageMap, redirects) {
// remove any fragments
href = href.replace(/#.*$/, '')
// find the page
const page = pageMap[href] || pageMap[redirects[href]]
if (page) return page
// get the current language
const currentLang = getLanguageCode.test(href) ? href.match(getLanguageCode)[1] : 'en'
// try to fall back to English if the translated page can't be found
const englishHref = href.replace(`/${currentLang}/`, '/en/')
return pageMap[englishHref] || pageMap[redirects[englishHref]]
}