Skip to content

Commit e06574b

Browse files
committed
make comments nicer
1 parent 5669cc9 commit e06574b

2 files changed

Lines changed: 30 additions & 21 deletions

File tree

lib/create-tree.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { sortBy } = require('lodash')
66
let basePath
77

88
module.exports = async function createTree (originalPath, langObj) {
9-
// Do not reset this value on recursive runs
9+
// Do not reset this value on recursive runs.
1010
if (!basePath) basePath = originalPath
1111

1212
// On recursive runs, this is processing page.children items in `/<link>` format.
@@ -23,34 +23,34 @@ module.exports = async function createTree (originalPath, langObj) {
2323
const relativePath = filepath.replace(`${basePath}/`, '')
2424
const localizedBasePath = path.join(__dirname, '..', langObj.dir, 'content')
2525

26-
// Initialize the Page! This is where the magic happens (sorry).
26+
// Initialize the Page! This is where the file reads happen.
2727
const page = await Page.init({
2828
basePath: localizedBasePath,
2929
relativePath,
3030
languageCode: langObj.code
3131
})
3232

3333
if (!page) {
34-
// Do not throw an error if early access is not available
34+
// Do not throw an error if Early Access is not available.
3535
if (relativePath.startsWith('early-access')) return
3636

3737
throw Error(`Cannot initialize page for ${filepath}`)
3838
}
3939

40-
// Create the root tree object on the first run, and create children recursively
40+
// Create the root tree object on the first run, and create children recursively.
4141
const item = {
4242
relativePath,
4343
title: page.shortTitle || page.title,
4444
page
4545
}
4646

47-
// Process frontmatter children recursively
47+
// Process frontmatter children recursively.
4848
if (item.page.children) {
4949
item.childPages = sortBy(
5050
(await Promise.all(item.page.children
5151
.map(async (child) => await createTree(path.join(originalPath, child), langObj))))
5252
.filter(Boolean),
53-
// Sort by the ordered array of children in the frontmatter
53+
// Sort by the ordered array of `children` in the frontmatter.
5454
item.page.children
5555
)
5656
}

lib/page-data.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,37 @@ const createTree = require('./create-tree')
55
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
66
const 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+
*/
1519
module.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

Comments
 (0)