@ -4,19 +4,29 @@ import Item from "@/components/Item.astro"
|
||||
import StreetSnap from "@/components/StreetSnap.astro"
|
||||
import { getSsrArticle, getSsrStreetSnap } from "@/lib/api"
|
||||
|
||||
// 按需 SSR:走秀详情与街拍详情统一收口到 /item/[id]。
|
||||
// 先按 article 取数(runway lookbook);取不到再回落 street snap,实现「所有详情进 /item」。
|
||||
// 按需 SSR:走秀(runway)与街拍(street snap)详情统一收口到 /item/[id]。
|
||||
// 对外 id 带类型前缀(r=runway / s=snap,见后端 hashid.EncodeTyped),据此直接查对应表,无歧义、无需回落。
|
||||
export const prerender = false
|
||||
|
||||
const { id } = Astro.params
|
||||
const { article, error: articleErr } = await getSsrArticle(id, Astro.currentLocale)
|
||||
const isSnap = !!id && id[0] === "s"
|
||||
|
||||
let article = null
|
||||
let articleErr = null
|
||||
let snap = null
|
||||
let snapErr: "missing" | "failed" | null = null
|
||||
if (!article) {
|
||||
const res = await getSsrStreetSnap(id, Astro.currentLocale)
|
||||
snap = res.snap
|
||||
snapErr = res.error
|
||||
let snapErr = null
|
||||
|
||||
// await 必须位于 frontmatter 顶层(Astro 不支持块内顶层 await)
|
||||
const data = isSnap
|
||||
? await getSsrStreetSnap(id, Astro.currentLocale)
|
||||
: await getSsrArticle(id, Astro.currentLocale)
|
||||
|
||||
if (isSnap) {
|
||||
snap = data.snap
|
||||
snapErr = data.error
|
||||
} else {
|
||||
article = data.article
|
||||
articleErr = data.error
|
||||
}
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user