llms.txt لـ Remix
نهجان في Remix: ملف ثابت في public/ لا يحتاج إلى إعداد، أو مسار مورد في app/routes/llms[.]txt.ts يعيد Response بنص عادي، ويمكن توليده من محتواك اختياريًا.
آخر تحديث:
الخيار 1: ملف ثابت في public/
يقدّم Remix كل شيء في public/ الدليل بصورة ثابتة في جذر موقعك. ضع ملفك في public/llms.txt، من دون حاجة إلى إعداد توجيه.
# Remix static file approach
#
# Place your file at: public/llms.txt
# Remix (and the underlying Node/Cloudflare/Vercel adapter)
# serves everything in public/ at the root of your site.
#
# Project structure:
# your-remix-app/
# ├── public/
# │ └── llms.txt ← add this
# ├── app/
# └── remix.config.js (or vite.config.ts)
يعمل هذا النهج مع جميع adapters في Remix: @remix-run/node, @remix-run/cloudflare, @remix-run/vercel, و @remix-run/netlify. ويتقدم الملف الثابت على أي مسار مطابق.
الخيار 2: مسار مورد
أنشئ مسار مورد في app/routes/llms[.]txt.ts. الـ [.] تفلت صيغة النقطة في اسم الملف حتى يربط Remix المسار بالـURL /llms.txt. صدّر loader وظيفة تعيد Response بالتنسيق الصحيح Content-Type.
// app/routes/llms[.]txt.ts
// Remix resource route, the [.] escapes the dot in the filename
// This file is served at exactly /llms.txt
import type { LoaderFunctionArgs } from '@remix-run/node';
export async function loader({ request }: LoaderFunctionArgs) {
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.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog.
## Product
- [Overview](https://yoursite.com/product): Features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing.
## Optional
- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
`;
return new Response(content, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}
بالنسبة إلى الإنشاء الديناميكي من طبقة المحتوى لديك، اجلب التوثيق في المحمّل وأنشئ قائمة روابط Markdown برمجياً:
// app/routes/llms[.]txt.ts
// Generate from your content / MDX files
import type { LoaderFunctionArgs } from '@remix-run/node';
import { getAllDocs } from '~/models/docs.server';
export async function loader({ request }: LoaderFunctionArgs) {
// Fetch your documentation index from a DB or file system
const docs = await getAllDocs();
const links = docs
.map((doc) => `- [${doc.title}](https://yoursite.com/docs/${doc.slug}/): ${doc.summary}`)
.join('\n');
const body = [
'# Your Site',
'',
'> One-sentence summary of your project.',
'',
'## Documentation',
'',
links,
].join('\n');
return new Response(body, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}
نهج إضافة Vite
إذا استخدمت Remix مع Vite (الافتراضي منذ Remix v2.7+)، يمكنك التوليد llms.txt كجزء من البناء باستخدام إضافة Vite. يوضع الملف المولّد في دليل مخرجات البناء
ويُقدَّم كأصل ثابت؛ وهذا يجمع بساطة الملف الثابت مع الوصول إلى المحتوى وقت البناء.
import { vitePlugin as remix } from '@remix-run/dev';
import { defineConfig } from 'vite';
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
// Simple Vite plugin to generate llms.txt at build time
function llmsTxtPlugin() {
return {
name: 'generate-llms-txt',
buildStart() {
const content = `# Your Site\n\n> Summary.\n\n## Documentation\n\n- [Docs](https://yoursite.com/docs): Guide.\n`;
writeFileSync(resolve(__dirname, 'public/llms.txt'), content, 'utf-8');
},
};
}
export default defineConfig({
plugins: [remix(), llmsTxtPlugin()],
}); تحقّق
بعد النشر، تأكد من تقديم الملف بصورة صحيحة:
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 أدلة ذات صلة
- كيفية إنشاء llms.txt, والقوالب وقائمة الفحص.
- مرجع تنسيق llms.txt, تفاصيل المواصفة.
- دليل Vercel, انشر Remix على Vercel.
- دليل Cloudflare Pages، Remix على Cloudflare.
- المدقّق · المولّد.