Skip to content

Commit 274b301

Browse files
authored
Merge pull request #11 from scroll-tech/add-redirects
remove docs in path and add redirects
2 parents 1ea7d62 + fd3d9e1 commit 274b301

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

src/components/LeftSidebar/LeftSidebar.astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ const currentPageMatch = removeSlashes(currentPage.slice(1))
5858
<>
5959
<li class="nav-link">
6060
<a
61-
href={isExternal(child.url) ? `${child.url}` : localizePath("/docs/" + child.url)}
61+
href={isExternal(child.url) ? `${child.url}` : localizePath(child.url)}
6262
target={isExternal(child.url) ? "_blank" : "_self"}
63-
aria-current={`${currentPage === localizePath("/docs/" + child.url) ? "page" : "false"}`}
63+
aria-current={`${
64+
currentPageMatch === removeSlashes(localizePath(child.url)) ? "page" : "false"
65+
}`}
6466
>
6567
{child.title}
6668
{isExternal(child.url) && (
@@ -77,10 +79,10 @@ const currentPageMatch = removeSlashes(currentPage.slice(1))
7779
{child.children.map((childItem) => (
7880
<li class="nav-link nested">
7981
<a
80-
href={isExternal(childItem.url) ? childItem.url : localizePath("/docs/" + childItem.url)}
82+
href={isExternal(childItem.url) ? childItem.url : localizePath(childItem.url)}
8183
target={isExternal(child.url) ? "_blank" : "_self"}
8284
aria-current={`${
83-
currentPage === localizePath("/docs/" + childItem.url) ? "page" : "false"
85+
currentPageMatch === removeSlashes(localizePath(childItem.url)) ? "page" : "false"
8486
}`}
8587
>
8688
{childItem.title}

src/config/menu.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ export const MENU: MenuItems = {
1010
en: [
1111
{
1212
text: "Getting Started",
13-
link: "/en/docs/getting-started/overview",
13+
link: "/en/getting-started/overview",
1414
section: "gettingStarted",
1515
},
16-
{ text: "Developers", link: "/en/docs/developers", section: "developers" },
17-
{ text: "Technology", link: "/en/docs/technology", section: "technology" },
18-
{ text: "Learn", link: "/en/docs/learn", section: "learn" },
16+
{ text: "Developers", link: "/en/developers", section: "developers" },
17+
{ text: "Technology", link: "/en/technology", section: "technology" },
18+
{ text: "Learn", link: "/en/learn", section: "learn" },
1919
],
2020
zh: [
2121
{
2222
text: "入门",
23-
link: "/zh/docs/getting-started/overview",
23+
link: "/zh/getting-started/overview",
2424
section: "gettingStarted",
2525
},
26-
{ text: "开发者", link: "/zh/docs/developers", section: "developers" },
27-
{ text: "技术", link: "/zh/docs/technology", section: "technology" },
28-
{ text: "学习", link: "/zh/docs/learn", section: "learn" },
26+
{ text: "开发者", link: "/zh/developers", section: "developers" },
27+
{ text: "技术", link: "/zh/technology", section: "technology" },
28+
{ text: "学习", link: "/zh/learn", section: "learn" },
2929
],
3030
}

src/config/sidebar.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { t } from "i18next"
1+
import i18next, { t } from "i18next"
2+
3+
const formatUrl = (url) => `${i18next.language}/${url}`
24

35
export const getSidebar = () => {
46
return {
@@ -12,27 +14,27 @@ export const getSidebar = () => {
1214
contents: [
1315
{
1416
title: t("sidebar.gettingStarted.userGuide"),
15-
url: "user-guide/",
17+
url: formatUrl("user-guide/"),
1618
children: [
1719
{
1820
title: t("sidebar.gettingStarted.setup"),
19-
url: "user-guide/setup",
21+
url: formatUrl("user-guide/setup"),
2022
},
2123
{
2224
title: t("sidebar.gettingStarted.faucet"),
23-
url: "user-guide/faucet",
25+
url: formatUrl("user-guide/faucet"),
2426
},
2527
{
2628
title: t("sidebar.gettingStarted.bridge"),
27-
url: "user-guide/bridge",
29+
url: formatUrl("user-guide/bridge"),
2830
},
2931
{
3032
title: t("sidebar.gettingStarted.transferTokens"),
31-
url: "user-guide/transfer-tokens",
33+
url: formatUrl("user-guide/transfer-tokens"),
3234
},
3335
{
3436
title: t("sidebar.gettingStarted.commonErrors"),
35-
url: "user-guide/common-errors",
37+
url: formatUrl("user-guide/common-errors"),
3638
},
3739
],
3840
},
@@ -66,7 +68,7 @@ export const getSidebar = () => {
6668
{ title: t("sidebar.developers.integrations"), url: "developers/integrations" },
6769
{
6870
title: t("sidebar.developers.ethereum&AlphaTestnetDifferences"),
69-
url: "developers/ethereum-and-alpha-testnet-differences",
71+
url: formatUrl("developers/ethereum-and-alpha-testnet-differences"),
7072
},
7173
],
7274
},
@@ -75,7 +77,7 @@ export const getSidebar = () => {
7577
contents: [
7678
{
7779
title: t("sidebar.developers.contractDeploymentTutorial"),
78-
url: "developers/guides/contract-deployment-tutorial",
80+
url: formatUrl("developers/guides/contract-deployment-tutorial"),
7981
},
8082
],
8183
},

src/pages/[...redirect].astro

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
---
2-
import { changeLanguage } from "i18next"
2+
import i18next, { t, changeLanguage } from "i18next"
33
import { GetStaticPathsResult } from "astro"
44
import redirects from "../features/redirects/redirects.json"
5+
import { getCollection } from "astro:content"
56
67
changeLanguage("en")
78
89
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
10+
const pages = await getCollection("docs")
11+
const allSlugs = new Set(
12+
pages.map((page) => {
13+
const [, ...slug] = page.slug.split("/")
14+
return slug.join("/")
15+
})
16+
)
17+
918
const sanitizeSource = (source: string) => {
1019
let newSource = source
1120
if (newSource[newSource.length - 1] === "/") newSource = newSource.slice(0, newSource.length - 1)
1221
if (newSource[0] === "/") return newSource.slice(1, newSource.length)
1322
return newSource
1423
}
15-
return redirects.redirects.map((entry) => {
24+
25+
const paths = redirects.redirects.map((entry) => {
1626
return {
1727
params: { redirect: sanitizeSource(entry.source) },
1828
props: {
@@ -23,6 +33,11 @@ export async function getStaticPaths(): Promise<GetStaticPathsResult> {
2333
},
2434
}
2535
})
36+
37+
for (let slug of allSlugs) {
38+
paths.push({ params: { redirect: slug }, props: { to: `/en/${slug}` } })
39+
}
40+
return paths
2641
}
2742
const { to } = Astro.props
2843
---

src/pages/[lang]/docs/[...slug].astro renamed to src/pages/[lang]/[...slug].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { getCollection } from "astro:content"
33
import i18next, { t, changeLanguage } from "i18next"
4-
import MainLayout from "../../../layouts/MainLayout.astro"
4+
import MainLayout from "../../layouts/MainLayout.astro"
55
66
export async function getStaticPaths() {
77
const pages = await getCollection("docs")

0 commit comments

Comments
 (0)