在v0上继续开发
导入Cursor项目
准备工作
1. 提交本地更改
# 确保所有更改已提交
git add .
git commit -m "Complete initial development in Cursor"
git push origin main
2. 项目清理
- 删除不必要的临时文件
- 整理项目结构
- 更新.gitignore文件
3. 检查依赖
# 确保package.json中的依赖是最新的
npm outdated
npm update
在v0上开发新功能
评论系统实现
标签系统优化
标签组件
// components/TagCloud.tsx
import { useState, useEffect } from 'react';
import Link from 'next/link';
interface Tag {
name: string;
count: number;
}
export function TagCloud() {
const [tags, setTags] = useState<Tag[]>([]);
const [selectedTag, setSelectedTag] = useState<string | null>(null);
useEffect(() => {
fetch('/api/tags')
.then(res => res.json())
.then(data => setTags(data))
.catch(error => console.error('Error fetching tags:', error));
}, []);
return (
<div className="p-4 bg-gray-50 rounded-lg">
<h3 className="text-lg font-semibold mb-4">标签云</h3>
<div className="flex flex-wrap gap-2">
{tags.map(tag => (
<Link
key={tag.name}
href={`/tags/${tag.name}`}
className={`px-3 py-1 rounded-full text-sm ${
selectedTag === tag.name
? 'bg-blue-500 text-white'
: 'bg-white hover:bg-blue-100'
}`}
onClick={() => setSelectedTag(tag.name)}
>
{tag.name} ({tag.count})
</Link>
))}
</div>
</div>
);
}
标签API
// pages/api/tags.ts
import { NextApiRequest, NextApiResponse } from 'next';
import { prisma } from '@/lib/prisma';
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === 'GET') {
try {
const tags = await prisma.tag.findMany({
include: {
_count: {
select: { posts: true }
}
}
});
const formattedTags = tags.map(tag => ({
name: tag.name,
count: tag._count.posts
}));
res.status(200).json(formattedTags);
} catch (error) {
res.status(500).json({ message: 'Error fetching tags' });
}
} else {
res.setHeader('Allow', ['GET']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
评论组件
API路由