fsfi

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 1d74a74ad8dfee22ecffd91d2410258eb77613cd
parent b577131d5b9b718460d4a645f21f0829f0694111
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 18 May 2019 15:41:36 -0400

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:
bin/html | 38++++++++++++++++++++------------------
templates/html/news.html | 4++--
2 files changed, 22 insertions(+), 20 deletions(-)

diff --git 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__": diff --git a/templates/html/news.html b/templates/html/news.html @@ -1,7 +1,7 @@ <!--#include virtual="/includes/html-open.html"--> <!--#include virtual="/includes/header-open.html"--> -<title><!-- NEWS-ITEM-TITLE --> &mdash; News &mdash; Free Software Foundation India</title> +<title><!-- ITEM-TITLE --> &mdash; News &mdash; Free Software Foundation India</title> <!--#include virtual="/includes/header-close.html"--> <!--#include virtual="/includes/body-open.html"--> @@ -15,7 +15,7 @@ <div class="header"> <hgroup> <h1><span class="tag is-medium">News</span></h1> - <h2><!-- NEWS-ITEM-TITLE --></h2> + <h2><!-- ITEM-TITLE --></h2> </hgroup> </div>