2021-07-14 23:49:18 +03:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
import frontmatter from './read-frontmatter.js'
|
|
|
|
import getApplicableVersions from './get-applicable-versions.js'
|
|
|
|
import removeFPTFromPath from './remove-fpt-from-path.js'
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-04-01 22:29:31 +03:00
|
|
|
// Both internal and external products are specified in content/index.md
|
|
|
|
const homepage = path.posix.join(process.cwd(), 'content/index.md')
|
|
|
|
const { data } = frontmatter(fs.readFileSync(homepage, 'utf8'))
|
2021-07-14 23:49:18 +03:00
|
|
|
export const productIds = data.children
|
2021-04-01 22:29:31 +03:00
|
|
|
const externalProducts = data.externalProducts
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
const internalProducts = {}
|
|
|
|
|
2021-07-15 00:35:01 +03:00
|
|
|
productIds.forEach((productId) => {
|
2020-09-29 20:36:07 +03:00
|
|
|
const relPath = productId
|
2021-04-01 22:29:31 +03:00
|
|
|
const dir = path.posix.join('content', relPath)
|
|
|
|
|
|
|
|
// Early Access may not exist in the current checkout
|
|
|
|
if (!fs.existsSync(dir)) return
|
|
|
|
|
|
|
|
const toc = path.posix.join(dir, 'index.md')
|
2020-09-27 15:10:11 +03:00
|
|
|
const { data } = frontmatter(fs.readFileSync(toc, 'utf8'))
|
2020-09-29 20:36:07 +03:00
|
|
|
const applicableVersions = getApplicableVersions(data.versions, toc)
|
2021-04-01 22:29:31 +03:00
|
|
|
const href = removeFPTFromPath(path.posix.join('/', applicableVersions[0], productId))
|
2020-09-27 15:10:11 +03:00
|
|
|
|
|
|
|
internalProducts[productId] = {
|
|
|
|
id: productId,
|
|
|
|
name: data.shortTitle || data.title,
|
|
|
|
href,
|
|
|
|
dir,
|
|
|
|
toc,
|
2020-10-21 00:22:08 +03:00
|
|
|
wip: data.wip || false,
|
2021-07-15 00:35:01 +03:00
|
|
|
hidden: data.hidden || false,
|
2020-09-27 15:10:11 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
internalProducts[productId].versions = applicableVersions
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
2021-07-14 23:49:18 +03:00
|
|
|
export const productMap = Object.assign({}, internalProducts, externalProducts)
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-07-14 23:49:18 +03:00
|
|
|
export default {
|
2021-04-01 22:29:31 +03:00
|
|
|
productIds,
|
2021-07-15 00:35:01 +03:00
|
|
|
productMap,
|
2021-04-01 22:42:59 +03:00
|
|
|
}
|