Ruby on Railsでのllms.txt
Rails はサイトのルートで public/ フォルダーを提供します。そこに llms.txt を追加するか、コンテンツが動的な場合はコントローラーから生成します。
最終更新:
2つのアプローチ
Railsでは llms.txt を2つの方法で配信できます: public/ (最も簡単な方法)、
またはデータからファイルを生成するコントローラーアクションです。コンテンツを最新のレコードに反映する必要がない限り、静的ファイルを使用してください。
方法1:public/内の静的ファイル
public/ 内のすべてのファイルはドメインのルートで配信されます。次の場所にあるファイル:
public/llms.txt
次に解決されます: /llms.txt.
- ファイルを作成します:
touch public/llms.txt - コンテンツを書きます( 作成方法ガイド):
# Your App Name
> One-sentence description of your app for LLM context.
## Core pages
- [Home](https://yourdomain.com/): what this app does.
- [Pricing](https://yourdomain.com/pricing/): plans and limits.
- [Docs](https://yourdomain.com/docs/): developer documentation.
方法2:コントローラーアクション
ファイルを動的に生成するには、プレーンテキストをレンダリングするルートとコントローラーを追加します:
# config/routes.rb
get "/llms.txt", to: "llms#show"
# app/controllers/llms_controller.rb
class LlmsController < ApplicationController
def show
pages = Page.published.order(:title) # example data source
body = "# Your App Name\n\n> Description of your app.\n\n## Core pages\n\n"
body += pages.map { |p| "- [#{p.title}](#{page_url(p)}): #{p.summary}" }.join("\n")
render plain: body, content_type: "text/plain"
end
end
本番環境での静的ファイル配信
設定の確認
curl -sI https://yourdomain.com/llms.txt | grep -i content-type
# expect: content-type: text/plain
Laravelを使用している場合は、 Laravelガイド。ページコンテンツをより完全に 書き出すには、 llms-full.txt.