Compare commits
No commits in common. "a896a950013e5af6e9b66112f3c337d2587c4a87" and "1f864b0e0e48bd2ca3fdf31ec6421caa642bfe59" have entirely different histories.
a896a95001
...
1f864b0e0e
16
index.json
16
index.json
|
@ -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 v2",
|
"last_commit": "index auto gen",
|
||||||
"commit_date": "2025-05-22T16:41:20Z"
|
"commit_date": "2025-05-22T16:39:18Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"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 v2",
|
"last_commit": "index auto gen",
|
||||||
"commit_date": "2025-05-22T16:41:20Z"
|
"commit_date": "2025-05-22T16:39:18Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"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 v2",
|
"last_commit": "index auto gen",
|
||||||
"commit_date": "2025-05-22T16:41:20Z"
|
"commit_date": "2025-05-22T16:39:18Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"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 v2",
|
"last_commit": "index auto gen",
|
||||||
"commit_date": "2025-05-22T16:41:20Z"
|
"commit_date": "2025-05-22T16:39:18Z"
|
||||||
}
|
}
|
||||||
]
|
]
|
41
index_gen.py
41
index_gen.py
|
@ -1,38 +1,17 @@
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
def get_local_path_from_url(url):
|
def get_last_commit_info():
|
||||||
"""
|
# Format: subject%n%ISO 8601 date
|
||||||
Converts blog URL to local file path assuming structure:
|
|
||||||
https://.../src/branch/main/<file> --> blog/<file>
|
|
||||||
"""
|
|
||||||
path = urlparse(url).path
|
|
||||||
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(
|
result = subprocess.run(
|
||||||
["git", "log", "-1", "--pretty=%s%n%cI", "--", filepath],
|
["git", "log", "-1", "--pretty=%s%n%cI"],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL,
|
|
||||||
text=True,
|
text=True,
|
||||||
check=True
|
check=True
|
||||||
)
|
)
|
||||||
output = result.stdout.strip().split("\n")
|
message, date = result.stdout.strip().split("\n", 1)
|
||||||
if len(output) < 2:
|
return message, date
|
||||||
return "uncommitted or no history", "unknown"
|
|
||||||
return output[0], output[1]
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
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"- \[(.*?)\]\((.*?)\)")
|
||||||
|
@ -43,15 +22,11 @@ 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:
|
||||||
local_path = get_local_path_from_url(entry["url"])
|
entry["last_commit"] = last_commit_msg
|
||||||
if local_path:
|
entry["commit_date"] = commit_date
|
||||||
msg, date = get_commit_info(local_path)
|
|
||||||
else:
|
|
||||||
msg, date = "invalid url", "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