diff options
author | davidovski <david@sendula.com> | 2021-08-27 03:08:43 +0100 |
---|---|---|
committer | davidovski <david@sendula.com> | 2021-08-27 03:08:43 +0100 |
commit | 372855459a5cb707a1cdbc6d7adb12177afbf44b (patch) | |
tree | dbce97edf0365812d920648030a5820e97a6b5c2 /build.py | |
parent | 16b00548ec80b58c4e9a2c14acb2c0b713fd5592 (diff) |
new article, added background
Diffstat (limited to 'build.py')
-rw-r--r-- | build.py | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -11,6 +11,21 @@ def getTemplateHTML(name): html = file.read(); return html +def lowerHeadings(html): + # This is a dumb lol + return html.replace("<h6>", "<p>")\ + .replace("</h6>", "</p>")\ + .replace("<h5>", "<h6>")\ + .replace("</h5>", "</h6>")\ + .replace("<h4>", "<h5>")\ + .replace("</h4>", "</h5>")\ + .replace("<h3>", "<h4>")\ + .replace("</h3>", "</h4>")\ + .replace("<h2>", "<h3>")\ + .replace("</h2>", "</h3>")\ + .replace("<h1>", "<h2>")\ + .replace("</h1>", "</h2>")\ + def listPages(): return [ (lambda path: @@ -19,7 +34,8 @@ def listPages(): (lambda name: { "source_file" : path, "source_content" : content, - "html" : markdown.markdown(content), + "html" : markdown.markdown("\n".join(content.split("\n...\n"))), + "summary" : lowerHeadings(markdown.markdown(content.split("\n...\n")[0])), "timestamp" : timestamp, "date": time.strftime(date_format, time.localtime(timestamp)), "name" : name, @@ -30,6 +46,7 @@ def listPages(): )(os.path.join(source, p)) for p in os.listdir(source) ] + def formatEntry(content, page): return content.replace("%date%", page["date"])\ .replace("%name%", page["name"])\ @@ -52,16 +69,16 @@ def make(): summary_templ = getTemplateHTML("summary.html") - summariesHTML = "\n".join( - [ - formatEntry(summary_templ, page) - .replace( - "%content%", - "\n".join(page["html"].split("\n")[:summary_max]) - ) + summariesHTML = getTemplateHTML("about.html") + "\n<hr>\n"+ "\n<hr>\n".join( + [ + formatEntry(summary_templ, page) + .replace( + "%content%", + page["summary"] + (f"<a href={page['url']}>read more...</a>" if len(page["source_content"].split("\n...\n")) > 1 else "") + ) - for page in pages - ] + for page in pages + ][: : -1] ) entry_templ = getTemplateHTML("page.html") @@ -78,11 +95,11 @@ def make(): - index_templ = getTemplateHTML("index.html") + index_templ = getTemplateHTML("page.html") with open(os.path.join(dist, "index.html"), "w") as index: index.write( - index_templ.replace("%entries%", summariesHTML) + index_templ.replace("%content%", summariesHTML) ) |