--- import { getCollection, type CollectionEntry } from "astro:content"; import MainLayout from "../../components/MainLayout.astro"; // 定义Props类型 export interface Props { entry: CollectionEntry<"culture">; } // 生成静态路径 export async function getStaticPaths() { const cultures = await getCollection("culture"); return cultures.map((entry) => ({ params: { slug: entry.slug }, props: { entry }, })); } // 获取当前文化数据 const { entry } = Astro.props; const { Content } = await entry.render(); // 获取相关文化 const allCultures = await getCollection("culture"); const relatedCultures = allCultures .filter( (item) => item.slug !== entry.slug && item.data.tags.some((tag) => entry.data.tags.includes(tag)) ) .slice(0, 3); ---
返回文化列表
首页 / 文化 / {entry.data.title}

{entry.data.title}

{entry.data.city && entry.data.city.length > 0 && (
📍 {entry.data.city.map((cityName, index) => ( <> {cityName} {index < entry.data.city.length - 1 && , } ))}
)} {entry.data.pubDate && (
📅 {new Date(entry.data.pubDate).toLocaleDateString('zh-CN')}
)}
🏷️ {entry.data.category}
{entry.data.tags.map((tag) => ( {tag} ))}

{entry.data.description}

{entry.data.image ? ( {entry.data.title} ) : ( {entry.data.title} 图片 )}

文化信息

{entry.data.city && entry.data.city.length > 0 && (
分布地区:
{entry.data.city.map((cityName, index) => ( <> {cityName} {index < entry.data.city.length - 1 && , } ))}
)}
文化类型: {entry.data.category}
特色标签:
{entry.data.tags.map((tag) => ( {tag} ))}
{entry.data.pubDate && (
发布时间: {new Date(entry.data.pubDate).toLocaleDateString('zh-CN')}
)}
{relatedCultures.length > 0 && ( )}