--- import { type Lang } from '@/types/i18n'; import { useTranslations } from '@/i18n/utils'; export interface Props { lang: Lang; publishDate?: string; readingTime?: number; tags?: string[]; tagId?: string[]; category?: string | string[]; categoryId?: string[] | string; className?: string; } const { lang, publishDate, readingTime, tags, tagId, category, categoryId, className = '' } = Astro.props; const t = useTranslations(lang); /** * Format date according to locale */ const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleDateString(lang === 'zh' ? 'zh-CN' : 'en-US', { year: 'numeric', month: 'long', day: 'numeric' }); }; /** * Get reading time text based on language */ const getReadingTimeText = (minutes: number) => { if (lang === 'zh') { return `${minutes} 分钟阅读`; } return `${minutes} min read`; }; ---
{publishDate && (
)} {readingTime && (
{getReadingTimeText(readingTime)}
)}
{(category || (tags && tags.length > 0)) && (
{category && (
{lang === 'zh' ? '分类' : 'Categories'}
{Array.isArray(category) ? ( category.map((cat, index) => { // 获取对应的 categoryId,如果存在 const catId = categoryId && Array.isArray(categoryId) && index < categoryId.length ? categoryId[index] : cat.toLowerCase(); return ( {cat} ); }) ) : ( {category} )}
)} {tags && tags.length > 0 && (
{lang === 'zh' ? '标签' : 'Tags'}
{tags.map((tag, index) => { // 获取对应的 tagId,如果存在 const tagRoute = tagId && Array.isArray(tagId) && index < tagId.length ? tagId[index] : tag.toLowerCase(); return ( # {tag} ); })}
)}
)}