llms.txt في Ruby on Rails

يقدّم Rails مجلد public/ في جذر الموقع. أضف llms.txt إليه أو ولّده من متحكّم إذا كان المحتوى ديناميكياً.

آخر تحديث:

نهجان

يستطيع Rails تقديم llms.txt بطريقتين: ملف ثابت في public/ (الأبسط)، أو إجراء متحكّم يبني الملف من بياناتك. استخدم الملف الثابت ما لم يكن المحتوى يجب أن يعكس السجلات الحية.

الطريقة 1: ملف ثابت في public/

كل ما في public/ يُقدّم في جذر النطاق. والملف الموجود في public/llms.txt يُحل إلى /llms.txt.

  1. أنشئ الملف: touch public/llms.txt
  2. اكتب محتواك (راجع دليل إجرائي):
# 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.

المصادر