From 2e8c6dfd876d25a00897e05ae2883a47f79d3eea Mon Sep 17 00:00:00 2001 From: neodarz <neodarz@neodarz.net> Date: Sun, 26 May 2019 12:38:04 +0200 Subject: Move postprocess_html_file function to external file --- pyblog | 18 +----------------- utils/utils.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pyblog b/pyblog index ec028c53..30103491 100755 --- a/pyblog +++ b/pyblog @@ -766,22 +766,6 @@ def generate_index_and_feed(): generate_sitemap(feed) -def postprocess_html_file(htmlfilepath): - """Perform a series of postprocessing to an HTML file.""" - with open(htmlfilepath, "r+", encoding="utf-8") as htmlfileobj: - soup = bs4.BeautifulSoup(htmlfileobj.read(), "lxml") - - # a series of postprocessing (extensible) - utils.process_image_sizes(soup) - utils.link_img_tags(soup) - utils.process_footnote_backlinks(soup) - - # write back - htmlfileobj.seek(0) - htmlfileobj.write(str(soup)) - htmlfileobj.truncate() - - def static_vars(**kwargs): def decorate(func): for k in kwargs: @@ -917,7 +901,7 @@ def generate_blog(fresh=False, report_total_errors=True): sys.stderr.write("error: failed to generate %s" % relpath) # postprocess generated HTML file - postprocess_html_file(dstpath) + utils.postprocess_html_file(dstpath) if anything_modified: generate_index_and_feed() diff --git a/utils/utils.py b/utils/utils.py index f8cb8ef6..1cabbdc8 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -177,3 +177,19 @@ def process_footnote_backlinks(soup): tag.string == "\u21A9"): # U+21A9: LEFTWARDS ARROW WITH HOOK fn_a_tag["class"] = "footnotes-backlink" fn_a_tag.string = "\u21A9\uFE0E" # U+FE0E: VARIATION SELECTOR-15 + + +def postprocess_html_file(htmlfilepath): + """Perform a series of postprocessing to an HTML file.""" + with open(htmlfilepath, "r+", encoding="utf-8") as htmlfileobj: + soup = bs4.BeautifulSoup(htmlfileobj.read(), "lxml") + + # a series of postprocessing (extensible) + process_image_sizes(soup) + link_img_tags(soup) + process_footnote_backlinks(soup) + + # write back + htmlfileobj.seek(0) + htmlfileobj.write(str(soup)) + htmlfileobj.truncate() -- cgit v1.2.1