Skip to content

Commit b198a6a

Browse files
committed
update script too
1 parent c3b5fec commit b198a6a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

script/content-migrations/update-tocs.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33
const fs = require('fs')
44
const path = require('path')
55
const walk = require('walk-sync')
6-
const yaml = require('js-yaml')
76
const frontmatter = require('../../lib/read-frontmatter')
87
const getDocumentType = require('../../lib/get-document-type')
98
const languages = require('../../lib/languages')
109

1110
const linkString = /{% [^}]*?link.*? (\/.*?) ?%}/m
1211
const linksArray = new RegExp(linkString.source, 'gm')
1312

14-
// The product order is determined by data/products.yml
15-
const productsFile = path.join(process.cwd(), 'data/products.yml')
16-
const productsYml = yaml.load(fs.readFileSync(productsFile, 'utf8'))
17-
const sortedProductIds = productsYml.productsInOrder.concat('early-access')
18-
1913
// This script turns `{% link /<link> %} style content into children: [ -/<link> ] frontmatter arrays.
2014
//
2115
// It MUST be run after script/content-migrations/remove-map-topics.js.
@@ -32,15 +26,28 @@ const fullDirectoryPaths = Object.values(languages).map(langObj => path.join(pro
3226
const indexFiles = fullDirectoryPaths.map(fullDirectoryPath => walk(fullDirectoryPath, walkOpts)).flat()
3327
.filter(file => file.endsWith('index.md'))
3428

29+
const englishHomepageData = {
30+
children: '',
31+
externalProducts: ''
32+
}
33+
3534
indexFiles
3635
.forEach(indexFile => {
3736
const relativePath = indexFile.replace(/^.+\/content\//, '')
3837
const documentType = getDocumentType(relativePath)
3938

4039
const { data, content } = frontmatter(fs.readFileSync(indexFile, 'utf8'))
4140

42-
if (documentType === 'homepage') {
43-
data.children = sortedProductIds
41+
// Save the English homepage frontmatter props...
42+
if (documentType === 'homepage' && !indexFile.includes('/translations/')) {
43+
englishHomepageData.children = data.children
44+
englishHomepageData.externalProducts = data.externalProducts
45+
}
46+
47+
// ...and reuse them in the translated homepages, in case the translated files are out of date
48+
if (documentType === 'homepage' && indexFile.includes('/translations/')) {
49+
data.children = englishHomepageData.children
50+
data.externalProducts = englishHomepageData.externalProducts
4451
}
4552

4653
const linkItems = content.match(linksArray) || []

0 commit comments

Comments
 (0)