mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-14 12:44:36 +00:00
wip(docs): i18n (#12681)
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
import type { APIRoute } from "astro"
|
||||
import { getCollection } from "astro:content"
|
||||
|
||||
export const GET: APIRoute = async ({ params }) => {
|
||||
function notFoundText(locals: unknown) {
|
||||
if (typeof locals !== "object" || locals === null || !("t" in locals)) {
|
||||
return "share.not_found"
|
||||
}
|
||||
const t = (locals as { t?: unknown }).t
|
||||
if (typeof t !== "function") {
|
||||
return "share.not_found"
|
||||
}
|
||||
const text = t("share.not_found")
|
||||
if (typeof text === "string" && text.length > 0) {
|
||||
return text
|
||||
}
|
||||
return "share.not_found"
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async ({ params, locals }) => {
|
||||
const slug = params.slug || "index"
|
||||
const docs = await getCollection("docs")
|
||||
const doc = docs.find((d) => d.id === slug)
|
||||
const notFound = notFoundText(locals)
|
||||
|
||||
if (!doc) {
|
||||
return new Response("Not found", { status: 404 })
|
||||
return new Response(notFound, { status: 404, statusText: notFound })
|
||||
}
|
||||
|
||||
return new Response(doc.body, {
|
||||
|
||||
Reference in New Issue
Block a user