- 创建 Next.js + TypeScript + Tailwind CSS Web 应用 - 支持 Markdown 渲染和 GFM 格式 - 支持 Obsidian 风格 wiki 链接 [[Page|Label]] - 侧边栏导航,按分类组织页面 - 图片资源支持(通过 API 路由从 wiki/assets 提供) - 响应式设计 - 更新 README 添加 Web 应用使用说明
38 lines
1.0 KiB
TypeScript
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 });
|
|
}
|
|
}
|