<!-- Generated from zh/llms-txt-hugo/index.html. The canonical document is the HTML page. -->

- [ 首页 ](/zh/) 
/
- [ 如何创建 ](/zh/how-to-create/) 
/
- Hugo 指南            
# Hugo 的 `llms.txt`

两种做法：在 static/ 中放静态文件（零配置，处处可用），或者使用自定义输出格式，在构建时从你的内容自动生成 llms.txt。

最近更新: 2026年4月22日

本页内容

- [ 选项 1：静态文件（推荐） ](#static)
- [ 选项 2：自定义输出格式 ](#output-format)
- [ 编写模板 ](#template)
- [ 部署 ](#deployment)
- [ 验证 ](#verify)              
备注

应使用哪种方案？

如果你的  llms.txt  内容是稳定的，并且你会手动更新它，请使用
静态文件 ，无需配置，风险为零。如果你希望它在每次内容更新时自动保持同步  hugo  构建时，请使用
自定义输出格式 .

## 选项 1：静态文件（推荐）

Hugo 会复制 `static/` 目录直接复制到 `public/` 构建输出。请将你的 `llms.txt`
将其放在那里后，文件会在以下地址提供： `/llms.txt` 在任何托管平台上提供，无需更改 Hugo
配置。
static/llms.txt, directory structure    复制     

```
# Hugo, zero-config static approach
#
# Place your file at: static/llms.txt
# Hugo copies everything in static/ directly to the public/ output directory.
# Your file will be served at /llms.txt on any host.
#
# Project structure:
# your-hugo-site/
# ├── static/
# │   └── llms.txt   ← add this
# ├── content/
# ├── layouts/
# └── hugo.toml
#
# No config changes needed. Run "hugo" and it appears in public/llms.txt.

```

运行 `hugo`，您会找到 `public/llms.txt`
位于构建输出中。部署 `public/` 到 Cloudflare Pages、Vercel、GitHub Pages 或任何 静态主机。

## 方案 2：自定义输出格式

Hugo 的输出格式系统允许你使用 Go 模板根据内容生成任意文件类型。定义一个新的 `LLMSTXT` 格式，然后创建模板，Hugo
会构建 `public/llms.txt`
自动在每个 `hugo` 运行时。

### 第 1 步，将输出格式添加到你的配置中
hugo.toml    复制     

```
# hugo.toml, define the llmstxt custom output format

[outputs]
home = ["HTML", "RSS", "LLMSTXT"]

[outputFormats.LLMSTXT]
mediaType = "text/plain"
baseName = "llms"
isPlainText = true
notAlternative = true

```

使用 YAML？配置相同：
hugo.yaml    复制     

```
# hugo.yaml, same config in YAML

outputs:
home:
- HTML
- RSS
- LLMSTXT

outputFormats:
LLMSTXT:
mediaType: text/plain
baseName: llms
isPlainText: true
notAlternative: true

```

关键设置是 `mediaType = "text/plain"` （使 Hugo 写入纯文本文件）， `baseName = "llms"` （生成
`llms.txt`），以及 `notAlternative = true` （抑制一个不需要的 ` ` 标签）。

## 编写模板

在以下位置创建模板： `layouts/index.llmstxt.txt`。Hugo 使用 *主页* 模板 作为根级输出。这里有一个列出所有常规页面的简洁版本：
layouts/index.llmstxt.txt, simple    复制     

```
{{/* layouts/index.llmstxt.txt */}}
{{/* Hugo home template for the llmstxt output format */}}
# {{ .Site.Title }}

> {{ .Site.Params.description }}

{{ with .Site.Params.llmstxtContext }}{{ . }}

{{ end -}}
## Pages

{{ range .Site.RegularPages -}}
- [{{ .Title }}]({{ .Permalink }}): {{ with .Description }}{{ . }}{{ else }}{{ .Summary | plainify | truncate 120 }}{{ end }}
{{ end }}

```

对于包含多个内容版块（博客、文档、教程）的站点，请按版块组织：
layouts/index.llmstxt.txt, by section    复制     

```
{{/* layouts/index.llmstxt.txt, organized by section */}}
# {{ .Site.Title }}

> {{ .Site.Params.description }}

{{ range .Site.Sections -}}
## {{ .Title }}

{{ range .Pages -}}
- [{{ .Title }}]({{ .Permalink }}): {{ with .Description }}{{ . }}{{ else }}{{ .Summary | plainify | truncate 100 }}{{ end }}
{{ end }}
{{ end -}}

## Optional

- [Homepage]({{ .Site.BaseURL }}): site entry point.

```

示例

使用 description frontmatter

Hugo 的  .Summary  是从每个页面的第一段自动提取的，往往过长或过于笼统，不适合作为优质 llms.txt
条目。请添加一个  description  字段添加到前置元数据中， 以提供精确的手工摘要：
content/docs/getting-started.md    复制     

```
---
# content/docs/getting-started.md
title: "Getting started"
description: "Install the CLI, run your first command, and deploy in under 5 minutes."
draft: false
---

Your content here...

```

## 部署

- **Cloudflare Pages**，将构建命令设置为 `hugo`
并将发布目录设置为 `public`。Cloudflare Pages 将会提供
`public/llms.txt` 在 `/llms.txt` 通过其全球 CDN 提供。请参阅 [Cloudflare Pages 指南](/zh/llms-txt-cloudflare/) 用于缓存头建议。 
- **Vercel**，系统会自动检测 Hugo。将构建命令设置为 `hugo` 并将输出目录设为
`public`。请参阅
[Vercel 指南](/zh/llms-txt-vercel/) 的边缘缓存选项。 
- **GitHub Pages**，使用运行以下命令的 GitHub Actions 工作流：
`hugo` 并部署 `public/` 到
`gh-pages` 分支。该文件将提供于
`https://your-org.github.io/llms.txt`. 
- **任何静态主机**，部署 `public/` 目录。文件将位于根目录，并得到正确提供。   
## 验证

先在本地检查：
Local verification    复制     

```
hugo
ls public/llms.txt          # should exist
cat public/llms.txt          # check content
https_proxy="" hugo server
curl http://localhost:1313/llms.txt
```

部署后：
Production verification    复制     

```
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8
```

然后将 URL 粘贴到 [验证器](/zh/validator/) 以进行完整的规范合规性检查。

## 相关指南

- [如何创建 llms.txt](/zh/how-to-create/)，包括模板、检查清单和所有技术栈。 
- [Cloudflare Pages 指南](/zh/llms-txt-cloudflare/)，在 CF Pages 上部署 Hugo。 
- [SvelteKit 指南](/zh/llms-txt-sveltekit/)，另一种 SSG 方法。 
- [Astro 指南](/zh/llms-txt-astro/)，内容集合端点。 
- [最佳实践](/zh/best-practices/)、应包含什么，以及应排除什么。 
- [验证器](/zh/validator/) · [生成器](/zh/generator/).        
## 来源

- [ llmstxt.org，社区提案 ](https://llmstxt.org/)
- [ Hugo 文档，自定义输出格式 ](https://gohugo.io/configuration/output-formats/)
- [ Hugo 文档，模板查找顺序 ](https://gohugo.io/templates/lookup-order/)
