|
@@ -1,57 +1,30 @@
|
|
#!/usr/bin/env node
|
|
#!/usr/bin/env node
|
|
|
|
|
|
const _fs = require('fs-magic');
|
|
const _fs = require('fs-magic');
|
|
-const _ejs = require('ejs');
|
|
|
|
const _path = require('path');
|
|
const _path = require('path');
|
|
const _assetsPath = _path.join(__dirname, '../assets');
|
|
const _assetsPath = _path.join(__dirname, '../assets');
|
|
const _langPath = _path.join(__dirname, '../i18n');
|
|
const _langPath = _path.join(__dirname, '../i18n');
|
|
const _cli = require('commander');
|
|
const _cli = require('commander');
|
|
const _pkg = require('../package.json');
|
|
const _pkg = require('../package.json');
|
|
|
|
+const _pageRenderer = require('../lib/page-renderer');
|
|
|
|
+const _jsonReader = require('../lib/json-reader');
|
|
|
|
|
|
// global paths
|
|
// global paths
|
|
let templatePath = null;
|
|
let templatePath = null;
|
|
let cssPath = null;
|
|
let cssPath = null;
|
|
|
|
|
|
-// render template using given data
|
|
|
|
-async function renderTemplate(data={}){
|
|
|
|
- // fetch css
|
|
|
|
- data.inlinecss = await _fs.readFile(cssPath, 'utf8');
|
|
|
|
-
|
|
|
|
- // fetch template
|
|
|
|
- const tpl = await _fs.readFile(templatePath, 'utf8');
|
|
|
|
-
|
|
|
|
- // render template - use custom escape function to handle linebreaks!
|
|
|
|
- return _ejs.render(tpl, data, {
|
|
|
|
- escape: function(text){
|
|
|
|
- // apply generic escape function
|
|
|
|
- text = _ejs.escapeXML(text);
|
|
|
|
-
|
|
|
|
- // linebreaks
|
|
|
|
- text = text.replace(/\n/g, '<br />');
|
|
|
|
-
|
|
|
|
- return text;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// parse json file and allow single line comments
|
|
|
|
-async function readJSONFile(filename){
|
|
|
|
- // load file
|
|
|
|
- let raw = await _fs.readFile(filename, 'utf8');
|
|
|
|
-
|
|
|
|
- // strip single line js comments
|
|
|
|
- raw = raw.replace(/^\s*\/\/.*$/gm, '');
|
|
|
|
-
|
|
|
|
- // parse text
|
|
|
|
- return JSON.parse(raw);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
async function generator(configFilename, pageDefinitionFile, distPath){
|
|
async function generator(configFilename, pageDefinitionFile, distPath){
|
|
// load config
|
|
// load config
|
|
- const config = await readJSONFile(configFilename);
|
|
|
|
|
|
+ const config = await _jsonReader(configFilename);
|
|
|
|
|
|
// load page definitions
|
|
// load page definitions
|
|
- const pages = await readJSONFile(pageDefinitionFile);
|
|
|
|
|
|
+ const pages = await _jsonReader(pageDefinitionFile);
|
|
|
|
+
|
|
|
|
+ // load template
|
|
|
|
+ const tpl = await _fs.readFile(templatePath, 'utf8');
|
|
|
|
+
|
|
|
|
+ // load css
|
|
|
|
+ const css = await _fs.readFile(cssPath, 'utf8');
|
|
|
|
|
|
console.log('Generating static pages');
|
|
console.log('Generating static pages');
|
|
|
|
|
|
@@ -67,7 +40,7 @@ async function generator(configFilename, pageDefinitionFile, distPath){
|
|
pconf.footer = pconf.footer || config.footer;
|
|
pconf.footer = pconf.footer || config.footer;
|
|
|
|
|
|
// render page
|
|
// render page
|
|
- const content = await renderTemplate(pconf);
|
|
|
|
|
|
+ const content = await _pageRenderer(tpl, css, pconf);
|
|
|
|
|
|
// generate filename
|
|
// generate filename
|
|
const filename = 'HTTP' + p + '.html';
|
|
const filename = 'HTTP' + p + '.html';
|