'use client'; import { useState, useEffect } from 'react'; import { Navigation } from '../../components/Navigation'; import { Footer } from '../../components/Footer'; import { Head } from '../../components/Head'; import { Calendar, User, Tag, ArrowRight, Clock } from 'lucide-react'; import Link from 'next/link'; interface NewsArticle { id: string; category: string; title: string; excerpt: string; author: string; date: string; readTime: number; image?: string; } export default function NewsPage() { const [currentLang, setCurrentLang] = useState<'zh' | 'zh-tw' | 'en'>('zh'); const [selectedCategory, setSelectedCategory] = useState('all'); const [articles, setArticles] = useState([]); const [loading, setLoading] = useState(true); const translations = { zh: { title: '资讯中心 - CloudPro 云服务器代理商', description: '获取最新的云计算资讯、技术文章、产品更新和行业动态,了解云服务器和云计算的最新发展趋势。', keywords: '云计算资讯,技术文章,产品更新,行业动态,云服务器新闻', nav: { home: '首页', products: '产品', solutions: '解决方案', support: '支持', news: '资讯', contact: '联系我们', }, hero: { title: '资讯中心', subtitle: '了解云计算最新动态', description: '获取最新的技术资讯、产品更新和行业洞察', }, categories: { all: '全部', tech: '技术文章', product: '产品更新', industry: '行业动态', tutorial: '教程指南', }, readMore: '阅读更多', readTime: '阅读时间', minutes: '分钟', loading: '加载中...', noArticles: '暂无文章', }, 'zh-tw': { title: '資訊中心 - CloudPro 雲伺服器代理商', description: '獲取最新的雲端運算資訊、技術文章、產品更新和行業動態,了解雲伺服器和雲端運算的最新發展趨勢。', keywords: '雲端運算資訊,技術文章,產品更新,行業動態,雲伺服器新聞', nav: { home: '首頁', products: '產品', solutions: '解決方案', support: '支援', news: '資訊', contact: '聯絡我們', }, hero: { title: '資訊中心', subtitle: '了解雲端運算最新動態', description: '獲取最新的技術資訊、產品更新和行業洞察', }, categories: { all: '全部', tech: '技術文章', product: '產品更新', industry: '行業動態', tutorial: '教學指南', }, readMore: '閱讀更多', readTime: '閱讀時間', minutes: '分鐘', loading: '載入中...', noArticles: '暫無文章', }, en: { title: 'News Center - CloudPro Cloud Server Reseller', description: 'Get the latest cloud computing news, technical articles, product updates and industry insights about cloud servers and cloud computing trends.', keywords: 'cloud computing news,technical articles,product updates,industry insights,cloud server news', nav: { home: 'Home', products: 'Products', solutions: 'Solutions', support: 'Support', news: 'News', contact: 'Contact', }, hero: { title: 'News Center', subtitle: 'Stay Updated with Cloud Computing', description: 'Get the latest technical insights, product updates and industry news', }, categories: { all: 'All', tech: 'Technical Articles', product: 'Product Updates', industry: 'Industry News', tutorial: 'Tutorials', }, readMore: 'Read More', readTime: 'Read Time', minutes: 'min', loading: 'Loading...', noArticles: 'No articles found', }, }; const t = translations[currentLang]; useEffect(() => { const browserLang = navigator.language.toLowerCase(); if (browserLang.includes('en')) { setCurrentLang('en'); } else if (browserLang.includes('zh-tw') || browserLang.includes('zh-hk')) { setCurrentLang('zh-tw'); } }, []); useEffect(() => { const loadArticles = async () => { try { setLoading(true); // 获取所有文章目录 const response = await fetch('/api/articles'); if (response.ok) { const articlesData = await response.json(); setArticles(articlesData); } else { console.error('Failed to load articles'); setArticles([]); } } catch (error) { console.error('Error loading articles:', error); setArticles([]); } finally { setLoading(false); } }; loadArticles(); }, []); const filteredArticles = selectedCategory === 'all' ? articles : articles.filter((article) => article.category === selectedCategory); const getCategoryColor = (category: string) => { const colors = { tech: 'bg-blue-100 text-blue-800', product: 'bg-green-100 text-green-800', industry: 'bg-purple-100 text-purple-800', tutorial: 'bg-orange-100 text-orange-800', }; return colors[category as keyof typeof colors] || 'bg-gray-100 text-gray-800'; }; if (loading) { return (

{t.loading}

); } return (
{/* Hero Section */}

{t.hero.title}

{t.hero.subtitle}

{t.hero.description}

{/* Category Filter */}
{Object.entries(t.categories).map(([key, label]) => ( ))}
{/* News Grid */}
{filteredArticles.length === 0 ? (

{t.noArticles}

) : (
{filteredArticles.map((article) => (
📰
{t.categories[article.category as keyof typeof t.categories] || article.category}
{article.readTime} {t.minutes}

{article.title}

{article.excerpt}

{article.author}
{article.date}
{t.readMore}
))}
)}
); }