---
title: "元数据与 SEO"
description: "标题、描述、Open Graph 图片、站点地图和逐页头部控制。"
---

> Documentation Index
> Fetch the complete documentation index at: https://nimbus-docs.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 元数据与 SEO

Nimbus 自动处理元数据基线，并在需要时提供逐页和站点级别的控制。

<h2 id="titles-and-descriptions">标题和描述</h2>

`title` 和 `description` frontmatter 会填充 `<title>` 和 `<meta name="description">`，并用于搜索摘要和 `llms.txt` 索引。站点级别的回退值来自 Nimbus 配置：

```ts title="astro.config.ts"
nimbus({
  site: "https://docs.example.com",
  title: "Acme",
  description: "Build with Acme.",
});
```

<h2 id="open-graph-images">Open Graph 图片</h2>

设置站点级别的回退卡片和替代文本，然后逐页覆盖：

```ts
nimbus({
  /* … */
  socialImage: "/og.png",
  socialImageAlt: "Acme documentation",
});
```

```yaml
---
title: Pricing
socialImage: /og/pricing.png
---
```

Nimbus 还提供了 OG 图片路由，因此没有显式图片的页面会获得生成的卡片。

图片路径是不包含 Astro 部署基础路径的逻辑路径。对于部署在 `/docs` 的站点，保持 `socialImage: "/og.png"`；Nimbus 会生成 `/docs/og.png`。绝对路径和协议相对的图片 URL 会被保留。

<h2 id="sitemap-and-robots">站点地图和 robots</h2>

设置 `site` 后，站点地图集成和 `/robots.txt` 会自动配置。可通过在集成选项中设置 `sitemap: false` 来禁用站点地图。

<h2 id="per-page-and-site-wide-head">逐页和站点级别头部</h2>

通过 `config.head` 在站点级别向 `<head>` 添加元素，或通过 frontmatter 逐页添加 — 两者会合并：

```yaml
---
title: Analytics-tracked page
head:
  - tag: meta
attrs: { name: "robots", content: "noindex" }
  - tag: link
attrs: { rel: "canonical", href: "https://example.com/canonical" }
---
```

有效的标签：`meta`、`link`、`script`、`style`、`title`、`noscript`、`base`。要在不手动编写标签的情况下将页面排除在爬虫之外，请使用 `noindex: true`。

<h2 id="canonical-urls">规范 URL</h2>

在版本化站点上，Nimbus 会生成 `<link rel="canonical">`，将旧版本指向当前版本，以及兄弟版本之间的 `<link rel="alternate">` — 由 `previousSlug` 驱动。

Source: https://nimbus-docs.cn/ai/metadata-and-seo/index.mdx
