import { NextRequest, NextResponse } from 'next/server'; import fs from 'fs'; import path from 'path'; export async function GET( request: NextRequest, { params }: { params: { locale: string } } ) { try { const locale = params.locale; const articlesPath = path.join(process.cwd(), 'public', 'docs', locale, 'news'); // 检查目录是否存在 if (!fs.existsSync(articlesPath)) { return NextResponse.json({ articles: [] }); } // 读取目录下的所有 .md 文件 const files = fs.readdirSync(articlesPath) .filter(file => file.endsWith('.md')) .map(file => file.replace('.md', '')); console.log(`📁 Found articles in ${locale}/news:`, files); return NextResponse.json({ articles: files, count: files.length }); } catch (error) { console.error('Error scanning articles:', error); return NextResponse.json({ articles: [], error: 'Failed to scan articles' }, { status: 500 }); } }