Files
frontend_v2/src/pages/article.astro
toom1996 d14dd7e2db
Some checks failed
deploy / deploy (push) Has been cancelled
update
2026-08-18 20:33:56 +08:00

28 lines
828 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
import Layout from "@/layouts/Layout.astro"
import Article from "@/components/pages/article.astro"
import { fetchArticleById } from "@/lib/data"
// 按需 SSR:服务端按 ?id= 取数并渲染(保留既有 /article?id= 链接,无需改动其他页面)
export const prerender = false
const API = (import.meta.env.API_SSR || import.meta.env.PUBLIC_API_BASE || "http://localhost:8090").replace(/\/$/, "")
const id = Astro.url.searchParams.get("id")
let article: import("@/lib/data").RawArticle | null = null
let error: "missing" | "failed" | null = null
if (!id) {
error = "missing"
} else {
try {
article = await fetchArticleById(id, API)
} catch {
article = null
}
error = article ? null : "failed"
}
---
<Layout>
<Article article={article} locale="en" apiBase={API} error={error} />
</Layout>