{
  "id": "build-a-nextjs-ai-tool-directory",
  "type": "prompts",
  "category": "prompts",
  "locale": "zh",
  "url": "/zh/prompts/build-a-nextjs-ai-tool-directory",
  "title": "构建Next.js AI工具目录的提示词",
  "description": "用于构建可搜索的Next.js AI工具目录的AI智能体提示词，支持MDX数据文件、分类筛选和静态生成。",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Next.js",
    "TypeScript",
    "Tailwind"
  ],
  "tags": [
    "nextjs",
    "typescript",
    "tailwind",
    "seo",
    "search"
  ],
  "difficulty": "medium",
  "updated": "2026-06-08",
  "markdown": "将此提示词交给你的智能体，用于构建一个静态生成的、SEO友好的AI工具目录，支持分类筛选、客户端搜索和每个工具的详情页——当平面MDX文件足够时，无需使用数据库。\n\n## 主要提示词\n\n```txt title=\"Main Prompt\"\nYou are building a new Next.js 15 App Router project using TypeScript and Tailwind CSS v4.\n\nTask: build an AI tool directory site.\n\nData model — each tool is a `.mdx` file in `src/data/tools/` with this frontmatter:\n  name, slug, tagline, description, category, website, pricing ('free'|'freemium'|'paid'),\n  tags (string[]), logo (relative path to public/).\n\nRequirements:\n- `src/lib/tools.ts`: read all MDX files at build time using `fs` + `gray-matter`; export\n  `getAllTools()` returning `Tool[]` and `getToolBySlug(slug)` returning `Tool | undefined`.\n- `src/app/page.tsx`: static page showing a grid of `<ToolCard>` components.\n  - A `<CategoryFilter>` client component that filters by category using URL search params\n    (`?category=writing`). Use `useSearchParams` — no external state library.\n  - A `<SearchBar>` client component that does client-side substring match on name and tagline\n    using `useSearchParams` (`?q=cursor`).\n- `src/app/tools/[slug]/page.tsx`: static detail page with `generateStaticParams` and\n  `generateMetadata`. Include og:title, og:description, og:image (the tool logo).\n- `src/app/categories/[category]/page.tsx`: static list filtered by category.\n- Seed data: create 5 real AI coding tools as MDX files (Cursor, GitHub Copilot, Claude Code,\n  Codeium, Tabnine) with accurate free/paid info.\n- Do NOT use a database, Contentlayer, or next-mdx-remote. Use `gray-matter` + `fs` only.\n\nStop and list all planned files before writing code.\n```\n\n## 实现注意事项\n\n- `getAllTools()`必须仅在服务器端运行；在客户端组件中调用它会将`fs`暴露给浏览器并导致构建崩溃。将数据作为props传递给客户端组件。\n- 为`[slug]`使用的`generateStaticParams`应调用`getAllTools()`并映射到`{ slug }`对象。\n- 对于分类页面，应从工具数据中推导出分类列表，而不是硬编码。\n\n## 预期文件变更\n\n```txt\nsrc/lib/tools.ts                              (new)\nsrc/app/page.tsx                              (new)\nsrc/app/tools/[slug]/page.tsx                 (new)\nsrc/app/categories/[category]/page.tsx        (new)\nsrc/components/ToolCard.tsx                   (new)\nsrc/components/CategoryFilter.tsx             (new — Client)\nsrc/components/SearchBar.tsx                  (new — Client)\nsrc/data/tools/cursor.mdx                     (new)\nsrc/data/tools/github-copilot.mdx            (new)\nsrc/data/tools/claude-code.mdx               (new)\nsrc/data/tools/codeium.mdx                   (new)\nsrc/data/tools/tabnine.mdx                   (new)\n```\n\n## 验收标准\n\n- `bun run build`命令退出代码为0，并为每个工具slug生成静态页面。\n- 点击分类筛选器会更新URL并过滤网格，而无需完全重新加载。\n- 每个工具详情页在HTML的`<head>`中都有唯一的`og:title`和`og:description`。\n- 搜索\"cursor\"时仅显示Cursor卡片。\n\n## 测试命令\n\n```bash\nbun run typecheck\nbun run build\nbun run start\ncurl -s http://localhost:3000/tools/cursor | grep 'og:title'\n# navigate to /?category=writing and confirm filter\n```\n\n## 常见AI错误\n\n- 在客户端组件中调用`getAllTools()`，导致`fs`模块错误而破坏构建。\n- 在`[slug]`页面上忘记`generateStaticParams`，导致静态导出出现404错误。\n- 在提示词明确禁止的情况下使用`next-mdx-remote`。\n- 硬编码分类列表，而不是从工具数据中推导。\n\n## 修复提示词\n\n```txt title=\"Fix Prompt\"\nThe build fails because `fs` is used in a client component, or static pages are not generated.\nFix in order:\n1. Move `getAllTools()` to a Server Component and pass the `tools` array as a prop to\n   `CategoryFilter` and `SearchBar`.\n2. Add `export async function generateStaticParams()` to `src/app/tools/[slug]/page.tsx`.\n3. Confirm `gray-matter` is installed: `bun add gray-matter`.\nShow only the corrected diff.\n```"
}