From a896a950013e5af6e9b66112f3c337d2587c4a87 Mon Sep 17 00:00:00 2001 From: glitchy Date: Thu, 22 May 2025 16:44:34 +0000 Subject: [PATCH] fuck gpt --- index_gen.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/index_gen.py b/index_gen.py index 07ecc00..d7096f7 100644 --- a/index_gen.py +++ b/index_gen.py @@ -5,14 +5,12 @@ from urllib.parse import urlparse def get_local_path_from_url(url): """ - Extracts the relative file path from the blog URL. - Assumes the file structure matches URLs. + Converts blog URL to local file path assuming structure: + https://.../src/branch/main/ --> blog/ """ - # 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 + path = urlparse(url).path parts = path.strip("/").split("/") - + try: idx = parts.index("main") relpath = "/".join(parts[idx + 1:]) @@ -25,13 +23,16 @@ def get_commit_info(filepath): result = subprocess.run( ["git", "log", "-1", "--pretty=%s%n%cI", "--", filepath], stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, text=True, check=True ) - msg, date = result.stdout.strip().split("\n", 1) - return msg, date + output = result.stdout.strip().split("\n") + if len(output) < 2: + return "uncommitted or no history", "unknown" + return output[0], output[1] except subprocess.CalledProcessError: - return "No commit info", "unknown" + return "uncommitted or error", "unknown" def parse_blog_links(md_text): pattern = re.compile(r"- \[(.*?)\]\((.*?)\)") @@ -47,11 +48,10 @@ def main(): 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" + msg, date = "invalid url", "unknown" + entry["last_commit"] = msg + entry["commit_date"] = date with open("index.json", "w", encoding="utf-8") as f: json.dump(blog_entries, f, indent=2)