Skip to content

Commit 0454bd4

Browse files
docs: fix redirects for old /latest URLs and root page
Generate latest alias pages for all docs across versions so old URLs like /latest/en/introduction get proper redirects to the quickstart. Add root index.astro redirect instead of relying on empty HTML + _redirects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 13c1b48 commit 0454bd4

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

apps/docs/client/src/pages/[version]/[locale]/[...slug].astro

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,30 @@ export async function getStaticPaths() {
2424
params: { version: "latest", locale },
2525
props: { doc: null, version: "latest" },
2626
})),
27-
// "latest" alias for all latest docs (so /latest/en/... redirects to /deco-studio/en/...)
27+
// "latest" alias for all docs across all versions (so old /latest/en/... URLs redirect properly)
2828
...allDocs
29-
.filter((doc) => doc.id.startsWith(`${LATEST_VERSION.id}/`))
30-
.map((doc) => {
29+
.flatMap((doc) => {
3130
const parts = doc.id.split("/");
3231
const locale = parts[1];
3332
const slug = parts.slice(2).join("/");
33+
// Check if this slug exists in the latest version
34+
const existsInLatest = allDocs.some(
35+
(d) => d.id === `${LATEST_VERSION.id}/${locale}/${slug}`,
36+
);
3437
return {
3538
params: { version: "latest", locale, slug },
36-
props: { doc: null, version: "latest" },
39+
props: { doc: null, version: "latest", existsInLatest },
3740
};
38-
}),
41+
})
42+
// Deduplicate by locale+slug (same slug may exist in multiple versions)
43+
.filter(
44+
(entry, index, arr) =>
45+
arr.findIndex(
46+
(e) =>
47+
e.params.locale === entry.params.locale &&
48+
e.params.slug === entry.params.slug,
49+
) === index,
50+
),
3951
4052
// Actual versioned paths
4153
...VERSION_IDS.flatMap((version) => [
@@ -72,15 +84,15 @@ export async function getStaticPaths() {
7284
];
7385
}
7486
75-
const { doc, version: propVersion } = Astro.props;
87+
const { doc, version: propVersion, existsInLatest } = Astro.props;
7688
const slug = Astro.params.slug;
7789
7890
// Redirect "latest" alias to actual version
7991
if (version === "latest") {
80-
const target = slug
81-
? `/${LATEST_VERSION.id}/${lang}/${slug}`
82-
: `/${LATEST_VERSION.id}/${lang}/studio/quickstart`;
83-
return Astro.redirect(target);
92+
if (slug && existsInLatest) {
93+
return Astro.redirect(`/${LATEST_VERSION.id}/${lang}/${slug}`);
94+
}
95+
return Astro.redirect(`/${LATEST_VERSION.id}/${lang}/${LATEST_VERSION.root}`);
8496
}
8597
8698
// Legacy redirects
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
import { LATEST_VERSION } from "../config/versions";
3+
4+
return Astro.redirect(`/${LATEST_VERSION.id}/en/${LATEST_VERSION.root}`);
5+
---

0 commit comments

Comments
 (0)