Skip to content

Commit 099872f

Browse files
committed
fix: add missing redirects
Fixes #2327 Fixes #2328 Fixes #2332
1 parent 462ddb0 commit 099872f

1 file changed

Lines changed: 85 additions & 1 deletion

File tree

src/config/redirect.js

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
// Redirect .html and non-.html blog post URLs to the new format. This will ensure that any existing links to blog posts will continue to work and redirect users to the correct location on the new site.
2+
import { getLanguageCodes } from "../i18n/utils"
3+
4+
/** @param {{[key: string]: string}} pageMap */
5+
function localizedPages(pageMap) {
6+
/** @type {{[key: string]: string}} */
7+
const localizedVersions = {};
8+
const languageCodes = getLanguageCodes();
9+
for (const [from, to] of Object.entries(pageMap)) {
10+
// All localized pages seem to have had both /<path> and /en/<path> versions
11+
localizedVersions[`/${from}`] = `/en/${to}`;
12+
for (const langCode of languageCodes) {
13+
localizedVersions[`/${langCode}/${from}`] = `/${langCode}/${to}`;
14+
}
15+
}
16+
return localizedVersions;
17+
}
18+
19+
/** @param {string[]} pageList */
20+
function stripHTML(pageList) {
21+
return Object.fromEntries(pageList.map(old => [old, old.substring(0, old.length - 5)]))
22+
}
23+
224
const blog = {
25+
'/blog/posts.html': '/en/blog',
26+
'/en/blog/posts.html': '/en/blog',
27+
'/en/blog/write-post.html': '/en/blog/write-post/',
328
'/2024/07/16/welcome-post.html': '/en/blog/2024-07-16-welcome-post',
429
'/2024/07/16/welcome-post': '/en/blog/2024-07-16-welcome-post',
530
'/2024/09/29/security-releases.html': '/en/blog/2024-09-29-security-releases',
@@ -60,10 +85,69 @@ const api_v2 = {
6085
};
6186

6287
const pages = {
88+
'/changelog/4x.html': 'https://github.com/expressjs/express/releases',
6389
'/en/changelog/4x.html': 'https://github.com/expressjs/express/releases',
6490
'/en/changelog/4x': 'https://github.com/expressjs/express/releases',
6591
};
6692

67-
const redirects = { ...blog, ...api_v2, ...pages };
93+
const api = localizedPages({
94+
'api.html': '5x/api/',
95+
'3x/api.html': '3x/api/',
96+
'4x/api.html': '4x/api/',
97+
'5x/api.html': '5x/api/',
98+
});
99+
100+
const localizedGuides = localizedPages(stripHTML([
101+
'advanced/best-practice-performance.html',
102+
'advanced/best-practice-security.html',
103+
'advanced/developing-template-engines.html',
104+
'advanced/healthcheck-graceful-shutdown.html',
105+
'advanced/security-updates.html',
106+
'guide/behind-proxies.html',
107+
'guide/database-integration.html',
108+
'guide/debugging.html',
109+
'guide/error-handling.html',
110+
'guide/migrating-4.html',
111+
'guide/migrating-5.html',
112+
'guide/overriding-express-api.html',
113+
'guide/routing.html',
114+
'guide/using-middleware.html',
115+
'guide/using-template-engines.html',
116+
'guide/writing-middleware.html',
117+
'starter/basic-routing.html',
118+
'starter/examples.html',
119+
'starter/faq.html',
120+
'starter/generator.html',
121+
'starter/hello-world.html',
122+
'starter/installing.html',
123+
'starter/static-files.html',
124+
]));
125+
126+
const localizedResources = localizedPages(stripHTML([
127+
'resources/community.html',
128+
'resources/contributing.html',
129+
'resources/glossary.html',
130+
'resources/middleware/body-parser.html',
131+
'resources/middleware/compression.html',
132+
'resources/middleware/connect-rid.html',
133+
'resources/middleware/cookie-parser.html',
134+
'resources/middleware/cookie-session.html',
135+
'resources/middleware/cors.html',
136+
'resources/middleware/errorhandler.html',
137+
'resources/middleware/method-override.html',
138+
'resources/middleware/morgan.html',
139+
'resources/middleware/multer.html',
140+
'resources/middleware/response-time.html',
141+
'resources/middleware/serve-favicon.html',
142+
'resources/middleware/serve-index.html',
143+
'resources/middleware/serve-static.html',
144+
'resources/middleware/session.html',
145+
'resources/middleware/timeout.html',
146+
'resources/middleware/vhost.html',
147+
'resources/middleware.html',
148+
'resources/utils.html',
149+
]))
150+
151+
const redirects = { ...blog, ...api_v2, ...pages, ...api, ...localizedGuides, ...localizedResources };
68152

69153
export default redirects;

0 commit comments

Comments
 (0)