From 779aaa764cb26f02da56e60bb903afc9442f5f1c Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 11 Oct 2018 18:39:34 +0800 Subject: Initial commit. --- generator/main.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 generator/main.js (limited to 'generator/main.js') diff --git a/generator/main.js b/generator/main.js new file mode 100644 index 0000000..0d86ca5 --- /dev/null +++ b/generator/main.js @@ -0,0 +1,86 @@ +const content_dir='../content'; +const template_dir='../templates'; +const dest_dir='../generated'; +const posts_per_listpage=5; + +const fs=require('fs'); +const path=require('path'); + +const scanner=require('./scanner'); +const list=scanner.scan(content_dir,dest_dir); +const tags=scanner.build_list_index(); +const taglist=Object.keys(tags).sort(); +const force=process.argv.indexOf('--force')!=-1; + +const postrenderer=require('./postrenderer'); +postrenderer.set_template(path.join(template_dir,'post_template')); + +function ensure_dir(p) +{ + let needcreation=false; + try{ + if(!fs.statSync(p).isDirectory()) + { + needcreation=true; + fs.unlinkSync(p); + } + }catch(e){needcreation=true;} + if(needcreation)fs.mkdirSync(p); + if(!fs.statSync(p).isDirectory())throw 'shit'; +} + +const post_dir=path.join(dest_dir,'post'); +ensure_dir(post_dir); +for(let j=0;j{console.log(`rendered: ${r}`);}) +} + +const listrenderer=require('./listrenderer'); +listrenderer.set_template(path.join(template_dir,'list_template')); + +const list_dir=path.join(dest_dir,'list'); +const ppp=posts_per_listpage; +ensure_dir(list_dir); +let pc=Math.floor(list.length/ppp)+(list.length%ppp!=0); +for(let i=0;i