Hugo 向け llms.txt
二つの方法があります。static/ に静的ファイルを置く方法(設定不要でどこでも動作)と、ビルド時にコンテンツから llms.txt を自動生成するカスタム出力形式を使う方法です。
最終更新:
オプション 1:静的ファイル(推奨)
Hugoは static/ ディレクトリを直接 public/ ビルド出力へコピーします。 llms.txt
に配置すれば、どのホスティングプラットフォームでも /llms.txt どのホスティングプラットフォームでも、Hugoの設定変更は
不要です。
# 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, 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, 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 (不要な <link rel="alternate"> HTML にあるタグ)。
テンプレートの記述
次の場所にテンプレートを作成します: layouts/index.llmstxt.txt。Hugoは ホーム テンプレートをルートレベルの出力に使用します。通常のページをすべて列挙する簡単な例を示します:
{{/* 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, 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.
---
# 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 ガイド]を参照してください。 Cloudflare Pages ガイド キャッシュヘッダーに関する推奨事項について。 - Vercel,
Hugoは自動的に検出されます。ビルドコマンドを次のように設定してください:
hugoおよび出力ディレクトリをpublic。次を参照してください Vercelガイド のエッジキャッシュオプションについて確認してください。 - GitHub Pagesでは、
hugoをデプロイします:public/をgh-pagesブランチ。ファイルは次で配信されます:https://your-org.github.io/llms.txt. - 任意の静的ホスト, 展開する
public/ディレクトリ。ファイルは ルートに配置され、正しく配信されます。
検証
まずローカルで確認します。
hugo
ls public/llms.txt # should exist
cat public/llms.txt # check content
https_proxy="" hugo server
curl http://localhost:1313/llms.txt デプロイ後:
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8 次に URL を バリデーター 完全な仕様準拠チェック用に
関連ガイド
- llms.txtの作成方法、テンプレート、チェックリスト、およびすべてのスタック。
- Cloudflare Pages ガイド, CF Pages に Hugo をデプロイします。
- SvelteKit ガイド、別のSSGアプローチ。
- Astroガイド、コンテンツ収集エンドポイント。
- ベストプラクティス、何を含め、何を除外するか。
- バリデータ · ジェネレーター.