33const fs = require ( 'fs' )
44const path = require ( 'path' )
55const walk = require ( 'walk-sync' )
6- const yaml = require ( 'js-yaml' )
76const frontmatter = require ( '../../lib/read-frontmatter' )
87const getDocumentType = require ( '../../lib/get-document-type' )
98const languages = require ( '../../lib/languages' )
109
1110const linkString = / { % [ ^ } ] * ?l i n k .* ? ( \/ .* ?) ? % } / m
1211const 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
3226const 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+
3534indexFiles
3635 . forEach ( indexFile => {
3736 const relativePath = indexFile . replace ( / ^ .+ \/ c o n t e n t \/ / , '' )
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