import { notFound } from 'next/navigation'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { getTranslations, Locale, getNavigationPaths, defaultLocale } from '@/lib/i18n'; import { generateMetadata as generateSEOMetadata } from '@/lib/seo'; import { getNewsArticle, getAvailableLocalesForArticle, checkArticleExists } from '@/lib/markdown'; import Layout from '@/components/Layout'; import LanguageSwitcher from '@/components/LanguageSwitcher'; import Link from 'next/link'; interface NewsDetailPageProps { params: { id: string; }; } export async function generateStaticParams() { // 默认语言的文章ID const articles = ['ai-transformation-2024', 'cloud-security-best-practices', 'company-expansion-2024']; return articles.map((id) => ({ id })); } export async function generateMetadata({ params }: NewsDetailPageProps) { const { id } = params; const locale = defaultLocale; // 使用默认语言 // Check if article exists if (!checkArticleExists(id, locale)) { return { title: 'Article Not Found', description: 'The requested article could not be found.', }; } const article = await getNewsArticle(id, locale); if (!article) { return { title: 'Article Not Found', description: 'The requested article could not be found.', }; } return { title: article.title, description: article.excerpt, openGraph: { title: article.title, description: article.excerpt, type: 'article', publishedTime: article.date, authors: [article.author], tags: article.tags, }, }; } export default async function NewsDetailPage({ params }: NewsDetailPageProps) { const { id } = params; const locale = defaultLocale; // 使用默认语言 // Check if article exists in the requested locale if (!checkArticleExists(id, locale)) { notFound(); } const article = await getNewsArticle(id, locale); if (!article) { notFound(); } const [common, availableLocales] = await Promise.all([ getTranslations(locale, 'common'), getAvailableLocalesForArticle(id), ]); const navigationPaths = getNavigationPaths(locale); const navigation = [ { name: common.navigation.home, href: navigationPaths.find((p) => p.key === 'home')?.path || '/', }, { name: common.navigation.products, href: navigationPaths.find((p) => p.key === 'products')?.path || '/products', }, { name: common.navigation.news, href: navigationPaths.find((p) => p.key === 'news')?.path || '/news', }, { name: common.navigation.support, href: navigationPaths.find((p) => p.key === 'support')?.path || '/support', }, { name: common.navigation.about, href: navigationPaths.find((p) => p.key === 'about')?.path || '/about', }, ]; return ( {/* Breadcrumb */}
{/* Language Switcher */}
可用语言:
{/* Back to News */} p.key === 'news')?.path || '/news'} className="text-sm text-blue-600 hover:text-blue-800 flex items-center space-x-1" > 返回新闻
{/* Article Header */}
{article.category} {article.featured && ( 精选 )}

{article.title}

{article.date}
{article.author}
{article.readTime}

{article.excerpt}

{/* Tags */} {article.tags.length > 0 && (
{article.tags.map((tag) => ( #{tag} ))}
)}
{/* Article Content */}
(

{children}

), h2: ({ children }) => (

{children}

), h3: ({ children }) => (

{children}

), p: ({ children }) => (

{children}

), ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), li: ({ children }) => (
  • {children}
  • ), blockquote: ({ children }) => (
    {children}
    ), code: ({ children }) => ( {children} ), pre: ({ children }) => (
                                            {children}
                                        
    ), }} > {article.content}
    {/* Related Articles */}

    相关文章

    {/* 这里可以添加相关文章的逻辑 */}

    更多新闻即将发布

    请持续关注我们的最新动态和行业见解。

    ); }