前端开发
在 Nuxt 项目中配置 SEO、生成…
适用于 Nuxt 应用的 SEO 基础配置、robots.txt/sitemap.xml 生成、动态 OG 图片、JSON-LD 结构化数据、面包屑与规范 URL 等任务。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
在 Nuxt 项目中配置 SEO、生成 特定
解决思路
- 安装模块:运行 `npx nuxi module add @nuxtjs/seo`。
- 按任务选择加载参考文件:配置站点 URL、名称或 SEO 基础时加载 `references/site-config.md`。
- 按任务选择加载参考文件:设置 robots.txt 或 sitemap.xml 时加载 `references/crawlability.md`。
- 按任务选择加载参考文件:生成动态 OG 图片时加载 `references/og-image.md`。
- 按任务选择加载参考文件:添加 JSON-LD 结构化数据时加载 `references/schema-org.md`。
- 按任务选择加载参考文件:处理面包屑、规范 URL 或链接检查时加载 `references/utilities.md`。
- 不要一次性加载所有参考文件;只加载与当前任务相关的文件。
- 在 `nuxt.config.ts` 中配置 `site`(如 URL、名称、可索引性等),作为所有 SEO 模块的基础。
- 通过 `useSiteConfig()` 访问站点配置;完整选项见 `references/site-config.md`。
- 使用 `nuxt-site-config` 做共享配置,关键 API 为 `useSiteConfig()`。
- 使用 `@nuxtjs/robots` 生成 robots.txt,关键 API 为 `useRobotsRule()`。
- 使用 `@nuxtjs/sitemap` 生成 sitemap.xml,关键 API 为 `defineSitemapEventHandler()`。
- 使用 `nuxt-og-image` 生成 OG images,关键 API 为 `defineOgImage()`。
- 使用 `nuxt-schema-org` 添加 JSON-LD,关键 API 为 `useSchemaOrg()`。
- 使用 `nuxt-seo-utils` 处理 Meta utilities,关键 API 为 `useBreadcrumbItems()`。
- 使用 `nuxt-link-checker` 做链接验证,采用构建时检查。
- 对 Nuxt Content v3,使用 `asSeoCollection()` 从 frontmatter 自动生成 sitemap、og-image 和 schema-org。
- 在 `content.config.ts` 中从 `@nuxt/content` 导入 `defineCollection`、`defineContentConfig`,并从 `@nuxtjs/seo/content` 导入 `asSeoCollection`。
- 在 `content.config.ts` 中用 `defineCollection(asSeoCollection({ type: 'page', source: 'posts/**' }))` 定义集合。
- 在 `modules` 数组中确保 `@nuxtjs/seo` 位于 `@nuxt/content` 之前,例如 `modules: ['@nuxtjs/seo', '@nuxt/content']`。
- 使用 frontmatter 字段:`ogImage`、`sitemap`、`robots`、`schemaOrg`。
- 如需 MDC 渲染与 SEO frontmatter,参考相关技能 `nuxt-content`(`../nuxt-content/SKILL.md`)。
- 查阅文档 `https://nuxtseo.com` 和 GitHub `https://github.com/harlan-zw/nuxt-seo`。
- 注意 token 效率:主技能约 250 tokens,每个子文件约 400-600 tokens;只加载与当前任务相关的文件。
适用边界 · 注意事项
- 非 Nuxt 项目,或无法安装/使用 `@nuxtjs/seo` 时。
- 当前任务不需要 SEO 配置、robots.txt、sitemap.xml、动态 OG 图片、JSON-LD 结构化数据、面包屑/规范 URL 或链接检查时。
- 不想引入该 meta-module,或只需要与这些模块无关的通用前端功能时。