--- import Layout from "@/layouts/Layout.astro" import Item from "@/components/Item.astro" import StreetSnap from "@/components/StreetSnap.astro" import { getSsrArticle, getSsrStreetSnap } from "@/lib/api" import { getI18n } from "@/i18n/utils" // 按需 SSR:走秀(runway)与街拍(street snap)详情统一收口到 /item/[id]。 // 对外 id 带类型前缀(r=runway / s=snap,见后端 hashid.EncodeTyped),据此直接查对应表,无歧义、无需回落。 export const prerender = false const { id } = Astro.params const isSnap = !!id && id[0] === "s" const { t } = getI18n(Astro) let article = null let articleErr = null let snap = null let snapErr = null let preview = false let imageTotal = 0 // 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 } preview = data.preview ?? false imageTotal = data.imageTotal ?? 0 // 供客户端「收藏 / 历史」使用的精简元信息(服务端已拿到,直接透传,避免前端再发请求)。 const meta = isSnap ? { id: id ?? "", type: "street", title: snap?.title ?? "", cover: snap?.cover ?? "", brand: "" } : { id: id ?? "", type: "runway", title: article?.title ?? "", cover: article?.cover ?? "", brand: article?.brand_name ?? "" } const saveLabel = t("save") const savedLabel = t("saved") --- {article ? : } {(article || snap) && ( )} {/* 注意:不能用 define:vars 传 meta —— 它会把脚本包成内联 IIFE 并把 import 塞进函数体内, 导致 SyntaxError(import 只能在模块顶层)。故改由 data-* 属性透传,脚本自行读取。 */}