docs: redirect bare Learn path

This commit is contained in:
David Karlsson authored and Codex committed 2026-08-03 14:12:21 +00:00
1 parent 48600cd547
commit 75deb7f882
3 files changed
+19 -1

No files matched your search

+2
View File
@@ -8,6 +8,8 @@
# provide a short, permanent link to refer to a topic in the documentation.
# For example, the docker CLI can output https://docs.docker.com/go/some-topic
# in its help output, which can be redirected to elsewhere in the documentation.
"/learn/":
- /learn
"/security/access-tokens/":
- /go/access-tokens/
"/reference/api/engine/#deprecated-api-versions":
+6 -1
View File
@@ -22,7 +22,12 @@ exports.handler = (event, context, callback) => {
const redirects = JSON.parse(`{{.RedirectsJSON}}`);
for (let key in redirects) {
const redirectTarget = key.replace(/\/$/, "");
if (redirectTarget !== requestUrl) {
const exactMatch = key === request.uri;
// Preserve slash-insensitive matching without redirecting a canonical
// slash-terminated destination back to itself.
const normalizedMatch =
redirectTarget === requestUrl && redirects[key] !== request.uri;
if (!exactMatch && !normalizedMatch) {
continue;
}
//console.log(`redirect: ${requestUrl} to ${redirects[key]}`);
@@ -17,6 +17,7 @@ const Module = require("node:module");
const SRC = path.join(__dirname, "cloudfront-lambda-redirects.js");
const REDIRECTS = {
"/learn": "/learn/",
"/old/page/": "/new/page/",
"/target-with-query/": "/dest/?ref=docs",
"/target-with-fragment/": "/dest/?ref=docs#install",
@@ -85,6 +86,16 @@ test("exact redirect without a query string is unchanged", async () => {
assert.equal(locationOf(result), "/new/page/");
});
test("bare path redirects without redirecting the canonical target to itself", async () => {
const { result: bareResult } = await invoke({ uri: "/learn" });
assert.equal(bareResult.status, "301");
assert.equal(locationOf(bareResult), "/learn/");
const { result: canonicalResult, request } = await invoke({ uri: "/learn/" });
assert.equal(canonicalResult, request);
assert.equal(request.uri, "/learn/index.html");
});
test("exact redirect appends with & when target already has a query string", async () => {
const { result } = await invoke({
uri: "/target-with-query/",