UPDATE
Some checks failed
deploy / deploy (push) Has been cancelled

This commit is contained in:
toom1996
2026-08-22 01:51:42 +08:00
parent 975c55feb2
commit 0df14036cf
16 changed files with 270 additions and 1023 deletions

View File

@ -11,13 +11,13 @@
const API_BASE = ((import.meta as any).env?.PUBLIC_API_BASE ?? "").replace(/\/$/, "")
export type RawArticle = {
id: number
id: string | number // 后端为 hashid 编码串(string);示例数据回落为数字
title: string
summary?: string
description?: string
cover: string
brand_name: string
brand_id?: number
brand_id?: string | number // hashid 编码串
year: number
image_count: number
published_at: number
@ -26,7 +26,7 @@ export type RawArticle = {
collection_type?: string
season?: string
season_code?: string
images?: { id: number; image: string; name?: string }[]
images?: { id?: number; image: string; name?: string }[]
}
// ---------- 通用辅助 ----------
@ -62,7 +62,7 @@ export function fmtDate(t: number | string): string {
// ---------- 内置示例(后端不可达时回落) ----------
const BRANDS = ["MAISON LUMEN", "STUDIO VANTA", "ATELIER NOIR", "KÔ", "CÉLESTE", "RIVE GAUCHE"]
const SAMPLE: RawArticle[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
id: String(i + 1),
title: `Collection ${String(i + 1).padStart(2, "0")}`,
brand_name: BRANDS[i % BRANDS.length],
year: 2023 + (i % 4),
@ -120,6 +120,7 @@ export async function fetchArticleById(id: number | string, apiBase: string = AP
if (!base) return null
try {
const res = await fetch(`${base}/api/public/articles/${id}`)
console.log(`${base}/api/public/articles/${id}`)
if (!res.ok) return null
const json: any = await res.json()
return json?.data ?? null
@ -133,7 +134,7 @@ export async function fetchArticleById(id: number | string, apiBase: string = AP
// (接口仅暴露 runway 文章一类数据,四块面板取真实列表的不同区段,避免重复同一批内容)
export type ArticleCard = {
id: number
id: string | number
brand: string
title: string
season: string // 季节码,如 AW16
@ -209,7 +210,7 @@ export function loadArticlesWithImages(size = 40): Promise<ArticleCard[]> {
// attachGallery 在构建期(SSG)为每个展示文章预取其真实多图(前 3 张),
// 供首页卡片直接渲染"图片堆",无需等到悬停才拉取。后端不可达时 gallery 为空。
async function attachGallery<T extends { id: number; gallery: string[] }>(items: T[]): Promise<T[]> {
async function attachGallery<T extends { id: string | number; gallery: string[] }>(items: T[]): Promise<T[]> {
return await Promise.all(
items.map(async (it) => {
let gallery: string[] = []
@ -226,7 +227,7 @@ async function attachGallery<T extends { id: number; gallery: string[] }>(items:
}
export type ColorItem = {
id: number
id: string | number
name: string
brand: string
season: string
@ -306,7 +307,7 @@ export async function getSite(): Promise<SiteInfo> {
// ---------- 文章画廊(/articles)所需结构 ----------
export type ReportItem = {
id: number
id: string | number
brand: string
title: string
year: number