summaryrefslogtreecommitdiff
path: root/build.py
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2021-08-27 03:08:43 +0100
committerdavidovski <david@sendula.com>2021-08-27 03:08:43 +0100
commit459fa8f48a8d91fe2ed7eb15b093c3346d17d129 (patch)
treedbce97edf0365812d920648030a5820e97a6b5c2 /build.py
parente6eaad2eb74de4c4992d98ad6ddd2a35523cef96 (diff)
new article, added background
Diffstat (limited to 'build.py')
-rw-r--r--build.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/build.py b/build.py
index 5e9a0c3..815a759 100644
--- a/build.py
+++ b/build.py
@@ -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)
)