2020-09-20 09:16:08 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const Handlebars = require('handlebars')
|
|
|
|
|
2020-09-13 15:38:00 +00:00
|
|
|
Handlebars.registerHelper('escapeDoubleQuote', (string) => {
|
|
|
|
return string.replace(/"/g, '"')
|
|
|
|
})
|
|
|
|
|
2020-09-13 19:28:38 +00:00
|
|
|
module.exports = ({ defaults, url }, templatesPath, destinationPath) => {
|
2020-09-20 09:16:08 +00:00
|
|
|
if (defaults.categories !== null) {
|
2020-09-13 13:24:51 +00:00
|
|
|
const pageTemplate = fs.readFileSync(`${templatesPath}/page.md.handlebars`, 'utf8')
|
2020-09-20 09:16:08 +00:00
|
|
|
const renderPage = Handlebars.compile(pageTemplate)
|
|
|
|
defaults.categories.forEach(({ folder, name, keys }) => {
|
|
|
|
if (keys === undefined) { return }
|
|
|
|
|
|
|
|
keys.forEach(({ domain, ...page }) => {
|
2020-09-13 19:28:38 +00:00
|
|
|
const pageReadmeContent = renderPage({ ...page, folder, name, domain, url })
|
2020-10-03 13:41:02 +00:00
|
|
|
fs.writeFileSync(`${destinationPath}/${folder}/${page.key.toLowerCase()}.md`, pageReadmeContent)
|
2020-09-20 09:16:08 +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}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|