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

47 lines
1.4 KiB
JavaScript
Raw Normal View History

const fs = require('fs')
const Handlebars = require('handlebars')
module.exports = ({ defaults, url }, templatesPath, destinationPath) => {
if (defaults.categories !== null) {
2020-11-27 12:45:16 +00:00
const pageTemplate = fs.readFileSync(
`${templatesPath}/page.md.handlebars`,
'utf8'
)
const renderPage = Handlebars.compile(pageTemplate)
defaults.categories.forEach(({ folder, name, keys }) => {
2020-11-27 12:45:16 +00:00
if (keys === undefined) {
return
}
keys.forEach(({ domain, ...page }) => {
2020-11-27 12:45:16 +00:00
const pageReadmeContent = renderPage({
...page,
folder,
name,
domain,
url,
})
fs.writeFileSync(
`${destinationPath}/${folder}/${page.key.toLowerCase()}.md`,
pageReadmeContent
)
2020-11-27 12:45:16 +00:00
page.examples.forEach((example) => {
if (example.image !== undefined) {
fs.copyFileSync(
`../../images/${folder}/${page.key}/${example.image.filename}`,
`${destinationPath}/${folder}/${folder}-${page.key}-${example.image.filename}`
)
}
if (example.video !== undefined) {
fs.copyFileSync(
`../../images/${folder}/${page.key}/${example.video.filename}`,
`${destinationPath}/${folder}/${folder}-${page.key}-${example.video.filename}`
)
}
})
})
})
}
}