Hugo 向け llms.txt

二つの方法があります。static/ に静的ファイルを置く方法(設定不要でどこでも動作)と、ビルド時にコンテンツから llms.txt を自動生成するカスタム出力形式を使う方法です。

最終更新:

オプション 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 (不要な <link rel="alternate"> HTML にあるタグ)。

テンプレートの記述

次の場所にテンプレートを作成します: 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.
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 ガイド]を参照してください。 Cloudflare Pages ガイド キャッシュヘッダーに関する推奨事項について。
  • Vercel, Hugoは自動的に検出されます。ビルドコマンドを次のように設定してください: hugo および出力ディレクトリを public。次を参照してください Vercelガイド のエッジキャッシュオプションについて確認してください。
  • GitHub Pagesでは、 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 を バリデーター 完全な仕様準拠チェック用に

関連ガイド

ソース