From 1d74a74ad8dfee22ecffd91d2410258eb77613cd Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 18 May 2019 15:41:36 -0400 Subject: bin: Refactor html. Update html to generate html for all sections written in markdown (news, articles). * bin/html (SECTIONS): New variable. (files): Add arg `sec`. (html, process): Rewrite functions. (run): Process different sections. * templates/html/news.html: Template NEW-ITEM-TITLE -> ITEM-TITLE. --- bin/html | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'bin/html') diff --git a/bin/html b/bin/html index c12b9bc..a317359 100644 --- a/bin/html +++ b/bin/html @@ -13,9 +13,11 @@ import subprocess as subp import sys +SECTIONS = ['news'] + # placeholders PH = { - 'title': '', + 'title': '', 'date': '', 'content': '', } @@ -35,8 +37,8 @@ def fok(f): return True -def files(): - files = os.scandir('md/news') +def files(sec): + files = os.scandir('md' + '/' + sec) fs = [] for f in files: @@ -121,31 +123,31 @@ def markdown(c): return r.stdout -def html(t, d, c): - h = template('news') - h = h.replace(PH['title'], t, 2) - h = h.replace(PH['date'], datefmt(d), 1) - h = h.replace(PH['content'], markdown(c), 1) - - return h - - -def process(f): +def html(sec, f): c = read(f.path) - s = slug(f.path) + t = title(c) d = date(c) c = content(c) - h = html(t, d, c) + h = template(sec) + h = h.replace(PH['title'], t, 2) + h = h.replace(PH['date'], datefmt(d), 1) + h = h.replace(PH['content'], markdown(c), 1) + + return s, h + - write('/'.join(['_build', 'news', s, 'index.html']), h) +def process(sec): + for f in files(sec): + s, h = html(sec, f) + write('/'.join(['_build', sec, s, 'index.html']), h) def run(): - for f in files(): - process(f) + for sec in SECTIONS: + process(sec) if __name__ == "__main__": -- cgit v1.2.3