Mintlify 会自动处理许多 SEO 最佳实践,包括:
  • 自动生成 meta 标签
  • 生成站点地图(Sitemap)和 robots.txt 文件
  • 语义化 HTML 结构
  • 移动端优化
你可以在 docs.json 或页面的 frontmatter 中添加 metatags 字段,以完整自定义站点的 meta 标签。

全局元标签

你可以在 docs.json 中添加 metadata 字段来设置默认元标签。
"seo": {
    "metatags": {
        "og:image": "link to your default meta tag image"
    }
}

针对页面的 meta 标签

像下面这样将你的 meta 标签添加到页面的元数据中:
---
title: 'Your Example Page Title'
'og:image': 'link to your meta tag image'
---
在页面元数据中,带有冒号的 meta 标签需要用引号包起来。

常用 Meta 标签参考

下面是可添加到你的 docs.json 中的 Meta 标签完整列表。这些标签有助于提升站点的 SEO、社交分享效果和浏览器兼容性。 你可以使用 metatags.io 预览这些 Meta 标签在不同平台上的展示效果。
"seo": {
    "metatags": {
      "robots": "noindex",
      "charset": "UTF-8",
      "viewport": "width=device-width, initial-scale=1.0",
      "description": "页面描述",
      "keywords": "关键词1, 关键词2, 关键词3",
      "author": "作者姓名",
      "robots": "index, follow",
      "googlebot": "index, follow",
      "google": "notranslate",
      "google-site-verification": "verification_token",
      "generator": "Mintlify",
      "theme-color": "#000000",
      "color-scheme": "light dark",
      "canonical": "https://your-custom-domain-here.com",
      "format-detection": "telephone=no",
      "referrer": "origin",
      "refresh": "30",
      "rating": "general",
      "revisit-after": "7 days",
      "language": "en",
      "copyright": "Copyright 2024",
      "reply-to": "email@example.com",
      "distribution": "global",
      "coverage": "Worldwide",
      "category": "Technology",
      "target": "all",
      "HandheldFriendly": "True",
      "MobileOptimized": "320",
      "apple-mobile-web-app-capable": "yes",
      "apple-mobile-web-app-status-bar-style": "black",
      "apple-mobile-web-app-title": "应用标题",
      "application-name": "应用名称",
      "msapplication-TileColor": "#000000",
      "msapplication-TileImage": "path/to/tile.png",
      "msapplication-config": "path/to/browserconfig.xml",
      "og:title": "Open Graph 标题",
      "og:type": "website",
      "og:url": "https://example.com",
      "og:image": "https://example.com/image.jpg",
      "og:description": "Open Graph 描述",
      "og:site_name": "站点名称",
      "og:locale": "en_US",
      "og:video": "https://example.com/video.mp4",
      "og:audio": "https://example.com/audio.mp3",
      "twitter:card": "summary",
      "twitter:site": "@username",
      "twitter:creator": "@username",
      "twitter:title": "Twitter 标题",
      "twitter:description": "Twitter 描述",
      "twitter:image": "https://example.com/image.jpg",
      "twitter:image:alt": "图片说明",
      "twitter:player": "https://example.com/player",
      "twitter:player:width": "480",
      "twitter:player:height": "480",
      "twitter:app:name:iphone": "应用名称",
      "twitter:app:id:iphone": "12345",
      "twitter:app:url:iphone": "app://",
      "article:published_time": "2024-01-01T00:00:00+00:00",
      "article:modified_time": "2024-01-02T00:00:00+00:00",
      "article:expiration_time": "2024-12-31T00:00:00+00:00",
      "article:author": "作者姓名",
      "article:section": "技术",
      "article:tag": "标签1, 标签2, 标签3",
      "book:author": "作者姓名",
      "book:isbn": "1234567890",
      "book:release_date": "2024-01-01",
      "book:tag": "标签1, 标签2, 标签3",
      "profile:first_name": "John",
      "profile:last_name": "Doe",
      "profile:username": "johndoe",
      "profile:gender": "male",
      "music:duration": "205",
      "music:album": "专辑名称",
      "music:album:disc": "1",
      "music:album:track": "1",
      "music:musician": "艺人姓名",
      "music:song": "歌曲名称",
      "music:song:disc": "1",
      "music:song:track": "1",
      "video:actor": "演员姓名",
      "video:actor:role": "角色名称",
      "video:director": "导演姓名",
      "video:writer": "编剧姓名",
      "video:duration": "120",
      "video:release_date": "2024-01-01",
      "video:tag": "标签1, 标签2, 标签3",
      "video:series": "系列名称"
  }
}

站点地图与 robots.txt 文件

Mintlify 会自动生成 sitemap.xmlrobots.txt 文件。你可以在文档站点的 URL 后加上 /sitemap.xml 来查看站点地图。 默认情况下,只会收录 docs.json 中包含的页面。若要包含隐藏链接,请在 docs.json 中添加 seo.indexing
"seo": {
    "indexing": all
}

自定义 sitemap 和 robots.txt 文件

要添加自定义的 sitemap.xmlrobots.txt 文件,请在项目根目录创建相应的 sitemap.xmlrobots.txt 文件。添加自定义文件会覆盖同名的自动生成文件。删除自定义文件后,将恢复使用默认文件。

关闭索引

如果你想阻止某个页面被搜索引擎收录,可以在页面的frontmatter中加入以下内容:
---
noindex: true
---
你也可以在 docs.json 中将 metadata.robots 字段设置为 "noindex",从而为文档中的所有页面指定 noindex
"seo": {
    "metatags": {
      "robots": "noindex"
    }
  }

SEO 最佳实践