-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
76 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
--- | ||
import Redir from "~/layouts/Redir.astro"; | ||
return new Response(null, { | ||
status: 301, | ||
headers: { | ||
Location: "/api/rest-v1", | ||
}, | ||
}); | ||
--- | ||
|
||
<Redir target="/api/rest-v1" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
--- | ||
import Redir from "~/layouts/Redir.astro"; | ||
return new Response(null, { | ||
status: 301, | ||
headers: { | ||
Location: "/api/rest-v2-legacy/v2-api", | ||
}, | ||
}); | ||
--- | ||
|
||
<Redir target="/api/rest-v2-legacy/v2-api" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,27 @@ | ||
--- | ||
import * as path from "node:path"; | ||
import type { GetStaticPathsItem } from "astro"; | ||
import type { CollectionEntry } from "astro:content"; | ||
import { getCollection } from "astro:content"; | ||
import { match, P } from "ts-pattern"; | ||
import redirYaml from "~/content/docs/_redir.yaml"; | ||
import Docs from "~/layouts/Docs.astro"; | ||
import Redir from "~/layouts/Redir.astro"; | ||
import type { Lang } from "../../../type"; | ||
import { isLang } from "~/type"; | ||
export async function getStaticPaths() { | ||
const docEntries = await getCollection("docs"); | ||
const staticPaths: Record<string, GetStaticPathsItem> = {}; | ||
for (const entry of docEntries) { | ||
const [lang, ...fragments] = entry.slug.split("/"); | ||
const absSlug = path.posix.join("/", entry.slug); | ||
const slug = fragments.join("/"); | ||
staticPaths[entry.slug] = { | ||
params: { lang, slug }, | ||
props: { entry, slug: absSlug }, | ||
}; | ||
} | ||
for (const redir of redirYaml) { | ||
const entrySlug = redir.old.slice(1); | ||
const [lang, ...fragments] = entrySlug.split("/"); | ||
const slug = fragments.join("/"); | ||
staticPaths[entrySlug] = { | ||
params: { lang, slug }, | ||
props: { redirTarget: redir.new }, | ||
}; | ||
} | ||
return Object.values(staticPaths); | ||
const { lang, slug } = Astro.params; | ||
if (!isLang(lang) || !slug) { | ||
return new Response(null, { status: 404 }); | ||
} | ||
type Props = | ||
| { redirTarget: string } | ||
| { | ||
entry: CollectionEntry<"docs">; | ||
slug: string; | ||
}; | ||
const absSlug = `/${lang}/${slug}`; | ||
const redir = redirYaml.find(({ old }) => old === absSlug); | ||
if (redir) { | ||
return new Response(null, { | ||
status: 301, | ||
headers: { Location: redir.new }, | ||
}); | ||
} | ||
const lang = Astro.params.lang as Lang; | ||
const entries = await getCollection("docs"); | ||
const entry = entries.find((entry) => entry.slug === `${lang}/${slug}`); | ||
if (!entry) return new Response(null, { status: 404 }); | ||
--- | ||
|
||
{ | ||
match(Astro.props) | ||
.with({ redirTarget: P.string }, ({ redirTarget }) => | ||
redirTarget.startsWith("https:") ? ( | ||
<Redir target={redirTarget} /> | ||
) : ( | ||
<Redir target={`/docs${redirTarget}`} /> | ||
), | ||
) | ||
.with({ slug: P.string, entry: P.any }, ({ slug, entry }) => ( | ||
<Docs lang={lang} slug={slug} entry={entry} /> | ||
)) | ||
.exhaustive() | ||
} | ||
<Docs lang={lang} slug={absSlug} entry={entry} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
--- | ||
import Redir from "~/layouts/Redir.astro"; | ||
import { isLang } from "~/type"; | ||
import type { Lang } from "../../../type"; | ||
export async function getStaticPaths() { | ||
return ["ko", "en"].map((lang) => ({ params: { lang } })); | ||
} | ||
const lang = Astro.params.lang as Lang; | ||
const { lang } = Astro.params; | ||
if (!isLang(lang)) return new Response(null, { status: 404 }); | ||
return new Response(null, { | ||
status: 301, | ||
headers: { Location: `/docs/${lang}/readme` }, | ||
}); | ||
--- | ||
|
||
<Redir target={`/docs/${lang}/readme`} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
--- | ||
import Redir from "~/layouts/Redir.astro"; | ||
return new Response(null, { | ||
status: 301, | ||
headers: { | ||
Location: "/docs/ko/readme", | ||
}, | ||
}); | ||
--- | ||
|
||
<Redir target="/docs/ko/readme" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters