Create an llms.txt File with the Hugo Static Site Generator
The llms.txt file is a proposal to make websites more LLM-friendly by providing a simple Markdown file that highlights important, LLM-readable information and points to Markdown versions of key pages.
The following steps show one way to create and render an llms.txt file with Hugo, ensuring it’s included automatically in your site’s output.
Requirements
- Hugo website project
Steps
Add a new media type and output format in your hugo.toml:
[mediaTypes] [mediaTypes.'text/plain'] suffixes = ['txt'] [outputFormats] [outputFormats.llms] mediaType = 'text/plain' isPlainText = true baseName = "llms" root = true
Create a template for your new defined output format (txt) to render the llms.txt file: layouts/_default/single.txt
{{ .RawContent | safeHTML }} ## Pages {{ "\n" }} {{- range .Site.Pages -}} {{- $p := . -}} {{- with .OutputFormats.Get "markdown" -}} - [{{ $p.Title }}]({{ .Permalink }}){{ "\n" }} {{- end -}} {{- end -}}
This renders the Markdown content from content/llms.md first, followed by a list of your pages (all pages with the markdown output format will be included).
Create a template to render pages in the markdown output format (if not already existing): layouts/_default/single.md
# {{ .Title }} {{ .RawContent | safeHTML }}
This simply renders the plain Markdown content of your page, adding the title as a heading.
Create a content/llms.md file:
+++ outputs = ['llms'] +++ # Title > Optional description goes here Optional details go here
See the llms.txt Format for more details.
Add the markdown output format to all pages that should be included in llms.txt:
+++ title = "Page title" outputs = ["html", "markdown"] +++
After these steps, Hugo will generate the file at public/llms.txt.