i love chatgpt

This commit is contained in:
glitchy 2025-05-22 16:42:46 +00:00
parent 1f864b0e0e
commit 26603c215c
2 changed files with 46 additions and 21 deletions

View file

@ -2,25 +2,25 @@
{
"title": "blog humble beginnings",
"url": "https://git.xargana.tr/glitchy/blog/src/branch/main/blog_init.md",
"last_commit": "index auto gen",
"commit_date": "2025-05-22T16:39:18Z"
"last_commit": "index auto gen v2",
"commit_date": "2025-05-22T16:41:20Z"
},
{
"title": "security is annoying",
"url": "https://git.xargana.tr/glitchy/blog/src/branch/main/security_is_annoying.md",
"last_commit": "index auto gen",
"commit_date": "2025-05-22T16:39:18Z"
"last_commit": "index auto gen v2",
"commit_date": "2025-05-22T16:41:20Z"
},
{
"title": "i dont really like school",
"url": "https://git.xargana.tr/glitchy/blog/src/branch/main/school_shit.md",
"last_commit": "index auto gen",
"commit_date": "2025-05-22T16:39:18Z"
"last_commit": "index auto gen v2",
"commit_date": "2025-05-22T16:41:20Z"
},
{
"title": "twitter with an identity crisis",
"url": "https://git.xargana.tr/glitchy/blog/src/branch/main/mastodon_yap.md",
"last_commit": "index auto gen",
"commit_date": "2025-05-22T16:39:18Z"
"last_commit": "index auto gen v2",
"commit_date": "2025-05-22T16:41:20Z"
}
]

View file

@ -1,17 +1,37 @@
import re
import json
import subprocess
from urllib.parse import urlparse
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 get_local_path_from_url(url):
"""
Extracts the relative file path from the blog URL.
Assumes the file structure matches URLs.
"""
# e.g., https://git.xargana.tr/glitchy/blog/src/branch/main/blog_init.md
# -> blog/blog_init.md
path = urlparse(url).path # /glitchy/blog/src/branch/main/blog_init.md
parts = path.strip("/").split("/")
try:
idx = parts.index("main")
relpath = "/".join(parts[idx + 1:])
return f"blog/{relpath}"
except ValueError:
return None
def get_commit_info(filepath):
try:
result = subprocess.run(
["git", "log", "-1", "--pretty=%s%n%cI", "--", filepath],
stdout=subprocess.PIPE,
text=True,
check=True
)
msg, date = result.stdout.strip().split("\n", 1)
return msg, date
except subprocess.CalledProcessError:
return "No commit info", "unknown"
def parse_blog_links(md_text):
pattern = re.compile(r"- \[(.*?)\]\((.*?)\)")
@ -22,11 +42,16 @@ def main():
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
local_path = get_local_path_from_url(entry["url"])
if local_path:
msg, date = get_commit_info(local_path)
entry["last_commit"] = msg
entry["commit_date"] = date
else:
entry["last_commit"] = "unknown"
entry["commit_date"] = "unknown"
with open("index.json", "w", encoding="utf-8") as f:
json.dump(blog_entries, f, indent=2)