Skip to content

Commit a612512

Browse files
committed
Add Canonical Page
1 parent f832771 commit a612512

5 files changed

Lines changed: 76 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
title: "{Device Name}"
1212
codename: {codename}
1313
oem: {OEM Name}
14+
permalink: /{codename}/
15+
redirect_from: /devices/{oem}/{codename}/
1416
supportstatus: Current/Discontinued
1517
maintainer: {Your GitHub Username/Name} # Without @
1618
ddof: "/dev/block/bootdevice/by-name/recovery"

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ theme: null
44
collections:
55
oem:
66
output: true
7-
permalink: /:name/
7+
permalink: /devices/:path/
88

99
url: "https://PitchBlackRecoveryProject.github.io"
1010
baseurl: "" # Leave empty for root, or set to "/repo-name" for GitHub Pages under username
@@ -15,4 +15,4 @@ repository: PitchBlackRecoveryProject/PitchBlackRecoveryProject.github.io
1515

1616
# Plugins for GitHub Pages
1717
plugins:
18-
- jekyll-redirect-from
18+
- jekyll-redirect-from

assets/scripts/fix_permalinks.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
5+
# This script migrates all existing device files in _oem/
6+
# from old permalink structure to new dual-link structure.
7+
# It forces the vendor part of the URL to be LOWERCASE.
8+
# Old: permalink: /codename/
9+
# New: permalink: /codename/
10+
# redirect_from: /devices/lower_vendor/codename/
11+
12+
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13+
OEM_DIR = os.path.join(REPO_ROOT, "_oem")
14+
15+
def fix_file(file_path, vendor):
16+
with open(file_path, 'r', encoding='utf-8') as f:
17+
content = f.read()
18+
19+
# Regex to find codename
20+
codename_match = re.search(r'^codename:\s*(.+)$', content, re.MULTILINE)
21+
if not codename_match:
22+
print(f"Skipping {file_path}: No codename found")
23+
return
24+
25+
codename = codename_match.group(1).strip()
26+
27+
# Construct desired lines (Force vendor to lowercase for URL)
28+
vendor_slug = vendor.lower()
29+
new_permalink = f"permalink: /{codename}/"
30+
new_redirect = f"redirect_from: /devices/{vendor_slug}/{codename}/"
31+
32+
# Check if already updated
33+
if new_permalink in content and new_redirect in content:
34+
return
35+
36+
# Replace old permalink
37+
# Case 1: permalink exists
38+
permalink_pattern = re.compile(r'^permalink:.*$', re.MULTILINE)
39+
40+
if permalink_pattern.search(content):
41+
# Replace existing permalink
42+
content = permalink_pattern.sub(new_permalink + "\n" + new_redirect, content)
43+
print(f"Updated {vendor}/{codename}")
44+
else:
45+
# Case 2: permalink might be missing (using default), add it after codename
46+
content = content.replace(f"codename: {codename}", f"codename: {codename}\n{new_permalink}\n{new_redirect}")
47+
print(f"Added permalink to {vendor}/{codename}")
48+
49+
with open(file_path, 'w', encoding='utf-8') as f:
50+
f.write(content)
51+
52+
def main():
53+
print("Starting Permalink Migration...")
54+
if not os.path.exists(OEM_DIR):
55+
print(f"Error: {OEM_DIR} not found.")
56+
return
57+
58+
count = 0
59+
for root, dirs, files in os.walk(OEM_DIR):
60+
for file in files:
61+
if file.endswith(".md"):
62+
# Get vendor from directory name
63+
vendor = os.path.basename(root)
64+
fix_file(os.path.join(root, file), vendor)
65+
count += 1
66+
67+
print(f"Processed {count} files.")
68+
69+
if __name__ == "__main__":
70+
main()

assets/scripts/sync_all_devices.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def process_device(vendor, device_codename, build_source_codename, specific_data
125125
title: "{device_name}"
126126
codename: {device_codename}
127127
permalink: /{device_codename}/
128+
redirect_from: /devices/{vendor_lower}/{device_codename}/
128129
oem: {vendor}
129130
supportstatus: Current
130131
maintainer: {maintainer}

assets/scripts/update_builds_json.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ layout: device
214214
title: "${T_NAME}"
215215
codename: ${T_CODE}
216216
permalink: /${T_CODE}/
217+
redirect_from: /devices/${VENDOR_LOWER}/${T_CODE}/
217218
oem: ${VENDOR}
218219
supportstatus: Current
219220
maintainer: ${T_MAINT}

0 commit comments

Comments
 (0)