Skip to content

Commit 0d9451d

Browse files
committed
fix redirects
1 parent 0551989 commit 0d9451d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
mv _posts/r/md/ggplot2 _posts/ggplot2/md
4141
mv _posts/fsharp/html/csharp _posts/csharp/html
4242
43+
- name: Fix case-sensitive redirect issues
44+
run: python fix-case-redirects.py _posts/julia/html
45+
4346
- name: Build site
4447
run: |
4548
python front-matter-ci.py _posts

fix-case-redirects.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
import frontmatter
3+
from pathlib import Path
4+
import sys
5+
6+
for path in sys.argv[1:]:
7+
for f in Path(path).glob("**/*.html"):
8+
try:
9+
post = frontmatter.load(f)
10+
except:
11+
continue
12+
13+
permalink = post.get('permalink', '').lower()
14+
redirects = post.get('redirect_from', [])
15+
if isinstance(redirects, str):
16+
redirects = [redirects]
17+
18+
fixed = [r for r in redirects if r.lower() != permalink]
19+
20+
if len(fixed) < len(redirects):
21+
removed = [r for r in redirects if r.lower() == permalink]
22+
print(f"{f}: removed {removed}")
23+
if fixed:
24+
post['redirect_from'] = fixed
25+
else:
26+
del post['redirect_from']
27+
with open(f, 'w') as out:
28+
out.write(frontmatter.dumps(post))

0 commit comments

Comments
 (0)