macos-defaults/build/production/write-categories.js
Yann Bertrand 3eb3fa5605
♻️ Normalize templates
- Allow special chars in category name and page title
- Improve HTML image attributes readibility
- Prod: allow double quotes in category and page descriptions
2020-09-26 20:24:54 +02:00

25 lines
946 B
JavaScript

const fs = require('fs')
const Handlebars = require('handlebars')
Handlebars.registerHelper('escapeDoubleQuote', (string) => {
return string.replace(/"/g, '"')
})
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}`
)
}
})
}
}