macos-defaults/build/docsify/write-config.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

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)
})
2020-11-27 12:45:16 +00:00
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)
2020-11-27 12:45:16 +00:00
const navbarTemplate = fs.readFileSync(
`${templatesPath}/_navbar.md.handlebars`,
'utf8'
)
const navbarContent = Handlebars.compile(navbarTemplate)({
currentUrl: supportedLanguage.url,
...supportedLanguages,
})
fs.writeFileSync(`${destinationPath}/_navbar.md`, navbarContent)
2020-11-27 12:45:16 +00:00
if (!rootConfig) {
return
}
2020-11-27 12:45:16 +00:00
fs.copyFileSync(
`${templatesPath}/favicon.ico`,
`${destinationPath}/favicon.ico`
)
2020-11-27 12:45:16 +00:00
const indexTemplate = fs.readFileSync(
`${templatesPath}/index.html.handlebars`,
'utf8'
)
const indexContent = Handlebars.compile(indexTemplate)({
...supportedLanguage,
...supportedLanguages,
})
fs.writeFileSync(`${destinationPath}/index.html`, indexContent)
}