1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
//Copyright Chris Xiong 2018
//License: Expat (MIT)
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;
}
|