llms.txt لـ Eleventy (11ty)

يجعل نظام قوالب Eleventy llms.txt مباشراً: استخدم ملف نص عادي مع مفتاح permalink في المقدمة، أو كرّر المجموعات لإنشاء الروابط تلقائياً من محتواك.

آخر تحديث:

الخيار 1: قالب نص عادي

أنشئ ملفاً في src/llms.txt (أو في أي مكان داخل دليل الإدخال لديك). أضف permalink مفتاح في YAML frontmatter للتحكم في مسار الإخراج. وسيعالج Eleventy الملف ويكتبه إلى _site/llms.txt.

src/llms.txt
---
permalink: /llms.txt
eleventyExcludeFromCollections: true
---
# Your Site

> One-sentence description of what your site or product does.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure in minutes.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog with examples.

## Product

- [Overview](https://yoursite.com/product): Core features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing details.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
eleventy.config.js, enable txt templates
// eleventy.config.js
module.exports = function (eleventyConfig) {
  // Add passthrough copy for any assets you want served verbatim
  // llms.txt is handled via permalink in the template, no passthrough needed

  // Optional: add a collection for docs
  eleventyConfig.addCollection('docs', function (collectionApi) {
    return collectionApi.getFilteredByGlob('src/docs/**/*.md');
  });

  // Ensure .txt files are processed as templates
  return {
    templateFormats: ['md', 'njk', 'html', 'txt'],
    dir: {
      input: 'src',
      output: '_site',
    },
  };
};

الخيار 2: التوليد من المجموعات

إذا كانت وثائقك تدار كمجموعات Eleventy (ملفات Markdown مع frontmatter)، يمكنك التكرار على المجموعة داخل القالب وتوليد قائمة الروابط تلقائياً. استخدم ---js صياغة البيانات الأمامية للإعداد المستند إلى JavaScript، أو صياغة قوالب Nunjucks/Liquid لمحتوى الصفحة.

src/llms.txt, from collections
---js
{
  permalink: "/llms.txt",
  eleventyExcludeFromCollections: true
}
---
# Your Site

> {{ site.description }}

## Documentation

{% for doc in collections.docs | sort(attribute='data.order') -%}
- [{{ doc.data.title }}]({{ site.url }}{{ doc.url }}): {{ doc.data.description }}
{% endfor %}

الـ site.url ينبغي ضبط متغير البيانات العام في _data/site.js أو _data/site.json الملف. احرص على استخدام عناوين URL مطلقة لكل الروابط، إذ لن تُحل المسارات النسبية بصورة صحيحة عند جلبها بواسطة زواحف الذكاء الاصطناعي.

خيارات frontmatter الأساسية لـ llms.txt قالب:

  • permalink: /llms.txt، أخرج الملف في جذر موقعك.
  • eleventyExcludeFromCollections: true, ويمنع ظهور الملف في مجموعات موقعك (التنقل والموجزات وخرائط الموقع).
  • layout: false, ويضمن عدم تطبيق غلاف تخطيط (ليس ضرورياً لأن .txt فالملفات لا تستخدم تخطيطات HTML افتراضياً).

تحقّق

شغّل بناء Eleventy وتحقق من المخرجات:

Build and verify
# Build
npx @11ty/eleventy

# Check that the file was generated
cat _site/llms.txt | head -5

# After deploying, verify the live URL
curl -I https://yoursite.com/llms.txt
# Expected: content-type: text/plain; charset=utf-8

أدلة ذات صلة

المصادر