'use client'; import { useState, useCallback, useEffect } from 'react'; import { useTranslation } from '../lib/i18n/useTranslation'; import { languages } from '../lib/i18n/config'; import { getNewsById, getAllNews, parseMarkdownContent, type NewsItem } from '../lib/news'; interface NewsDetailPageProps { initialLanguage?: string; newsId: string; } // 只保留元信息,正文内容已迁移到 md 文件 interface NewsArticleMeta { id: number; category: string; date: string; readTime: string; image: string; } // 仅示例,实际内容请从 md 文件读取 const newsArticles: NewsArticleMeta[] = [ { id: 1, category: 'product', date: '2024-01-15', readTime: '5 min', image: 'https://images.unsplash.com/photo-1504711434969-e33886168f5c?w=800&h=600&fit=crop', }, { id: 2, category: 'industry', date: '2024-01-12', readTime: '8 min', image: 'https://images.unsplash.com/photo-1586953208448-b95a79798f07?w=800&h=600&fit=crop', }, { id: 3, category: 'company', date: '2024-01-10', readTime: '3 min', image: 'https://images.unsplash.com/photo-1552664730-d307ca884978?w=800&h=600&fit=crop', }, ]; // 分类图标映射 const categoryIcons = { company: '🏢', product: '📦', industry: '🏭', technology: '💻', }; export default function NewsDetailPage({ initialLanguage, newsId }: NewsDetailPageProps) { const { language, t, changeLanguage, getLocalizedPath, isInitialized } = useTranslation(initialLanguage); const [isMenuOpen, setIsMenuOpen] = useState(false); const [showScrollTop, setShowScrollTop] = useState(false); const handleLanguageChange = useCallback( (newLanguage: string) => { changeLanguage(newLanguage as any); }, [changeLanguage], ); // 获取新闻元信息 const article = newsArticles.find((article) => article.id.toString() === newsId); // 滚动到顶部功能 const scrollToTop = () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }; // 监听滚动事件 useEffect(() => { const handleScroll = () => { setShowScrollTop(window.scrollY > 300); }; window.addEventListener('scroll', handleScroll); return () => window.removeEventListener('scroll', handleScroll); }, []); // 格式化日期 const formatDate = (dateString: string) => { const date = new Date(dateString); if (language === 'en') { return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); } else { return date.toLocaleDateString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric', }); } }; // 在语言初始化完成前显示加载状态 if (!isInitialized) { return (

Loading...

); } // 如果找不到文章,显示404页面 if (!article) { return (
📰

{language === 'en' ? 'Article Not Found' : language === 'zh-CN' ? '文章未找到' : '文章未找到'}

{language === 'en' ? 'The article you are looking for does not exist or has been moved.' : language === 'zh-CN' ? '您查找的文章不存在或已被移动。' : '您查找的文章不存在或已被移動。'}

{language === 'en' ? 'Back to News' : language === 'zh-CN' ? '返回新闻' : '返回新聞'}
); } // Navigation items const navItems = [ { key: 'home', label: t.nav.home, href: getLocalizedPath('/') }, { key: 'products', label: t.nav.products, href: getLocalizedPath('/products') }, { key: 'news', label: t.nav.news, href: getLocalizedPath('/news') }, { key: 'support', label: t.nav.support, href: getLocalizedPath('/support') }, { key: 'about', label: t.nav.about, href: getLocalizedPath('/about') }, ]; return (
{/* Navigation */} {/* Breadcrumb */}
{/* Article Header */}
{/* Category Badge */}
{categoryIcons[article.category as keyof typeof categoryIcons]} {language === 'en' ? article.category.charAt(0).toUpperCase() + article.category.slice(1) : article.category === 'company' ? language === 'zh-CN' ? '公司' : '公司' : article.category === 'product' ? language === 'zh-CN' ? '产品' : '產品' : article.category === 'industry' ? language === 'zh-CN' ? '行业' : '行業' : article.category === 'technology' ? language === 'zh-CN' ? '技术' : '技術' : article.category}
{/* Title */}

{article.category.charAt(0).toUpperCase() + article.category.slice(1)}

{/* Meta Information */}
{formatDate(article.date)}
{article.readTime}
{/* Featured Image */}
{
{/* CTA Section */}

{language === 'en' ? 'Stay Updated' : language === 'zh-CN' ? '保持更新' : '保持更新'}

{language === 'en' ? 'Subscribe to our newsletter and never miss important updates and insights.' : language === 'zh-CN' ? '订阅我们的新闻通讯,不要错过重要的更新和见解。' : '訂閱我們的新聞通訊,不要錯過重要的更新和見解。'}

{language === 'en' ? 'View All News' : language === 'zh-CN' ? '查看所有新闻' : '查看所有新聞'}
{/* 回到顶部按钮 */} {showScrollTop && ( )} {/* Footer */}
); }