Skip to content

Commit f055ce0

Browse files
committed
redirect pages
Signed-off-by: chang-ning <spiderpower02@gmail.com>
1 parent c7ec58c commit f055ce0

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

app.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,46 @@
5959
"notes/systemd.html": "notes/tools/systemd.html",
6060
}
6161

62+
# Pages that lived at nested paths but were renamed or removed in the
63+
# Jan 2026 cleanup (e.g. /notes/cpp/cpp_constructor.html merged into
64+
# cpp_basic.html, the /notes/cmake/ section collapsed into cpp_cmake.html,
65+
# the /notes/appendix/ section migrated to /notes/rust/). Google still has
66+
# many of these indexed -- mapping them avoids 404s and lets the index
67+
# converge on the surviving canonical pages.
68+
_LEGACY_NESTED_REDIRECTS = {
69+
"notes/c/asm_basic.html": "notes/c/asm.html",
70+
"notes/c/c_gnuext.html": "notes/c/c_macro.html",
71+
"notes/debug/gdb_debug.html": "notes/debug/gdb.html",
72+
"notes/os/os_concurrency.html": "notes/os/os_thread.html",
73+
"notes/cmake/cmake_basic.html": "notes/cpp/cpp_cmake.html",
74+
"notes/cmake/cmake_external.html": "notes/cpp/cpp_cmake.html",
75+
"notes/cmake/cmake_package.html": "notes/cpp/cpp_cmake.html",
76+
"notes/cmake/index.html": "notes/cpp/cpp_cmake.html",
77+
"notes/cpp/cpp_constructor.html": "notes/cpp/cpp_basic.html",
78+
"notes/cpp/cpp_forwarding.html": "notes/cpp/cpp_move.html",
79+
"notes/cpp/cpp_initialization.html": "notes/cpp/cpp_raii.html",
80+
"notes/cpp/cpp_ranges.html": "notes/cpp/cpp_iterator.html",
81+
"notes/cpp/cpp_variadic.html": "notes/cpp/cpp_template.html",
82+
"notes/tools/bash_date.html": "notes/tools/bash.html",
83+
"notes/tools/bash_find.html": "notes/tools/bash.html",
84+
"notes/tools/bash_os.html": "notes/tools/bash.html",
85+
"notes/tools/bash_re.html": "notes/tools/bash.html",
86+
"notes/bash/index.html": "notes/tools/bash.html",
87+
"notes/appendix/index.html": "notes/rust/index.html",
88+
"notes/appendix/rust_from_cpp.html": "notes/rust/index.html",
89+
}
90+
6291
_LEGACY_FLAT_PATTERN = re.compile(
6392
r"^notes/(cpp|c|cuda|rust)_([a-z0-9_]+)\.html$"
6493
)
6594

6695

6796
def _resolve_legacy_flat_target(path):
68-
"""Return the nested URL for a known legacy flat path, or None."""
69-
explicit = _LEGACY_FLAT_REDIRECTS.get(path)
97+
"""Return the canonical URL for a known legacy path, or None."""
98+
explicit = (
99+
_LEGACY_FLAT_REDIRECTS.get(path)
100+
or _LEGACY_NESTED_REDIRECTS.get(path)
101+
)
70102
if explicit:
71103
return explicit
72104
match = _LEGACY_FLAT_PATTERN.match(path)

app_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@ def test_resolve_legacy_flat_target_explicit(self):
189189
for old, new in cases.items():
190190
self.assertEqual(_resolve_legacy_flat_target(old), new)
191191

192+
def test_resolve_legacy_flat_target_nested(self):
193+
"""Renamed/removed nested paths resolve to current canonical URLs."""
194+
cases = {
195+
"notes/c/asm_basic.html": "notes/c/asm.html",
196+
"notes/debug/gdb_debug.html": "notes/debug/gdb.html",
197+
"notes/os/os_concurrency.html": "notes/os/os_thread.html",
198+
"notes/cmake/cmake_basic.html": "notes/cpp/cpp_cmake.html",
199+
"notes/cmake/index.html": "notes/cpp/cpp_cmake.html",
200+
"notes/cpp/cpp_constructor.html": "notes/cpp/cpp_basic.html",
201+
"notes/cpp/cpp_ranges.html": "notes/cpp/cpp_iterator.html",
202+
"notes/tools/bash_find.html": "notes/tools/bash.html",
203+
"notes/bash/index.html": "notes/tools/bash.html",
204+
"notes/appendix/rust_from_cpp.html": "notes/rust/index.html",
205+
}
206+
for old, new in cases.items():
207+
self.assertEqual(_resolve_legacy_flat_target(old), new)
208+
209+
def test_redirect_legacy_flat_paths_nested(self):
210+
"""A removed nested URL returns 301 to its new canonical location."""
211+
with app.test_request_context("/notes/cmake/cmake_basic.html"):
212+
resp = redirect_legacy_flat_paths()
213+
self.assertEqual(resp.status_code, 301)
214+
self.assertTrue(
215+
resp.headers["Location"].endswith("/notes/cpp/cpp_cmake.html")
216+
)
217+
192218
def test_resolve_legacy_flat_target_pattern(self):
193219
"""Pattern fallback resolves flat URLs to existing nested files."""
194220
# cpp/cpp_basic.html exists, so cpp_basic.html should resolve to it.

0 commit comments

Comments
 (0)