seo-meta-tags
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSEO Meta Tags
SEO元标签
Boilerplate and component library for production-ready metadata across three framework targets.
适用于三个框架目标的生产就绪型元数据模板和组件库。
Decision Tree
决策树
Determine the correct framework path first:
- Static HTML site or any-backend project — Read references/html.md
- Next.js 13+ App Router — Read references/nextjs.md
- Vite + React — Read references/vite.md, React section
- Vite + Vue 3 — Read references/vite.md, Vue section
- Multiple frameworks at once — Read all relevant reference files
Then determine action type:
- Creating metadata from scratch? — Read matching reference → copy boilerplate → replace placeholders.
- Updating existing metadata? — Load file → keep structure → change requested values → verify parity across tag families.
- Auditing / reviewing metadata? — Run through Quality Gate below → report issues.
- Migrating between frameworks? — Read source reference → read target reference → map fields.
首先确定正确的框架路径:
- 静态HTML站点或任意后端项目 — 阅读references/html.md
- Next.js 13+ App Router — 阅读references/nextjs.md
- Vite + React — 阅读references/vite.md中的React章节
- Vite + Vue 3 — 阅读references/vite.md中的Vue章节
- 同时使用多个框架 — 阅读所有相关参考文件
然后确定操作类型:
- 从零开始创建元数据? — 阅读对应参考文档 → 复制模板 → 替换占位符。
- 更新现有元数据? — 加载文件 → 保留结构 → 修改指定值 → 确保各元数据家族内容一致。
- 审核/检查元数据? — 执行下方的质量检查项 → 报告问题。
- 在框架间迁移? — 阅读源框架参考文档 → 阅读目标框架参考文档 → 映射字段。
Framework Selection
框架选择
| Framework | When to use | Reference |
|---|---|---|
| HTML | Static sites, any backend, SSGs | references/html.md |
| Next.js | Next.js 13+ App Router projects | references/nextjs.md |
| Vite | Vite + React or Vite + Vue apps | references/vite.md |
Read only the reference file that matches the user's target framework.
| 框架 | 使用场景 | 参考文档 |
|---|---|---|
| HTML | 静态站点、任意后端、静态站点生成器 | references/html.md |
| Next.js | Next.js 13+ App Router 项目 | references/nextjs.md |
| Vite | Vite + React 或 Vite + Vue 应用 | references/vite.md |
仅阅读与用户目标框架匹配的参考文件。
Metadata Families
元数据家族
Every framework target must keep parity across these families. When modifying one family, verify the others remain consistent.
每个框架目标都必须保持这些元数据家族之间的一致性。修改其中一个家族时,需验证其他家族内容是否一致。
1. Essential / Primary
1. 核心/基础元数据
| Tag | Constraint |
|---|---|
| Under 60 characters |
| 150-160 characters |
| 5-10 terms max, comma-separated |
| Full name |
| |
| Absolute URL, must match deployment URL |
| |
| 标签 | 约束条件 |
|---|---|
| 长度不超过60个字符 |
| 长度为150-160个字符 |
| 最多5-10个术语,用逗号分隔 |
| 完整姓名 |
| 默认值为 |
| 绝对URL,必须与部署URL一致 |
| |
2. Open Graph (og:*
)
og:*2. Open Graph(og:*
)
og:*| Property | Notes |
|---|---|
| |
| Absolute URL |
| Can differ from |
| Can differ from meta description |
| Absolute URL, 1200x630px, JPG or PNG, under 1 MB |
| |
| Required when image is present |
| Brand name |
| e.g. |
For type also include: , , , .
articlearticle:published_timearticle:modified_timearticle:authorarticle:tag| 属性 | 说明 |
|---|---|
| 首页/落地页用 |
| 绝对URL |
| 可与 |
| 可与meta description不同 |
| 绝对URL,尺寸1200x630px,格式为JPG或PNG,大小不超过1 MB |
| |
| 存在图片时必须设置 |
| 品牌名称 |
| 示例: |
对于类型,还需包含:, , , 。
articlearticle:published_timearticle:modified_timearticle:authorarticle:tag3. Twitter Cards (twitter:*
)
twitter:*3. Twitter Cards(twitter:*
)
twitter:*| Property | Notes |
|---|---|
| |
| Organization handle with |
| Author handle with |
| Under 70 characters |
| Under 200 characters |
| Same spec as OG image |
| Required when image is present |
| 属性 | 说明 |
|---|---|
| 默认值为 |
| 带 |
| 带 |
| 长度不超过70个字符 |
| 长度不超过200个字符 |
| 与Open Graph图片规格一致 |
| 存在图片时必须设置 |
4. Theme Color
4. 主题色
Provide three values:
- Default: or single value
<meta name="theme-color" content="..."> - Light:
media="(prefers-color-scheme: light)" - Dark:
media="(prefers-color-scheme: dark)"
Next.js uses the array in the Metadata object.
themeColor提供三个值:
- 默认值:或单个值
<meta name="theme-color" content="..."> - 浅色模式:
media="(prefers-color-scheme: light)" - 深色模式:
media="(prefers-color-scheme: dark)"
Next.js 中需在Metadata对象的数组中配置。
themeColor5. Icons and Manifest
5. 图标和清单
| Asset | Size | Format |
|---|---|---|
| 32x32 or multi-size | ICO |
| 16x16 | PNG |
| 32x32 | PNG |
| 180x180 | PNG |
| n/a | JSON |
Generate with favicon.io or RealFaviconGenerator.
| 资源 | 尺寸 | 格式 |
|---|---|---|
| 32x32 或多尺寸 | ICO |
| 16x16 | PNG |
| 32x32 | PNG |
| 180x180 | PNG |
| 无要求 | JSON |
6. Structured Data (JSON-LD)
6. 结构化数据(JSON-LD)
Emit a block (HTML/Vite) or use a separate Script component in Next.js. Required keys:
<script type="application/ld+json">json
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "",
"description": "",
"url": "",
"image": { "@type": "ImageObject", "url": "", "width": 1200, "height": 630 },
"author": { "@type": "Person", "name": "" },
"publisher": {
"@type": "Organization",
"name": "",
"logo": { "@type": "ImageObject", "url": "" }
}
}Common values: , , , , , .
@typeWebSiteArticleOrganizationProductFAQPageBreadcrumbList在HTML/Vite中添加代码块,在Next.js中使用独立的Script组件。必填字段:
<script type="application/ld+json">json
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "",
"description": "",
"url": "",
"image": { "@type": "ImageObject", "url": "", "width": 1200, "height": 630 },
"author": { "@type": "Person", "name": "" },
"publisher": {
"@type": "Organization",
"name": "",
"logo": { "@type": "ImageObject", "url": "" }
}
}常见的值:, , , , , 。
@typeWebSiteArticleOrganizationProductFAQPageBreadcrumbList7. Internationalization (hreflang)
7. 国际化(hreflang)
html
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="es" href="https://example.com/es/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />Next.js equivalent: in the Metadata object.
alternates.languageshtml
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="es" href="https://example.com/es/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />Next.js 中的等效配置:在Metadata对象的中设置。
alternates.languages8. Performance Hints
8. 性能提示
Include when external resources are used:
html
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="dns-prefetch" href="https://www.google-analytics.com" />使用外部资源时需添加:
html
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="dns-prefetch" href="https://www.google-analytics.com" />Placeholder Tokens
占位符标记
All boilerplate files use tokens. Common tokens:
{{PLACEHOLDER_NAME}}| Token | Purpose |
|---|---|
| Page |
| Meta description |
| Page URL (absolute) |
| Canonical URL |
| Comma-separated keywords |
| Content author |
| Brand / site name |
| Hex color codes |
| Open Graph |
| |
| Twitter handles |
| JSON-LD |
| Publisher org |
| Icons |
| Author website URL (Next.js) |
| Content creator name (Next.js) |
| Site category (Next.js) |
| Search engine verification codes (Next.js) |
| Language-specific alternate URLs (Next.js) |
| hreflang alternate URLs (HTML/Vite) |
When implementing for a user, replace every token. Never leave placeholders in production output.
{{...}}所有模板文件均使用占位符标记。常见标记:
{{PLACEHOLDER_NAME}}| 标记 | 用途 |
|---|---|
| 页面 |
| Meta描述 |
| 页面URL(绝对路径) |
| 规范URL |
| 逗号分隔的关键词 |
| 内容作者 |
| 品牌/站点名称 |
| 十六进制颜色代码 |
| Open Graph相关参数 |
| Twitter相关参数 |
| Twitter账号 |
| JSON-LD相关参数 |
| 发布机构信息 |
| 图标地址 |
| 作者网站URL(Next.js) |
| 内容创作者名称(Next.js) |
| 站点分类(Next.js) |
| 搜索引擎验证代码(Next.js) |
| 多语言替代URL(Next.js) |
| hreflang替代URL(HTML/Vite) |
为用户实现时,需替换所有标记。生产环境中绝不能保留占位符。
{{...}}Quality Gate
质量检查项
Run these checks before considering any metadata task complete:
- No placeholders — grep for in all modified files; count must be zero.
{{ - Absolute URLs — canonical, OG url, OG image, Twitter image, JSON-LD url/image must start with .
https:// - Image alt text — every /
og:imagemust have a corresponding alt field.twitter:image - No duplicate tags — no two conflicting ,
<title>, ordescriptiontags in the same scope.canonical - Title length — verify under 60 characters.
- Description length — verify 150-160 characters.
- JSON-LD validity — valid JSON with required and
@contextkeys.@type - OG/Twitter parity — if OG title is set, Twitter title should also be set (and vice versa).
- Canonical consistency — canonical URL matches the actual page URL or intended redirect target.
- Theme color — includes both light and dark media variants.
- hreflang — includes when language alternates exist.
x-default - Robots — allows indexing unless user explicitly requests noindex.
在完成任何元数据任务前,执行以下检查:
- 无占位符 — 在所有修改的文件中搜索,结果数量必须为零。
{{ - 绝对URL — 规范链接、Open Graph URL、Open Graph图片、Twitter图片、JSON-LD URL/图片必须以开头。
https:// - 图片替代文本 — 每个/
og:image必须对应一个替代文本字段。twitter:image - 无重复标签 — 同一作用域内(布局 vs 页面)不能存在冲突的、
<title>或description标签。canonical - 标题长度 — 验证长度不超过60个字符。
- 描述长度 — 验证长度为150-160个字符。
- JSON-LD有效性 — 包含必填的和
@context字段的有效JSON。@type - Open Graph/Twitter一致性 — 若设置了Open Graph标题,也需设置Twitter标题(反之亦然)。
- 规范链接一致性 — 规范URL与实际页面URL或预期重定向目标一致。
- 主题色 — 包含浅色和深色模式的媒体查询变体。
- hreflang — 存在多语言替代链接时需包含。
x-default - Robots设置 — 允许索引,除非用户明确要求禁止索引。
Image Specifications
图片规格
| Use case | Dimensions | Ratio | Format | Max size |
|---|---|---|---|---|
| OG / Twitter | 1200x630 | 1.91:1 | JPG or PNG | 1 MB |
| Favicon 32 | 32x32 | 1:1 | PNG | n/a |
| Favicon 16 | 16x16 | 1:1 | PNG | n/a |
| Apple Touch | 180x180 | 1:1 | PNG | n/a |
| 使用场景 | 尺寸 | 比例 | 格式 | 最大尺寸 |
|---|---|---|---|---|
| Open Graph / Twitter | 1200x630 | 1.91:1 | JPG或PNG | 1 MB |
| 32x32图标 | 32x32 | 1:1 | PNG | 无要求 |
| 16x16图标 | 16x16 | 1:1 | PNG | 无要求 |
| Apple触摸图标 | 180x180 | 1:1 | PNG | 无要求 |
Testing Tools
测试工具
Recommend to users after deployment:
Common Mistakes
常见错误
| Mistake | Impact | Fix |
|---|---|---|
Relative URLs in | Social platforms can't fetch the image | Always use absolute URLs starting with |
Missing | All | Wrap app root in |
Missing | | Call |
| Committing verification codes to public repos | Exposes site ownership tokens | Use environment variables for |
Duplicate | Crawlers pick an unpredictable one | Use only one source of truth per scope (layout vs. page) |
| Accessibility failure, some validators warn | Always pair image with alt text |
Using | Unnecessary async overhead on every request | Use static |
Leaving | Broken display on social platforms, poor SEO | Grep for |
| JSON-LD with trailing commas or comments | Invalid JSON, structured data ignored | Validate JSON before finishing |
| Image gets cropped to tiny square | Use |
| 错误 | 影响 | 修复方案 |
|---|---|---|
| 社交平台无法获取图片 | 始终使用以 |
Vite React中缺少 | 所有 | 在 |
Vite Vue中缺少 | | 在 |
| 将验证代码提交到公共仓库 | 暴露站点所有权令牌 | 使用环境变量存储 |
重复的 | 爬虫会随机选择其中一个 | 每个作用域(布局 vs 页面)仅保留一个可信数据源 |
设置 | 可访问性不达标,部分验证工具会发出警告 | 始终为图片添加替代文本 |
静态页面使用 | 每次请求都会产生不必要的异步开销 | 若构建时已知值,使用静态 |
遗留 | 社交平台显示异常,SEO效果差 | 上线前搜索 |
| JSON-LD中存在尾随逗号或注释 | JSON无效,结构化数据被忽略 | 完成前验证JSON格式 |
图片尺寸为1200x630时 | 图片被裁剪为小方形 | 横向图片使用 |
Migration Paths
迁移路径
| From | To | Notes |
|---|---|---|
| Vite React ( | Replace with |
| Vite Vue ( | Replace |
| Next.js ( | Remove |
Pages Router | App Router | Replace |
| 源框架/库 | 目标框架/库 | 说明 |
|---|---|---|
| Vite React( | 替换为 |
| Vite Vue( | 用 |
| Next.js( | 移除 |
Pages Router | App Router | 替换 |