aboutsummaryrefslogtreecommitdiff
path: root/generator/scanner.js
diff options
context:
space:
mode:
Diffstat (limited to 'generator/scanner.js')
-rw-r--r--generator/scanner.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/generator/scanner.js b/generator/scanner.js
new file mode 100644
index 0000000..0817cdb
--- /dev/null
+++ b/generator/scanner.js
@@ -0,0 +1,53 @@
+module.exports={
+ scan:function(s,d){return _scan(s,d);},
+ build_list_index:function(){return _build_list_index();}
+};
+const fs=require('fs');
+const path=require('path');
+const list=[];
+const tags=[];
+function _scan(s,dst)
+{
+ list.splice(0);
+ d=fs.readdirSync(s).reverse();
+ pdst=path.join(dst,'post');
+ let poste=true;
+ try{
+ st=fs.statSync(pdst);
+ if(!st.isDirectory)throw 'shit';
+ }catch(e){poste=false;}
+ for(let i of d)
+ if(i.endsWith('.txt'))
+ {
+ const cont=fs.readFileSync(path.join(s,i),'utf8');
+ const smodt=fs.statSync(path.join(s,i)).mtimeMs;
+ let dmodt=0;
+ try{
+ dmodt=fs.statSync(path.join(pdst,i.substring(0,i.length-4)+'.html')).mtimeMs;
+ }catch(e){};
+ contsplit=cont.split('\n');
+ if(contsplit.length<4)continue;
+ if(contsplit[1].indexOf('WIP')!=-1)continue;
+ list.push({
+ file:i.substring(0,i.length-4),
+ title:contsplit[0].trim(),
+ date:contsplit[1].trim(),
+ tags:contsplit[2].trim(),
+ mdate:smodt,
+ needsupdate:dmodt<smodt
+ });
+
+ }
+ return list;
+}
+function _build_list_index()
+{
+ for(let i of list)
+ for(let tg of i.tags.split(','))
+ {
+ if(!tags[tg])tags[tg]={posts:[],needsupdate:false};
+ tags[tg].posts.push(i);
+ tags[tg].needsupdate|=i.needsupdate;
+ }
+ return tags;
+}