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

View file

@ -1,17 +1,37 @@
import re import re
import json import json
import subprocess import subprocess
from urllib.parse import urlparse
def get_last_commit_info(): def get_local_path_from_url(url):
# Format: subject%n%ISO 8601 date """
result = subprocess.run( Extracts the relative file path from the blog URL.
["git", "log", "-1", "--pretty=%s%n%cI"], Assumes the file structure matches URLs.
stdout=subprocess.PIPE, """
text=True, # e.g., https://git.xargana.tr/glitchy/blog/src/branch/main/blog_init.md
check=True # -> blog/blog_init.md
) path = urlparse(url).path # /glitchy/blog/src/branch/main/blog_init.md
message, date = result.stdout.strip().split("\n", 1) parts = path.strip("/").split("/")
return message, date
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): def parse_blog_links(md_text):
pattern = re.compile(r"- \[(.*?)\]\((.*?)\)") pattern = re.compile(r"- \[(.*?)\]\((.*?)\)")
@ -22,11 +42,16 @@ def main():
md_content = f.read() md_content = f.read()
blog_entries = parse_blog_links(md_content) blog_entries = parse_blog_links(md_content)
last_commit_msg, commit_date = get_last_commit_info()
for entry in blog_entries: for entry in blog_entries:
entry["last_commit"] = last_commit_msg local_path = get_local_path_from_url(entry["url"])
entry["commit_date"] = commit_date 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: with open("index.json", "w", encoding="utf-8") as f:
json.dump(blog_entries, f, indent=2) json.dump(blog_entries, f, indent=2)