diff options
author | metamuffin <metamuffin@disroot.org> | 2025-10-03 23:14:58 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-10-03 23:14:58 +0200 |
commit | 5c92840108a05f0f311d5bef2d6512579b593438 (patch) | |
tree | 2f564a598380f00f53fa02f6dc3433cbddb0909b | |
parent | 8444803182573e59414ebcbc4bec9da36aeac451 (diff) | |
download | metamuffin-website-5c92840108a05f0f311d5bef2d6512579b593438.tar metamuffin-website-5c92840108a05f0f311d5bef2d6512579b593438.tar.bz2 metamuffin-website-5c92840108a05f0f311d5bef2d6512579b593438.tar.zst |
read title from h1
-rw-r--r-- | process.py | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -11,18 +11,21 @@ PROCESSORS = { } def run_pi(input: str) -> str: - RE_PI = r"(?sm)\<\?(?P<n>\w+)\W(?P<b>.*?)\?\>" + RE_PI = r"(?sm)<\?(?P<name>\w+)\W(?P<body>.*?)\?>" def run_pi_match(m: re.Match): - name = m.group("n") - body = m.group("b") + name = m.group("name") + body = m.group("body") print(f"({name})$ {body}") output = PROCESSORS[name](body) return output return re.sub(RE_PI, run_pi_match, input) def template(input: str) -> str: + RE_TITLE = r"<h1>(?P<title>.*?)</h1>" + title_match = re.match(RE_TITLE, input) + title = title_match.group(1) if title_match != None else "no title :(" tpl = open("template.html", "r").read() - return tpl.replace("CONTENT", input).replace("TITLE", "TODO TITLE") + return tpl.replace("CONTENT", input).replace("TITLE", title) doc = open(argv[1], "r").read() doc = markdown(doc) |