站点 Robots

Antora 可以生成 robots.txt 文件来控制网站爬虫可以访问的路径。

robots键

robots 的键是可选的。它在剧本的 site 键下配置。它的可接收值是:

allow

允许所有用户代理访问发布站点中的所有路径。

disallow

禁止所有用户代理访问已发布站点中的所有路径。

custom multi-line string

非空的用户指定字符串,用作生成的 robots.txt 文件的内容。

Example 1. Example 1. antora-playbook.yml
site:
  title: Site Title
  url: https://example.org
  robots: disallow
YAML

Antora 将在站点的根目录下生成 robots.txt 文件。

robots 键取决于同级的 url 键。如果 url 键没有被分配一个值,即使 robots 设置为可接受的值,Antora 也不会生成一个 robots.txt 文件。

指定允许或不允许 robots

假设 urlrobots 键定义如下:

Example 2. Example 2. antora-playbook.yml
site:
  title: Demo Docs Site
  url: https://demo.antora.org
  robots: allow
YAML

这将生成一个 robots.txt 文件,该文件允许用户代理访问站点的所有路径。

Example 3. Generated robots.txt
User-agent: *
Allow: /
YAML

类似地,如果 urlrobots 键定义如下:

Example 4. Example 3. antora-playbook.yml
site:
  title: Demo Docs Site
  url: https://demo.antora.org
  robots: disallow
YAML

这将生成一个 robots.txt 文件,该文件禁止访问所有路径。

Example 5. Generated robots.txt
User-agent: *
Disallow: /
YAML

使用自定义内容生成 robots.txt

如果分配了任何其他非空值给 robots ,该值将被用作 robots.txt 文件的内容。例如,假设 robots 键声明如下:

Example 6. Example 4. antora-playbook.yml
site:
  title: Demo Docs Site
  url: https://demo.antora.org
  robots: |
    User-agent: *
    Disallow: /private/
YAML

这将生成以下 robots.txt 文件。

Example 7. Generated robots.txt
User-agent: *
Disallow: /private/
YAML