MCPcopy Index your code
hub / github.com/github/docs / loadPageList

Function loadPageList

lib/page-data.js:245–269  ·  view source on GitHub ↗
(unversionedTree, languagesOnly = null)

Source from the content-addressed store, hash-verified

243
244// Derive a flat array of Page objects in all languages.
245export async function loadPageList(unversionedTree, languagesOnly = null) {
246 if (languagesOnly && !Array.isArray(languagesOnly)) {
247 throw new Error("'languagesOnly' has to be an array")
248 }
249 const rawTree = unversionedTree || (await loadUnversionedTree(languagesOnly))
250 const pageList = []
251
252 await Promise.all(
253 (languagesOnly || Object.keys(languages)).map(async (langCode) => {
254 await addToCollection(rawTree[langCode], pageList)
255 })
256 )
257
258 async function addToCollection(item, collection) {
259 if (!item.page) return
260 collection.push(item.page)
261
262 if (!item.childPages) return
263 await Promise.all(
264 item.childPages.map(async (childPage) => await addToCollection(childPage, collection))
265 )
266 }
267
268 return pageList
269}
270
271export const loadPages = loadPageList
272

Callers 1

loadPageMapFunction · 0.85

Calls 2

loadUnversionedTreeFunction · 0.85
addToCollectionFunction · 0.85

Tested by

no test coverage detected