index auto gen
This commit is contained in:
parent
ef5aaf8f0e
commit
0bdff97d09
18
index.json
Normal file
18
index.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
36
index_gen.py
Normal file
36
index_gen.py
Normal file
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue