summaryrefslogtreecommitdiffstats
path: root/bin/html
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-05-18 15:41:36 -0400
committerrsiddharth <s@ricketyspace.net>2019-05-18 15:41:36 -0400
commit1d74a74ad8dfee22ecffd91d2410258eb77613cd (patch)
tree7118d74ebd1a8bb1c78bee0cc22eeaac339c3d2e /bin/html
parentb577131d5b9b718460d4a645f21f0829f0694111 (diff)
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.
Diffstat (limited to 'bin/html')
-rw-r--r--bin/html38
1 files changed, 20 insertions, 18 deletions
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': '<!-- NEWS-ITEM-TITLE -->',
+ 'title': '<!-- ITEM-TITLE -->',
'date': '<!-- DATE -->',
'content': '<!-- MAIN-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__":