macos-defaults/build/vuepress/write-categories.js

32 lines
973 B
JavaScript
Raw Normal View History

const fs = require('fs')
const Handlebars = require('handlebars')
2020-10-03 13:41:02 +00:00
Handlebars.registerHelper('lowerCase', (string) => {
return string.toLowerCase()
})
module.exports = (defaults, templatesPath, destinationPath) => {
if (defaults.categories !== null) {
2020-11-27 12:45:16 +00:00
const categoryTemplate = fs.readFileSync(
`${templatesPath}/category.md.handlebars`,
'utf8'
)
const renderCategory = Handlebars.compile(categoryTemplate)
2020-11-27 12:45:16 +00:00
defaults.categories.forEach((category) => {
fs.mkdirSync(`${destinationPath}/${category.folder}`)
const categoryReadmeContent = renderCategory(category)
2020-11-27 12:45:16 +00:00
fs.writeFileSync(
`${destinationPath}/${category.folder}/readme.md`,
categoryReadmeContent
)
if (category.image !== undefined) {
fs.copyFileSync(
`../../images/${category.folder}/${category.image.filename}`,
`${destinationPath}/${category.folder}/${category.image.filename}`
)
}
})
}
}