-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgenerateHtmlCheatSheet.js
20 lines (16 loc) · 1.03 KB
/
generateHtmlCheatSheet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const fs = require('fs')
const path = require('path')
const Handlebars = require('handlebars')
const cheatSheetTemplatePath = path.resolve(__dirname, './handlebars/cheatSheet.handlebars')
const cheatSheetTemplate = fs.readFileSync(cheatSheetTemplatePath, 'utf8')
const fillCheatSheetTemplate = Handlebars.compile(cheatSheetTemplate)
const cheatSheetSectionTemplatePath = path.resolve(__dirname, './handlebars/cheatSheetSection.handlebars')
const cheatSheetSectionTemplate = fs.readFileSync(cheatSheetSectionTemplatePath, 'utf8')
const fillCheatSheetSectionTemplate = Handlebars.compile(cheatSheetSectionTemplate)
const generateHTMLCheatSheet = cheatSheetData => {
const sectionsString = cheatSheetData.sections.map(sectionObject => fillCheatSheetSectionTemplate(sectionObject)).join('')
const content = fillCheatSheetTemplate({ ...cheatSheetData, sections: sectionsString })
fs.writeFileSync(`build/html/${cheatSheetData.file}`, content)
fs.writeFileSync(`${cheatSheetData.file}.html`, content)
}
module.exports = generateHTMLCheatSheet