@@ -5,28 +5,37 @@ const createTree = require('./create-tree')
55const nonEnterpriseDefaultVersion = require ( './non-enterprise-default-version' )
66const englishPath = path . join ( __dirname , '..' , 'content' )
77
8- // This function creates three structures that we need for various purposes:
9- // 1. siteTree: A nested object with pages for every language and version:
10- // siteTree[languageCode][version].childPages[<array of pages>].childPages[<array of pages>] (etc...)
11- //
12- // 2. pageMap: A map of all pages with permalinks as keys for fast lookup.
13- //
14- // 3. pageList: A simple array of all page objects for fast iterating.
8+ /**
9+ * This function creates three representions of pages we need for different purposes:
10+ *
11+ * 1. siteTree: A nested object with pages for every language and version, useful for nav because it
12+ * contains parent, child, and sibling relationships:
13+ * siteTree[languageCode][version].childPages[<array of pages>].childPages[<array of pages>] (etc...)
14+ *
15+ * 2. pageMap: A map of all pages with permalinks as keys for fast lookup.
16+ *
17+ * 3. pageList: A simple array of all page objects for fast iterating.
18+ */
1519module . exports = async function loadPageData ( ) {
16- // We only need to initialize pages *once per language* since pages don't change per version. So we do that
17- // first since it's the most expensive work. This gets us a nested object with pages attached that we can use
18- // as the basis for the siteTree after we do some versioning.
20+ /**
21+ * We only need to initialize pages _once per language_ since pages don't change per version. So we do that
22+ * first since it's the most expensive work. This gets us a nested object with pages attached that we can use
23+ * as the basis for the siteTree after we do some versioning.
24+ */
1925 const rawTree = { }
26+
2027 await Promise . all ( Object . values ( languages )
2128 . map ( async ( langObj ) => {
2229 rawTree [ langObj . code ] = await createTree ( englishPath , langObj )
2330 } ) )
2431
25- // Now that we have the object of all pages per language, we can walk it for each version and do a couple operations:
26- // 1. Add a versioned href to every item, where the href is the relevant permalink for the current version.
27- // A) Add an entry for the permalink in the pageMap.
28- // 2. Drop any child pages that are not available in the current version.
29- // Note that order of languages and versions doesn't matter, but order of child page arrays DOES matter (for navigation).
32+ /**
33+ * Now that we have the object of all pages per language, we can walk it for each version and do a couple operations:
34+ * 1. Add a versioned href to every item, where the href is the relevant permalink for the current version.
35+ * A) Add an entry for the permalink in the pageMap.
36+ * 2. Drop any child pages that are not available in the current version.
37+ * Note that order of languages and versions doesn't matter, but order of child page arrays DOES matter (for navigation).
38+ */
3039 const siteTree = { }
3140 const pageMap = { }
3241
0 commit comments