Adding an llms.txt file to Hugo
Today, I set out to add an llms.txt to this site.
I’ve made a few similar additions in the past with raw post markdown files and a search index.
Every time I try and change something with outputFormats
in Hugo, I forget one of the steps, so in writing this up, finally I’ll have it for next time.
Steps
First, I added a new output format in my config.toml
file:
[outputFormats.TXT]mediaType = "text/plain"baseName = "llms"isPlainText = true
Then, I added this format to my home outputs:
[outputs]home = ["HTML", "RSS", "JSON", "SearchIndex", "TXT"]
Finally, I created a template file at layouts/_default/index.txt
that renders my site content in a structured markdown per the spec recommendations.
# {{ .Site.Title }}
> {{ .Site.Params.description }}
## Content{{ range $type := .Site.Params.front_page_content }}### {{ title $type }}
{{ range (where $.Site.RegularPages "Type" $type) }}- [{{ .Title }}]({{ .Permalink }}index.md): Published {{ .Date.Format "2006-01-02" }}{{ end }}{{ end }}
Now, when I build my site, it generates an llms.txt
file at the root that contains a Markdown list of the content on this site.
This makes it easy for language models to understand my site without dealing with HTML markup.
Recommended
Raw Markdown Pages
I added some configuration to this Hugo site allow access to the raw Markdown versions of posts. This enables you to hit URLs such as this to get the...
Hugo Social Image Previews
I've started posting more on Bluesky and I noticed that articles from my site didn't have social image previews 😔
Hugo Page Bundles
Hugo allows you to store your images with your content using a feature called page bundles. I was loosely familiar with the feature, but Claude...