Skip to content

Commit 3768084

Browse files
committed
doc: Fix cool URIs
1 parent aa2928f commit 3768084

File tree

2 files changed

+66
-17
lines changed

2 files changed

+66
-17
lines changed

doc/cool-uris.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# Do not edit manually.
33
annotated.html: []
44
classes.html: []
5+
debugging.html: []
56
deprecated.html: []
67
dir_63ce773eee1f9b680e6e312b48cc99ca.html: []
78
dir_891596f32582d3133e8915e72908625f.html: []
89
dir_d44c64559bbebec7f509842c48db8b23.html: []
910
dir_e68e8157741866f444e17edd764ebbae.html: []
11+
doxygen_crawl.html: []
1012
error-index.html: []
1113
files.html: []
1214
functions.html: []
@@ -33,8 +35,9 @@ group__x11.html: []
3335
index.html: []
3436
keymap-text-format-v1.html:
3537
- md_doc_keymap_format_text_v1.html
36-
md_doc_quick_guide.html: []
37-
modules.html: []
38+
md_doc_2quick-guide.html:
39+
- md_doc_quick_guide.html
40+
meson_options.html: []
3841
pages.html: []
3942
rule-file-format.html:
4043
- md_doc_rules_format.html
@@ -54,6 +57,8 @@ structxkb__keymap.html: []
5457
structxkb__rule__names.html: []
5558
structxkb__state.html: []
5659
todo.html: []
60+
topics.html:
61+
- modules.html
5762
user-configuration.html:
5863
- md_doc_user_configuration.html
5964
xkb-intro.html: []

scripts/ensure-stable-doc-urls.py

+59-15
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ class ExitCode(IntFlag):
2828
NORMAL = 0
2929
INVALID_UPDATES = 1 << 4
3030
MISSING_UPDATES = 1 << 5
31+
NON_UNIQUE_DIRECTIONS = 1 << 6
3132

3233

3334
THIS_SCRIPT_PATH = Path(__file__)
3435
RELATIVE_SCRIPT_PATH = THIS_SCRIPT_PATH.relative_to(THIS_SCRIPT_PATH.parent.parent)
3536

3637
REDIRECTION_DELAY = 6 # in seconds. Note: at least 6s for accessibility
38+
REDIRECTION_TITLE = "xkbcommon: Page Redirection"
3739

3840
# NOTE: The redirection works with the HTML tag: <meta http-equiv="refresh">.
3941
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#http-equiv
@@ -50,7 +52,7 @@ class ExitCode(IntFlag):
5052
<meta http-equiv="refresh" content="${delay}; url=${canonical}">
5153
<link href="doxygen.css" rel="stylesheet" type="text/css">
5254
<link href="doxygen-extra.css" rel="stylesheet" type="text/css">
53-
<title>xkbcommon: Page Redirection</title>
55+
<title>${title}</title>
5456
</head>
5557
<body>
5658
<div id="top">
@@ -87,6 +89,14 @@ def parse_page_update(update: str) -> Update:
8789
return updateʹ
8890

8991

92+
def is_page_redirection(path: Path):
93+
with path.open("rt", encoding="utf-8") as fd:
94+
for line in fd:
95+
if REDIRECTION_TITLE in line:
96+
return True
97+
return False
98+
99+
90100
def update_registry(registry_path: Path, doc_dir: Path, updates: Sequence[str]):
91101
"""
92102
Update the URL registry by:
@@ -95,21 +105,28 @@ def update_registry(registry_path: Path, doc_dir: Path, updates: Sequence[str]):
95105
"""
96106
# Parse updates
97107
updates_ = dict(map(parse_page_update, updates))
108+
# Update
109+
invalid_updates = set(updates_)
98110
# Load previous registry
99111
with registry_path.open("rt", encoding="utf-8") as fd:
100-
registry = yaml.safe_load(fd) or {}
112+
registry: dict[str, list[str]] = yaml.safe_load(fd) or {}
101113
# Expected updates
102114
missing_updates = set(file for file in registry if not (doc_dir / file).is_file())
103-
# Update
104-
invalid_updates = set(updates_)
115+
# Ensure each page is unique
116+
for d, rs in registry.items():
117+
if clashes := frozenset(rs).intersection(registry):
118+
print(
119+
f"[ERROR] The following redirections of “{d}”",
120+
f"clash with canonical directions: {clashes}",
121+
)
122+
exit(ExitCode.NON_UNIQUE_DIRECTIONS)
105123
redirections = frozenset(chain(*registry.values()))
106124
for file in glob.iglob("**/*.html", root_dir=doc_dir, recursive=True):
107125
# Skip redirection pages
108126
if file in redirections:
109127
continue
110128
# Get previous entry and potential update
111-
old = updates_.get(file)
112-
if old:
129+
if old := updates_.get(file):
113130
# Update old entry
114131
invalid_updates.remove(file)
115132
entry = registry.get(old)
@@ -137,8 +154,21 @@ def update_registry(registry_path: Path, doc_dir: Path, updates: Sequence[str]):
137154
exit_code |= ExitCode.INVALID_UPDATES
138155
if missing_updates:
139156
for old in missing_updates:
140-
print(f"[ERROR] “{old}” not found and has no update.")
141-
exit_code |= ExitCode.MISSING_UPDATES
157+
# Handle older Doxygen versions
158+
old_redirections = registry[old]
159+
for r in old_redirections:
160+
path = doc_dir / r
161+
if path.is_file() and not is_page_redirection(path):
162+
print(
163+
"[WARNING] Handling old Doxygen version:",
164+
f"use “{r}” instead of “{old}” for the canonical direction",
165+
)
166+
missing_updates.remove(old)
167+
break
168+
else:
169+
print(f"[ERROR] “{old}” not found and has no update.")
170+
if missing_updates:
171+
exit_code |= ExitCode.MISSING_UPDATES
142172
if exit_code:
143173
print("[ERROR] Processing interrupted: please fix the errors above.")
144174
exit(exit_code.value)
@@ -159,22 +189,36 @@ def generate_redirections(registry_path: Path, doc_dir: Path):
159189
cool = True
160190
# Load registry
161191
with registry_path.open("rt", encoding="utf-8") as fd:
162-
registry = yaml.safe_load(fd) or {}
192+
registry: dict[str, list[str]] = yaml.safe_load(fd) or {}
163193
for canonical, aliases in registry.items():
164194
# Check canonical path is up-to-date
165195
if not (doc_dir / canonical).is_file():
166-
cool = False
167-
print(
168-
f"ERROR: missing canonical documentation page “{canonical}”. "
169-
f"Please update “{registry_path}” using {RELATIVE_SCRIPT_PATH}”."
170-
)
196+
# Handle older Doxygen versions
197+
for r in aliases:
198+
path = doc_dir / r
199+
if path.is_file() and not is_page_redirection(path):
200+
print(
201+
"[WARNING] Handling old Doxygen version:",
202+
f"use “{r}” instead of “{canonical}” for the canonical direction",
203+
)
204+
canonical = r
205+
aliases.remove(r)
206+
break
207+
else:
208+
cool = False
209+
print(
210+
f"ERROR: missing canonical documentation page “{canonical}”. "
211+
f"Please update “{registry_path}” using {RELATIVE_SCRIPT_PATH}”."
212+
)
171213
# Add a redirection page
172214
for alias in aliases:
173215
path = doc_dir / alias
174216
with path.open("wt", encoding="utf-8") as fd:
175217
fd.write(
176218
REDIRECTION_PAGE_TEMPLATE.substitute(
177-
canonical=canonical, delay=REDIRECTION_DELAY
219+
canonical=canonical,
220+
delay=REDIRECTION_DELAY,
221+
title=REDIRECTION_TITLE,
178222
)
179223
)
180224
if not cool:

0 commit comments

Comments
 (0)