From 0bdff97d09b5773d41c11c126944db0dec4be068 Mon Sep 17 00:00:00 2001 From: glitchy Date: Thu, 22 May 2025 16:39:18 +0000 Subject: [PATCH] index auto gen --- index.json | 18 ++++++++++++++++++ index_gen.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 index.json create mode 100644 index_gen.py diff --git a/index.json b/index.json new file mode 100644 index 0000000..41153fe --- /dev/null +++ b/index.json @@ -0,0 +1,18 @@ +[ + { + "title": "blog humble beginnings", + "url": "https://git.xargana.tr/glitchy/blog/src/branch/main/blog_init.md" + }, + { + "title": "security is annoying", + "url": "https://git.xargana.tr/glitchy/blog/src/branch/main/security_is_annoying.md" + }, + { + "title": "i dont really like school", + "url": "https://git.xargana.tr/glitchy/blog/src/branch/main/school_shit.md" + }, + { + "title": "twitter with an identity crisis", + "url": "https://git.xargana.tr/glitchy/blog/src/branch/main/mastodon_yap.md" + } +] \ No newline at end of file diff --git a/index_gen.py b/index_gen.py new file mode 100644 index 0000000..ad2681f --- /dev/null +++ b/index_gen.py @@ -0,0 +1,36 @@ +import re +import json +import subprocess + +def get_last_commit_info(): + # Format: subject%n%ISO 8601 date + result = subprocess.run( + ["git", "log", "-1", "--pretty=%s%n%cI"], + stdout=subprocess.PIPE, + text=True, + check=True + ) + message, date = result.stdout.strip().split("\n", 1) + return message, date + +def parse_blog_links(md_text): + pattern = re.compile(r"- \[(.*?)\]\((.*?)\)") + return [{"title": title, "url": url} for title, url in pattern.findall(md_text)] + +def main(): + with open("README.md", "r", encoding="utf-8") as f: + md_content = f.read() + + blog_entries = parse_blog_links(md_content) + last_commit_msg, commit_date = get_last_commit_info() + + for entry in blog_entries: + entry["last_commit"] = last_commit_msg + entry["commit_date"] = commit_date + + with open("index.json", "w", encoding="utf-8") as f: + json.dump(blog_entries, f, indent=2) + +if __name__ == "__main__": + main() +