Files
Junjian Wang 3b6dc2e9fc 添加 Next.js Web 应用
- 创建 Next.js + TypeScript + Tailwind CSS Web 应用
- 支持 Markdown 渲染和 GFM 格式
- 支持 Obsidian 风格 wiki 链接 [[Page|Label]]
- 侧边栏导航,按分类组织页面
- 图片资源支持(通过 API 路由从 wiki/assets 提供)
- 响应式设计
- 更新 README 添加 Web 应用使用说明
2026-04-13 20:54:14 +08:00

38 lines
1.0 KiB
TypeScript

import { NextResponse } from 'next/server';
import fs from 'fs';
import path from 'path';
export async function GET(
_request: Request,
{ params }: { params: Promise<{ path: string[] }> }
) {
const { path: pathSegments } = await params;
const assetPath = path.join(process.cwd(), '../wiki/assets', ...pathSegments);
try {
if (!fs.existsSync(assetPath)) {
return NextResponse.json({ error: 'Not found' }, { status: 404 });
}
const fileBuffer = fs.readFileSync(assetPath);
const ext = path.extname(assetPath).toLowerCase();
const contentTypeMap: Record<string, string> = {
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.webp': 'image/webp',
};
return new NextResponse(fileBuffer, {
headers: {
'Content-Type': contentTypeMap[ext] || 'application/octet-stream',
},
});
} catch (e) {
return NextResponse.json({ error: 'Not found' }, { status: 404 });
}
}