MCPcopy
hub / github.com/github/docs / findPage

Function findPage

lib/find-page.js:4–20  ·  view source on GitHub ↗
(href, pages, redirects)

Source from the content-addressed store, hash-verified

2import getRedirect from './get-redirect.js'
3
4export default function findPage(href, pages, redirects) {
5 // remove any fragments
6 href = new URL(href, 'http://example.com').pathname
7
8 const redirectsContext = { redirects, pages }
9
10 // find the page
11 const page = pages[href] || pages[getRedirect(href, redirectsContext)]
12 if (page) return page
13
14 // get the current language
15 const currentLang = getLanguageCode.test(href) ? href.match(getLanguageCode)[1] : 'en'
16
17 // try to fall back to English if the translated page can't be found
18 const englishHref = href.replace(`/${currentLang}/`, '/en/')
19 return pages[englishHref] || pages[getRedirect(englishHref, redirectsContext)]
20}

Callers 5

getEnglishHeadingsFunction · 0.70
processLinkFunction · 0.70
getNewTitleFunction · 0.50
find-page.jsFile · 0.50

Calls 1

getRedirectFunction · 0.70

Tested by

no test coverage detected