llms.txt لـ Nuxt.js
ثلاثة نهوج لـ Nuxt.js: ملف ثابت في public/ (بلا إعداد)، أو مسار خادم Nitro للتوليد الديناميكي، أو توليد تلقائي من وثائق Nuxt Content.
آخر تحديث:
الخيار 1: ملف ثابت في public/
ينسخ Nuxt كل شيء إلى public/ الدليل مباشرةً إلى مخرجات البناء، حيث يُقدَّم في جذر موقعك.
ضع ملفك في public/llms.txt وسيكون متاحاً في /llms.txt عند كل هدف نشر.
# Nuxt static file approach
#
# Place your file at: public/llms.txt
# Nuxt copies everything in public/ directly to the build output.
#
# Project structure:
# your-nuxt-app/
# ├── public/
# │ └── llms.txt ← add this
# ├── pages/
# └── nuxt.config.ts
#
# No configuration needed. Works with all deployment presets.
لا يتطلب هذا النهج أي إعداد ويعمل بالطريقة نفسها عبر جميع إعدادات Nitro المسبقة: node-server, cloudflare-pages, vercel, netlify، و ثابت.
الخيار 2: مسار API على الخادم
أنشئ ملفاً في server/routes/llms.txt.ts. ويعيّن محرك Nitro في Nuxt الملفات في server/routes/ مباشرةً إلى مسارات URL، ولذلك يُقدَّم هذا الملف بالضبط في /llms.txt من دون إعداد توجيه
إضافي.
// server/routes/llms.txt.ts
// Nuxt server route, served at /llms.txt
export default defineEventHandler(() => {
const content = `# 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.
`;
setResponseHeader(event, 'Content-Type', 'text/plain; charset=utf-8');
setResponseHeader(event, 'Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');
return content;
});
استخدم setResponseHeader من h3 مكتبة (مضمّنة مع Nuxt) لضبط Content-Type. أضف Cache-Control الرأس حتى تخزّن حواف CDN الاستجابة مؤقتاً وتخفف الحمل عن المصدر.
الخيار 3: التوليد التلقائي عبر Nuxt Content
إذا كنت تستخدم Nuxt Content للتوثيق، يمكنك الاستعلام عن مجموعة
المحتوى لديك وإنشاء قائمة الروابط تلقائياً. وهذا يضمن llms.txt يبقى متزامناً مع توثيقك
من دون تحديثات يدوية.
// server/routes/llms.txt.ts
// Auto-generate llms.txt from Nuxt Content documents
import { serverQueryContent } from '#content/server';
export default defineEventHandler(async (event) => {
// Query all docs; adjust collection name as needed
const docs = await serverQueryContent(event, '/docs')
.only(['title', 'description', '_path'])
.find();
const links = docs
.map((doc) => `- [${doc.title}](https://yoursite.com${doc._path}/): ${doc.description ?? ''}`)
.join('\n');
const body = [
'# Your Site',
'',
'> One-sentence description of your project.',
'',
'## Documentation',
'',
links,
].join('\n');
setResponseHeader(event, 'Content-Type', 'text/plain; charset=utf-8');
return body;
});
اضبط مسار الاستعلام (/docs) وأسماء الحقول لتطابق بنية محتواك. شغّل المدقّق بعد النشر لاكتشاف أي تراجعات في التنسيق.
Nitro وأهداف النشر
- node-server، تعمل مسارات الخادم كمعالج HTTP في Node.js. أضف قاعدة تخزين مؤقت
في الوكيل العكسي (nginx/Caddy) من أجل
/llms.txtلتجنب تشغيل Node عند كل طلب. - cloudflare-pages, الملفات الثابتة في
public/تُقدَّم عبر شبكة CDN العالمية التابعة لـ Cloudflare. وتصبح مسارات الخادم Pages Functions. راجع دليل Cloudflare لترويسات التخزين المؤقت. - vercel, وتخزّن الملفات الثابتة مؤقتاً عند الحافة تلقائياً. وتصبح مسارات الخادم وظائف Vercel Serverless أو Edge وفق الإعداد.
- ثابت (معروض مسبقاً بالكامل)، فاستخدم
public/نهج الملف الثابت؛ فمسارات الخادم غير متاحة في إخراج ثابت بحت.
تحقّق
بعد النشر، تأكد من تقديم الملف بصورة صحيحة:
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8
curl https://yoursite.com/llms.txt | head -5
# Should print the first lines of your file أدلة ذات صلة
- كيفية إنشاء llms.txt, والقوالب وقائمة الفحص.
- مرجع تنسيق llms.txt, تفاصيل المواصفة.
- دليل Vercel, والنشر ورؤوس التخزين المؤقت.
- دليل Cloudflare Pages, وإعداد CDN.
- المدقّق · المولّد.