Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

find-page.js 598 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  1. const { getLanguageCode } = require('./patterns')
  2. module.exports = function findPage (href, pageMap, redirects) {
  3. // remove any fragments
  4. href = href.replace(/#.*$/, '')
  5. // find the page
  6. const page = pageMap[href] || pageMap[redirects[href]]
  7. if (page) return page
  8. // get the current language
  9. const currentLang = getLanguageCode.test(href) ? href.match(getLanguageCode)[1] : 'en'
  10. // try to fall back to English if the translated page can't be found
  11. const englishHref = href.replace(`/${currentLang}/`, '/en/')
  12. return pageMap[englishHref] || pageMap[redirects[englishHref]]
  13. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...