summarybugs & patchesrefslogtreecommitdiffstats
path: root/tools/gen.py
diff options
context:
space:
mode:
authorVosjedev <vosje@vosjedev.net>2026-02-08 16:58:37 +0100
committerVosjedev <vosje@vosjedev.net>2026-02-08 16:58:37 +0100
commitc6f203b9f035f54cecbb20450a309cb0596ccfff (patch)
tree85eb24b747f2e3bb0919d66b892e8cacd166ad08 /tools/gen.py
downloadwebsite-c6f203b9f035f54cecbb20450a309cb0596ccfff.tar.gz
website-c6f203b9f035f54cecbb20450a309cb0596ccfff.tar.bz2
website-c6f203b9f035f54cecbb20450a309cb0596ccfff.tar.xz
WTF am I doing atp
Diffstat (limited to 'tools/gen.py')
-rw-r--r--tools/gen.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/tools/gen.py b/tools/gen.py
new file mode 100644
index 0000000..e2f65e1
--- /dev/null
+++ b/tools/gen.py
@@ -0,0 +1,80 @@
+import os, shutil
+from discord_md import md
+import json
+from collections import UserDict
+
+class IgnoreUnfoundPlaceholders(UserDict):
+ """Wrapper around dicts for using in str.format()
+ It basically tries to lookup the key it gets, and if the key doesn't exist,
+ it returns ``{keyname}`` where ``keyname`` is the key it got
+ """
+ def __missing__(self, key):
+ return "{%s}"%str(key)
+
+# with open("conf.json", "r") as fd:
+# conf=json.load(fd)
+
+with open("html/footer.html","r") as fd:
+ footer=fd.read()
+
+with open("html/header.html","r") as fd:
+ header=fd.read()
+
+with open("html/pagetemplate.html","r") as fd:
+ template=fd.read()
+
+template=template.format_map(
+ IgnoreUnfoundPlaceholders(header=header, footer=footer)
+)
+
+if os.path.isdir("out"):
+ shutil.rmtree("out")
+
+out=os.path.abspath('out')
+os.makedirs(out)
+os.symlink(os.path.abspath("static"), os.path.join(out,"static"), True)
+#os.chdir("content")
+
+def processdir(path):
+ print("processing",path)
+ os.chdir(path)
+ parent=os.path.dirname(path)
+ for file in os.listdir():
+ if file.endswith(".md"):
+
+ with open(file, "r") as fd:
+ print("| reading",file)
+ text=md.convert(fd.read())
+
+ meta:dict=md.Meta
+ print("Meta:",meta)
+ section=meta.get("section",[""])[0]
+
+ html=template.format(
+ title=meta.get("title",["<No title>"])[0] + (" - "+section if section else ''),
+ section=section,
+ content=text,
+ toc=md.toc if not meta.get("notoc") else ""
+ )
+
+ newname=file.removesuffix(".md")+".html"
+ newname=newname.replace("README","index")
+
+ target=os.path.join(out, section)
+ if not os.path.isdir(target):
+ os.makedirs(target)
+
+ with open(os.path.join(out, section, newname), "x") as fd:
+ print("| writing")
+ fd.write(html)
+
+ elif os.path.isdir(file):
+ processdir(os.path.join(path,file))
+
+ else:
+ shutil.copy2(file, os.path.join(out, os.path.basename(path)))
+
+ os.chdir(parent)
+
+processdir("./content")
+