llms.txt لـ SvelteKit
ثلاثة نهوج: ملف ثابت في static/ (بلا إعداد)، أو نقطة نهاية +server.ts للتوليد الديناميكي، أو مولّد يعتمد على المحتوى باستخدام import.meta.glob.
آخر تحديث:
الخيار 1: ملف ثابت (موصى به)
ينسخ SvelteKit كل شيء في static/ الدليل مباشرةً في مخرجات البناء. ضع ملفك في static/llms.txt وسيُقدَّم على العنوان /llms.txt على كل adapter، من دون حاجة إلى تغييرات في الإعداد.
# SvelteKit, zero-config static approach
#
# Place your file at: static/llms.txt
# SvelteKit copies everything in static/ directly into the build output.
# Your file will be served at /llms.txt on any adapter.
#
# Project structure:
# your-sveltekit-app/
# ├── static/
# │ └── llms.txt ← add this
# ├── src/
# └── svelte.config.js
#
# No config changes needed. Deploy as normal.
يعمل هذا النهج مع adapter-static, adapter-cloudflare, adapter-vercel, adapter-node، وكل adapter رسمي آخر. ويُقدَّم الملف بترويسات الملفات الثابتة الافتراضية الخاصة بالمحوّل.
الخيار 2: نقطة نهاية +server.ts
أنشئ مسار خادم في src/routes/llms.txt/+server.ts يصدّر GET المعالج. وسيقدّمه
SvelteKit على المسار /llms.txt.
// src/routes/llms.txt/+server.ts
// SvelteKit server endpoint, dynamic generation
import type { RequestHandler } from './$types';
export const GET: RequestHandler = () => {
const body = `# Your Site
> One-sentence description of what your site is.
## Product
- [Overview](https://yoursite.com/product): core capabilities.
- [Pricing](https://yoursite.com/pricing): plans and limits.
## Documentation
- [Getting started](https://yoursite.com/docs): install, first steps.
- [API reference](https://yoursite.com/api): full endpoint catalog.
## Optional
- [Changelog](https://yoursite.com/changelog): version history.
`;
return new Response(body, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
};
اضبط Cache-Control الرأس حتى تخزّن شبكات CDN الطرفية الاستجابة مؤقتاً؛ فهي نادراً ما
تتغير ولا تحتاج إلى تسليم جديد مع كل طلب.
// src/routes/llms.txt/+server.ts
// Add this line to pre-render the endpoint at build time (adapter-static / SSG)
export const prerender = true;
import type { RequestHandler } from './$types';
export const GET: RequestHandler = () => {
const body = `# Your Site\n\n> Summary.\n\n## Docs\n\n- [Guide](https://yoursite.com/docs)`;
return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};
الخيار 3: الإنشاء من المحتوى
إذا كنت تدير التوثيق أو منشورات المدونة في src/content/، يمكنك إنشاء llms.txt تلقائياً وقت البناء باستخدام
import.meta.glob. يقرأ المثال أدناه كل ملفات Markdown ويبني قائمة الروابط من
frontmatter الخاص بها.
// src/routes/llms.txt/+server.ts
// Generate llms.txt from your Markdown content files
import type { RequestHandler } from './$types';
// Import all Markdown files in src/content/docs/
const docs = import.meta.glob('/src/content/docs/**/*.md', { eager: true }) as Record<
string,
{ metadata?: { title?: string; summary?: string; slug?: string } }
>;
export const prerender = true;
export const GET: RequestHandler = () => {
const lines = Object.values(docs)
.filter((m) => m.metadata?.title && m.metadata?.slug)
.map((m) => `- [${m.metadata!.title}](https://yoursite.com/docs/${m.metadata!.slug}/): ${m.metadata!.summary ?? ''}`);
const body = [
'# Your Site',
'',
'> One-sentence summary.',
'',
'## Documentation',
'',
...lines,
].join('\n');
return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};
اضبط نمط glob وحقول البيانات الوصفية بما يلائم بنية محتوى مشروعك. شغّل المدقّق في CI لالتقاط المخرجات المعطلة بعد عمليات ترحيل المحتوى.
ملاحظات التكييف
- adapter-cloudflare, الملفات الثابتة في
static/تُقدَّم مباشرةً عبر CDN العالمية التابعة لـ Cloudflare مع تخزين مؤقت تلقائي. وتصبح مسارات الخادم Cloudflare Pages Functions. راجع دليل Cloudflare Pages من أجل توصيات ترويسات التخزين المؤقت وأوامر التفريغ. - adapter-vercel, تُقدّم الملفات الثابتة من شبكة Edge لدى Vercel. وتعمل مسارات
الخادم كوظائف Vercel (أو وظائف Edge مع
export const config = { runtime: 'edge' }). راجع دليل Vercel لـvercel.jsonخيارات إعادة الكتابة. - adapter-static, يجب أن تكون كل المسارات قابلة للعرض المسبق. أضف
export const prerender = true;إلى+server.ts، أو استخدم نهج الملف الثابت بدلاً منه. - adapter-node, تعمل مسارات الخادم كخادم HTTP على Node.js. أما
+server.tsنهجاً مثالياً؛ أضف تخزيناً مؤقتاً قوياًCache-Controlترويسات حتى يتمكن بروكسي عكسي (nginx أو Caddy) من تخزين الاستجابة مؤقتاً.
تحقّق
بعد النشر، تأكد من تقديم الملف بصورة صحيحة:
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 ثم الصق عنوان URL في المدقّق لفحص كامل للتوافق مع المواصفة.
أدلة ذات صلة
- كيفية إنشاء llms.txt, والقوالب وقائمة الفحص.
- دليل Cloudflare Pages, وتفاصيل SvelteKit وadapter-cloudflare.
- دليل Vercel، وتفاصيل SvelteKit وadapter-vercel.
- أفضل الممارسات, وما ينبغي تضمينه وما ينبغي تركه.
- المدقّق · المولّد.