fuck gpt
This commit is contained in:
parent
26603c215c
commit
a896a95001
26
index_gen.py
26
index_gen.py
|
@ -5,14 +5,12 @@ from urllib.parse import urlparse
|
||||||
|
|
||||||
def get_local_path_from_url(url):
|
def get_local_path_from_url(url):
|
||||||
"""
|
"""
|
||||||
Extracts the relative file path from the blog URL.
|
Converts blog URL to local file path assuming structure:
|
||||||
Assumes the file structure matches URLs.
|
https://.../src/branch/main/<file> --> blog/<file>
|
||||||
"""
|
"""
|
||||||
# e.g., https://git.xargana.tr/glitchy/blog/src/branch/main/blog_init.md
|
path = urlparse(url).path
|
||||||
# -> blog/blog_init.md
|
|
||||||
path = urlparse(url).path # /glitchy/blog/src/branch/main/blog_init.md
|
|
||||||
parts = path.strip("/").split("/")
|
parts = path.strip("/").split("/")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
idx = parts.index("main")
|
idx = parts.index("main")
|
||||||
relpath = "/".join(parts[idx + 1:])
|
relpath = "/".join(parts[idx + 1:])
|
||||||
|
@ -25,13 +23,16 @@ def get_commit_info(filepath):
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["git", "log", "-1", "--pretty=%s%n%cI", "--", filepath],
|
["git", "log", "-1", "--pretty=%s%n%cI", "--", filepath],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
text=True,
|
text=True,
|
||||||
check=True
|
check=True
|
||||||
)
|
)
|
||||||
msg, date = result.stdout.strip().split("\n", 1)
|
output = result.stdout.strip().split("\n")
|
||||||
return msg, date
|
if len(output) < 2:
|
||||||
|
return "uncommitted or no history", "unknown"
|
||||||
|
return output[0], output[1]
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return "No commit info", "unknown"
|
return "uncommitted or error", "unknown"
|
||||||
|
|
||||||
def parse_blog_links(md_text):
|
def parse_blog_links(md_text):
|
||||||
pattern = re.compile(r"- \[(.*?)\]\((.*?)\)")
|
pattern = re.compile(r"- \[(.*?)\]\((.*?)\)")
|
||||||
|
@ -47,11 +48,10 @@ def main():
|
||||||
local_path = get_local_path_from_url(entry["url"])
|
local_path = get_local_path_from_url(entry["url"])
|
||||||
if local_path:
|
if local_path:
|
||||||
msg, date = get_commit_info(local_path)
|
msg, date = get_commit_info(local_path)
|
||||||
entry["last_commit"] = msg
|
|
||||||
entry["commit_date"] = date
|
|
||||||
else:
|
else:
|
||||||
entry["last_commit"] = "unknown"
|
msg, date = "invalid url", "unknown"
|
||||||
entry["commit_date"] = "unknown"
|
entry["last_commit"] = msg
|
||||||
|
entry["commit_date"] = date
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue