Skip to content

Commit 2295496

Browse files
committed
update all-products so it reads from the homepage frontmatter
1 parent 73c6785 commit 2295496

1 file changed

Lines changed: 18 additions & 61 deletions

File tree

lib/all-products.js

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,28 @@
11
const fs = require('fs')
22
const path = require('path')
3-
const slash = require('slash')
4-
const assert = require('assert')
5-
const { difference } = require('lodash')
6-
const yaml = require('js-yaml')
7-
const contentDir = path.join(process.cwd(), 'content')
83
const frontmatter = require('./read-frontmatter')
94
const getApplicableVersions = require('./get-applicable-versions')
105
const removeFPTFromPath = require('./remove-fpt-from-path')
116

12-
// the product order is determined by data/products.yml
13-
const productsFile = path.join(process.cwd(), 'data/products.yml')
14-
const productsYml = yaml.load(fs.readFileSync(productsFile, 'utf8'))
15-
const sortedProductIds = productsYml.productsInOrder
16-
17-
const contentProductIds = fs.readdirSync(contentDir, { withFileTypes: true })
18-
.map(entry => {
19-
// `fs.readdir` provides file entries based on `fs.lstat`, which doesn't
20-
// resolve symbolic links to their target file/directory. We need to take
21-
// an extra step here to resolve the Early Access symlinked directory.
22-
const { name } = entry
23-
if (entry.isSymbolicLink()) {
24-
entry = fs.statSync(path.join(contentDir, entry.name))
25-
entry.name = name
26-
}
27-
return entry
28-
})
29-
.filter(entry => entry.isDirectory())
30-
.map(entry => entry.name)
31-
32-
// require the content/<subdir> list to match the list in data/products.yml,
33-
// with the exception of content/early-access, which lives in a separate private repo
34-
const publicContentProductIds = contentProductIds.filter(id => id !== 'early-access')
35-
assert(difference(sortedProductIds, publicContentProductIds).length === 0)
36-
assert(difference(publicContentProductIds, sortedProductIds).length === 0)
7+
// Both internal and external products are specified in content/index.md
8+
const homepage = path.posix.join(process.cwd(), 'content/index.md')
9+
const { data } = frontmatter(fs.readFileSync(homepage, 'utf8'))
10+
const productIds = data.children
11+
const externalProducts = data.externalProducts
3712

3813
const internalProducts = {}
3914

40-
// add optional early access content dir to sorted products list if present
41-
const earlyAccessId = contentProductIds.find(id => id === 'early-access')
42-
if (earlyAccessId) sortedProductIds.push(earlyAccessId)
43-
44-
sortedProductIds.forEach(productId => {
15+
productIds.forEach(productId => {
4516
const relPath = productId
46-
const dir = slash(path.join('content', relPath))
47-
const toc = slash(path.join(dir, 'index.md'))
17+
const dir = path.posix.join('content', relPath)
18+
19+
// Early Access may not exist in the current checkout
20+
if (!fs.existsSync(dir)) return
21+
22+
const toc = path.posix.join(dir, 'index.md')
4823
const { data } = frontmatter(fs.readFileSync(toc, 'utf8'))
4924
const applicableVersions = getApplicableVersions(data.versions, toc)
50-
const href = removeFPTFromPath(slash(path.join('/', applicableVersions[0], productId)))
25+
const href = removeFPTFromPath(path.posix.join('/', applicableVersions[0], productId))
5126

5227
internalProducts[productId] = {
5328
id: productId,
@@ -62,27 +37,9 @@ sortedProductIds.forEach(productId => {
6237
internalProducts[productId].versions = applicableVersions
6338
})
6439

65-
const externalProducts = {
66-
cli: {
67-
id: 'cli',
68-
name: 'GitHub CLI',
69-
href: 'https://cli.github.com/manual',
70-
external: true
71-
},
72-
atom: {
73-
id: 'atom',
74-
name: 'Atom',
75-
href: 'https://atom.io/docs',
76-
external: true
77-
},
78-
electron: {
79-
id: 'electron',
80-
name: 'Electron',
81-
href: 'https://electronjs.org/docs',
82-
external: true
83-
}
84-
}
85-
86-
const allProducts = Object.assign({}, internalProducts, externalProducts)
40+
const productMap = Object.assign({}, internalProducts, externalProducts)
8741

88-
module.exports = allProducts
42+
module.exports = {
43+
productIds,
44+
productMap
45+
}

0 commit comments

Comments
 (0)