-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile_additional_pages.py
More file actions
98 lines (76 loc) · 2.98 KB
/
compile_additional_pages.py
File metadata and controls
98 lines (76 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import yaml
import subprocess
from pathlib import Path
import re
import unicodedata
def slugify(value):
"""Convert title to URL-friendly slug"""
value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
value = re.sub(r"[^\w\s-]", "", value.lower())
return re.sub(r"[-\s]+", "-", value).strip("-_")
def update_post_permalink(post_path):
try:
lines = post_path.read_text(encoding='utf-8').splitlines()
if not lines or lines[0].strip() != '---':
print(f"❌ Skipping {post_path.name}: No front matter found")
return
# Find the end of the front matter
end_index = None
for i, line in enumerate(lines[1:], start=1):
if line.strip() == '---':
end_index = i
break
if end_index is None:
print(f"❌ Skipping {post_path.name}: Unterminated front matter")
return
front_lines = lines[1:end_index]
body_lines = lines[end_index+1:]
front_matter = yaml.safe_load('\n'.join(front_lines)) or {}
title = front_matter.get("title")
in_collections = front_matter.get("in_collections", [])
if "permalink" in front_matter and front_matter["permalink"]:
print(f"✔️ Skipping {post_path.name}: Permalink already set")
return
if not title or not in_collections:
print(f"❌ Skipping {post_path.name}: Missing title or in_collections")
return
collection_slug = in_collections[0]
title_slug = slugify(title)
permalink = f"/{collection_slug}/{title_slug}/"
# Insert permalink just before the closing ---
permalink_line = f"permalink: {permalink}"
front_lines.append(permalink_line)
new_content = "\n".join(['---'] + front_lines + ['---'] + body_lines) + "\n"
post_path.write_text(new_content, encoding='utf-8')
subprocess.run(['git', 'add', str(post_path)], check=True)
print(f"✅ Added permalink to {post_path.name}")
except Exception as e:
print(f"⚠️ Error processing {post_path.name}: {e}")
# === Update Post Permalinks ===
posts_dir = Path('_posts')
for post_file in posts_dir.rglob('*.md'):
if re.match(r'^\d{4}-\d{1,2}-\d{1,2}-', post_file.name):
update_post_permalink(post_file)
import yaml
import subprocess
from pathlib import Path
# Load author data
with open('_data/authors.yml', 'r') as f:
authors = yaml.safe_load(f)
# Output directory
output_dir = Path('_pages/authors')
output_dir.mkdir(parents=True, exist_ok=True)
# Generate .md file for each author
for key, data in authors.items():
md_path = output_dir / f"{key}.md"
# Write the file
with open(md_path, 'w') as f:
f.write(f"""---
layout: default
title: "{data.get('name', key)}"
permalink: /author/{key}/
---
{{% include display_author_projects.html author="{key}" %}}
""")
# Add file to git
subprocess.run(['git', 'add', str(md_path)], check=True)