MCPcopy Create free account
hub / github.com/github/docs / syncSearchIndexes

Function syncSearchIndexes

script/search/sync.js:13–88  ·  view source on GitHub ↗
({
  language,
  version,
  notLanguage,
  outDirectory,
  config = {},
})

Source from the content-addressed store, hash-verified

11// Build a search data file for every combination of product version and language
12// e.g. `github-docs-dotcom-en.json` and `github-docs-2.14-ja.json`
13export default async function syncSearchIndexes({
14 language,
15 version,
16 notLanguage,
17 outDirectory,
18 config = {},
19}) {
20 const t0 = new Date()
21
22 // build indices for a specific language if provided; otherwise build indices for all languages
23 const languagesToBuild = Object.keys(languages).filter((lang) =>
24 notLanguage ? notLanguage !== lang : language ? language === lang : true
25 )
26
27 // build indices for a specific version if provided; otherwise build indices for all versions
28 const versionsToBuild = Object.keys(allVersions).filter((ver) =>
29 version ? version === ver : true
30 )
31
32 console.log(
33 `Building indices for ${chalk.yellow(language || 'all languages')} and ${chalk.yellow(
34 version || 'all versions'
35 )}.\n`
36 )
37
38 // Exclude WIP pages, hidden pages, index pages, etc
39 const indexablePages = await findIndexablePages(config.filter)
40 const redirects = {}
41 indexablePages.forEach((page) => {
42 const href = page.relativePath.replace('index.md', '').replace('.md', '')
43 for (let redirectFrom of page.redirect_from || []) {
44 // Remember that each redirect_from as a prefix / and often it ends
45 // with a trailing /
46 if (redirectFrom.startsWith('/')) redirectFrom = redirectFrom.slice(1)
47 if (redirectFrom.endsWith('/')) redirectFrom = redirectFrom.slice(0, -1)
48 redirects[redirectFrom] = href
49 }
50 })
51
52 let countRecordsTotal = 0
53 // Build and validate all indices
54 for (const languageCode of languagesToBuild) {
55 for (const pageVersion of versionsToBuild) {
56 // if GHES, resolves to the release number like 2.21, 2.22, etc.
57 // if FPT, resolves to 'dotcom'
58 // if GHAE, resolves to 'ghae'
59 const indexVersion =
60 allVersions[pageVersion].plan === 'enterprise-server'
61 ? allVersions[pageVersion].currentRelease
62 : allVersions[pageVersion].miscBaseName
63
64 // github-docs-dotcom-en, github-docs-2.22-en
65 const indexName = `${namePrefix}-${indexVersion}-${languageCode}`
66
67 // The page version will be the new version, e.g., free-pro-team@latest, enterprise-server@3.7
68 const records = await buildRecords(
69 indexName,
70 indexablePages,

Callers

nothing calls this directly

Calls 4

writeIndexRecordsFunction · 0.90
findIndexablePagesFunction · 0.85
buildRecordsFunction · 0.85
formatSecondsFunction · 0.85

Tested by

no test coverage detected