aboutsummaryrefslogtreecommitdiff
path: root/generator
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2018-12-09 10:52:50 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2018-12-09 10:52:50 +0800
commitedd8aa6e058d12dd0f9b0b886e507bd73dce72cb (patch)
treeb2c778c0a3e2f269207de65543ee289b95fa404d /generator
parenta846e514aa281059f8b207823d1ff7612b89b768 (diff)
downloadsbs-edd8aa6e058d12dd0f9b0b886e507bd73dce72cb.tar.xz
Load images asynchronously.
Fix line endings in templates. Apply theme color.
Diffstat (limited to 'generator')
-rwxr-xr-x[-rw-r--r--]generator/main.js1
-rw-r--r--generator/postrenderer.js15
2 files changed, 12 insertions, 4 deletions
diff --git a/generator/main.js b/generator/main.js
index ccdc380..e25d5f2 100644..100755
--- a/generator/main.js
+++ b/generator/main.js
@@ -1,3 +1,4 @@
+#!/usr/bin/node
//Copyright Chris Xiong 2018
//License: Expat (MIT)
const content_dir='../content';
diff --git a/generator/postrenderer.js b/generator/postrenderer.js
index 8797c22..e387691 100644
--- a/generator/postrenderer.js
+++ b/generator/postrenderer.js
@@ -133,18 +133,25 @@ async function _render(inf,outf,np,pp)
await encrypt(trd);
//TOC
- const l=trd.getElementById('article').querySelectorAll('h2,h3,h4,h5,h6');
- const tocroot=trd.getElementById('tocroot');
tocid=0;
headerlist=[];
- for(let i of l)
- if(!i.classList.contains('notoc'))headerlist.push(i);
+ trd.getElementById('article').querySelectorAll('h2,h3,h4,h5,h6').forEach(
+ (i)=>{if(!i.classList.contains('notoc'))headerlist.push(i);}
+ );
+ const tocroot=trd.getElementById('tocroot');
for(let i=0;i<headerlist.length;)i=_dfs(trd,headerlist[i],tocroot,i);
if(!tocroot.children.length)trd.getElementById('tocouter').style.display='none';
//Footnotes
footnoter(trd);
+ //async images
+ //TODO: Actually compress the images using imagemagick
+ //(by introducing a new tag e.g. <thumb> ?)
+ trd.getElementById('article').querySelectorAll('img').forEach(
+ (i)=>{if(!i.getAttribute('decoding'))i.setAttribute('decoding','async');}
+ );
+
//Tag list
const tgs=meta[2].split(',');
for(let i=0;i<tgs.length;++i)