macos-defaults/build/docsify/build.js
2020-09-26 20:24:54 +02:00

30 lines
1.1 KiB
JavaScript

const fs = require('fs')
const YAML = require('yaml')
const writeTree = require('./write-tree')
const writeConfig = require('./write-config')
const input = fs.readFileSync('../../defaults.yml', 'utf8')
const inputFr = fs.readFileSync('../../defaults-fr.yml', 'utf8')
const defaults = YAML.parse(input)
const defaultsFr = YAML.parse(inputFr)
const templatesPath = 'templates'
const destinationPath = 'docs'
const supportedLanguages = {
languages: [
{ url: '/fr/', lang: 'fr-FR', home: 'Accueil', defaults: getSafeDefaults(defaultsFr, defaults), isFallback: false },
{ url: '/', lang: 'en-US', home: 'Home', defaults: defaults, isFallback: true },
]
}
supportedLanguages.languages.forEach((supportedLanguage) => {
const { url, isFallback } = supportedLanguage
writeTree(supportedLanguage, `${templatesPath}${url}`, `${destinationPath}${url}`)
writeConfig(supportedLanguage, supportedLanguages, `${templatesPath}${url}`, `${destinationPath}${url}`, isFallback)
})
function getSafeDefaults(localizedDefaults, fallbackDefaults) {
return { ...fallbackDefaults, ...localizedDefaults }
}