forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall-products.js
62 lines (52 loc) · 1.83 KB
/
all-products.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs')
const path = require('path')
const slash = require('slash')
const assert = require('assert')
const { difference } = require('lodash')
const yaml = require('js-yaml')
const contentDir = path.join(process.cwd(), 'content')
const frontmatter = require('@github-docs/frontmatter')
const getApplicableVersions = require('./get-applicable-versions')
// the product order is determined by data/products.yml
const productsFile = path.join(process.cwd(), 'data/products.yml')
const productsYml = yaml.load(fs.readFileSync(productsFile, 'utf8'))
const sortedProductIds = productsYml.productsInOrder
const contentProductIds = fs.readdirSync(contentDir, { withFileTypes: true })
.filter(entry => entry.isDirectory())
.map(entry => entry.name)
assert(difference(sortedProductIds, contentProductIds).length === 0)
assert(difference(contentProductIds, sortedProductIds).length === 0)
const internalProducts = {}
sortedProductIds.forEach(productId => {
const relPath = productId
const dir = slash(path.join('content', relPath))
const toc = slash(path.join(dir, 'index.md'))
const { data } = frontmatter(fs.readFileSync(toc, 'utf8'))
const applicableVersions = getApplicableVersions(data.versions, toc)
const href = slash(path.join('/', applicableVersions[0], productId))
internalProducts[productId] = {
id: productId,
name: data.shortTitle || data.title,
href,
dir,
toc,
wip: data.wip || false
}
internalProducts[productId].versions = applicableVersions
})
const externalProducts = {
atom: {
id: 'atom',
name: 'Atom',
href: 'https://atom.io/docs',
external: true
},
electron: {
id: 'electron',
name: 'Electron',
href: 'https://electronjs.org/docs',
external: true
}
}
const allProducts = Object.assign({}, internalProducts, externalProducts)
module.exports = allProducts