2
0
Fork 0
mirror of https://github.com/yannbertrand/macos-defaults synced 2024-12-17 15:03:08 +00:00
macos-defaults/build/docsify/write-config.js
Yann Bertrand a6a996ddd2 🚨 Run Prettier
2020-11-27 14:39:16 +01:00

53 lines
1.3 KiB
JavaScript

const fs = require('fs')
const Handlebars = require('handlebars')
Handlebars.registerHelper('ifCond', function (v1, v2, options) {
if (v1 === v2) {
return options.fn(this)
}
return options.inverse(this)
})
module.exports = (
supportedLanguage,
supportedLanguages,
templatesPath,
destinationPath,
rootConfig = false
) => {
const sidebarTemplate = fs.readFileSync(
`${templatesPath}/_sidebar.md.handlebars`,
'utf8'
)
const sidebarContent = Handlebars.compile(sidebarTemplate)(supportedLanguage)
fs.writeFileSync(`${destinationPath}/_sidebar.md`, sidebarContent)
const navbarTemplate = fs.readFileSync(
`${templatesPath}/_navbar.md.handlebars`,
'utf8'
)
const navbarContent = Handlebars.compile(navbarTemplate)({
currentUrl: supportedLanguage.url,
...supportedLanguages,
})
fs.writeFileSync(`${destinationPath}/_navbar.md`, navbarContent)
if (!rootConfig) {
return
}
fs.copyFileSync(
`${templatesPath}/favicon.ico`,
`${destinationPath}/favicon.ico`
)
const indexTemplate = fs.readFileSync(
`${templatesPath}/index.html.handlebars`,
'utf8'
)
const indexContent = Handlebars.compile(indexTemplate)({
...supportedLanguage,
...supportedLanguages,
})
fs.writeFileSync(`${destinationPath}/index.html`, indexContent)
}