|
1 | 1 | // 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 | + |
2 | 24 | 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/', |
3 | 28 | '/2024/07/16/welcome-post.html': '/en/blog/2024-07-16-welcome-post', |
4 | 29 | '/2024/07/16/welcome-post': '/en/blog/2024-07-16-welcome-post', |
5 | 30 | '/2024/09/29/security-releases.html': '/en/blog/2024-09-29-security-releases', |
@@ -60,10 +85,69 @@ const api_v2 = { |
60 | 85 | }; |
61 | 86 |
|
62 | 87 | const pages = { |
| 88 | + '/changelog/4x.html': 'https://github.com/expressjs/express/releases', |
63 | 89 | '/en/changelog/4x.html': 'https://github.com/expressjs/express/releases', |
64 | 90 | '/en/changelog/4x': 'https://github.com/expressjs/express/releases', |
65 | 91 | }; |
66 | 92 |
|
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 }; |
68 | 152 |
|
69 | 153 | export default redirects; |
0 commit comments