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):
|
||||
"""
|
||||
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/<file> --> blog/<file>
|
||||
"""
|
||||
# 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)
|
||||
|
|
Loading…
Reference in a new issue