macos-defaults/build/production/write-categories.js
Cameron Little 32cf426956 Add support for spaces (and other specials) in keys
Currently, page url generation (slugification) is just toLowerCase. In https://github.com/yannbertrand/macos-defaults/pull/146 I add some defaults that contain keys with spaces, which currently breaks.

This pulls in `slugify` to add support, and shell escapes keys in examples.
2021-04-06 20:53:41 +02:00

27 lines
886 B
JavaScript

const fs = require('fs')
const Handlebars = require('handlebars')
module.exports = (defaults, templatesPath, destinationPath) => {
if (defaults.categories !== null) {
const categoryTemplate = fs.readFileSync(
`${templatesPath}/category.md.handlebars`,
'utf8'
)
const renderCategory = Handlebars.compile(categoryTemplate)
defaults.categories.forEach((category) => {
fs.mkdirSync(`${destinationPath}/${category.folder}`)
const categoryReadmeContent = renderCategory(category)
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}`
)
}
})
}
}