|
| 1 | +import { redirects as retiredPageRedirects } from "../redirects.ts"; |
1 | 2 | import referenceAliases from "./reference-aliases.json" with { type: "json" }; |
2 | 3 |
|
3 | 4 | export const deploymentBase = "/docs"; |
@@ -25,6 +26,24 @@ const authoredRedirectRules = [ |
25 | 26 | }, |
26 | 27 | ]; |
27 | 28 |
|
| 29 | +// `route` is relative to the deployment base; a `#fragment` has no Markdown form. |
| 30 | +function markdownRoute(route) { |
| 31 | + const pathname = route.split("#")[0]; |
| 32 | + return `${deploymentBase}${pathname === "/" ? "/index" : pathname}.md`; |
| 33 | +} |
| 34 | + |
| 35 | +function unbased(route) { |
| 36 | + return route.slice(deploymentBase.length) || "/"; |
| 37 | +} |
| 38 | + |
| 39 | +// Blume emits HTML meta-refresh stubs for retired Markdown URLs. Agents need |
| 40 | +// an HTTP redirect instead of HTML at those URLs. Moved pages also need a rule, |
| 41 | +// so both kinds get a 301 to the replacement's Markdown file. |
| 42 | +export const markdownTwinRules = [ |
| 43 | + ...authoredRedirectRules.map(({ from, to }) => ({ from: unbased(from), to: unbased(to) })), |
| 44 | + ...retiredPageRedirects, |
| 45 | +].map(({ from, to }) => ({ from: markdownRoute(from), status: 301, to: markdownRoute(to) })); |
| 46 | + |
28 | 47 | const aliasFamilies = [ |
29 | 48 | { |
30 | 49 | sourcePrefix: "/api/operations/", |
@@ -117,6 +136,7 @@ function applyRule(rule, source) { |
117 | 136 | export function buildRoutingRules(redirects) { |
118 | 137 | return [ |
119 | 138 | ...authoredRedirectRules, |
| 139 | + ...markdownTwinRules, |
120 | 140 | ...compileRedirectRules(redirects).map(({ from, status, to }) => ({ |
121 | 141 | from: `${deploymentBase}${from}`, |
122 | 142 | status, |
|
0 commit comments