commit e0afc82688d2b544397a029c81512ba1241a82e8 Author: davidovski Date: Sun Aug 8 03:59:47 2021 +0100 initial commit diff --git a/build.py b/build.py new file mode 100644 index 0000000..0f88612 --- /dev/null +++ b/build.py @@ -0,0 +1,88 @@ +import markdown +import os +import time +import shutil + +from const import * + +def getTemplateHTML(name): + html = "" + with open(os.path.join(templates, name), "r") as file: + html = file.read(); + return html + +def listPages(): + return [ + (lambda path: + (lambda content: + (lambda timestamp: + (lambda name: { + "source_file" : path, + "source_content" : content, + "html" : markdown.markdown(content), + "timestamp" : timestamp, + "date": time.strftime(date_format, time.localtime(timestamp)), + "name" : name, + "url" : f"entries/{name}.html" + })(".".join(p.split(".")[:-1])) + )(os.stat(path).st_ctime) + )(open(path, "r").read()) + )(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"])\ + .replace("%time%", str(page["timestamp"]))\ + .replace("%source%", site_index + page["source_file"])\ + .replace("%url%", site_index + page["url"]) + +def make(): + + shutil.rmtree(dist) + os.makedirs(os.path.join(dist, "entries")) + shutil.copytree(source, os.path.join(dist, "src")) + shutil.copytree(images, os.path.join(dist, "images")) + + pages = listPages() + + summary_templ = getTemplateHTML("summary.html") + + summariesHTML = "\n".join( + [ + formatEntry(summary_templ, page) + .replace( + "%content%", + "\n".join(page["html"].split("\n")[:10]) + ) + + for page in pages + ] + ) + + entry_templ = getTemplateHTML("page.html") + + for page in pages: + with open(os.path.join(dist, page["url"]), "w") as entry: + entry.write( + formatEntry( + entry_templ, + page + ) + .replace("%content%", page["html"]) + ) + + + + index_templ = getTemplateHTML("index.html") + + with open(os.path.join(dist, "index.html"), "w") as index: + index.write( + index_templ.replace("%entries%", summariesHTML) + ) + + +make() + + + diff --git a/const.py b/const.py new file mode 100644 index 0000000..bb5bfda --- /dev/null +++ b/const.py @@ -0,0 +1,7 @@ +site_index = "www.example.com/" +images = "images" +date_format = "%a, %d %b %Y" +source = "src" +templates = "templates" +dist = "dist" +summary_max = 10 diff --git a/new.sh b/new.sh new file mode 100755 index 0000000..60f377d --- /dev/null +++ b/new.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +EDITOR=nvim +TEMPFILE=/tmp/blog_entry.md + +$EDITOR $TEMPFILE + +NAME=src/$(head -1 $TEMPFILE | cut -d" " -f2-).md + +cp $TEMPFILE "$NAME" +rm $TEMPFILE +python build.py + +./sync.sh diff --git a/src/another blog entry.md b/src/another blog entry.md new file mode 100644 index 0000000..f642273 --- /dev/null +++ b/src/another blog entry.md @@ -0,0 +1,12 @@ +# another blog entry + +Another blog entry to test + +wow +thats pretty cool + +- things +- things and +- most +- importantly +- things diff --git a/src/test blog entry.md b/src/test blog entry.md new file mode 100644 index 0000000..df76307 --- /dev/null +++ b/src/test blog entry.md @@ -0,0 +1,3 @@ +# Test Blog entry + +this is a test blog entry for my blog diff --git a/src/test.md b/src/test.md new file mode 100644 index 0000000..6d85a7c --- /dev/null +++ b/src/test.md @@ -0,0 +1,2 @@ +# This is test markdown +- a test markdown document diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..d422ea9 --- /dev/null +++ b/sync.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +### +# your syncing script here +### diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..b97e88d --- /dev/null +++ b/templates/index.html @@ -0,0 +1,13 @@ + + + + + + + +

blog test

+
+ %entries% +
+ + diff --git a/templates/page.html b/templates/page.html new file mode 100644 index 0000000..4cb6980 --- /dev/null +++ b/templates/page.html @@ -0,0 +1,10 @@ + + + + + %name% + + + %content% + + diff --git a/templates/summary.html b/templates/summary.html new file mode 100644 index 0000000..062c582 --- /dev/null +++ b/templates/summary.html @@ -0,0 +1,7 @@ +
+ %content% + + ... + more +

Date: %date%

+