<!-- Generated from ar/llms-txt-astro/index.html. The canonical document is the HTML page. -->

- [ الرئيسية ](/ar/) 
/
- [ كيفية إنشاء ](/ar/how-to-create/) 
/
- دليل Astro            
# `llms.txt` مع Astro

نهجان: ضع ملفاً في public/ للنشر الفوري، أو أنشئه ديناميكياً من مجموعات محتواك عبر نقطة نهاية TypeScript.

آخر تحديث: 29 أكتوبر 2026

في هذه الصفحة

- [ النهج 1، ملف ثابت في public/ ](#approach-1)
- [ النهج 2، نقطة نهاية TypeScript مع getCollection() ](#approach-2)
- [ إضافة llms-full.txt ](#llms-full)
- [ مواقع Starlight: starlight-llms-txt ](#starlight)
- [ تحقّق بعد البناء ](#verify)
- [ أي نهج تختار ](#which)               
مثال

يعمل هذا الموقع على Astro

بُني llmtxt.info نفسه باستخدام Astro على Cloudflare Pages. والطرائق أدناه هي بالضبط ما نستخدمه
لتقديم ملفنا الخاص  /llms.txt .

## النهج 1: ملف ثابت في `public/`

أبسط خيار. أنشئ ملفاً نصياً عادياً في `public/llms.txt` في جذر مشروعك. وينسخ Astro الدليل
الكامل `public/` الدليل حرفياً إلى `dist/` أثناء `astro build`،
حتى يُقدَّم الملف في
`/llms.txt` من دون أي إعداد.
static approach, public/llms.txt    نسخ     

```
# Place the file at: public/llms.txt
# Astro copies everything in public/ to the output directory as-is.
# Result: served at https://yoursite.com/llms.txt, no code changes needed.

# After deploy, verify:
curl -I https://yoursite.com/llms.txt
# Expected: HTTP/2 200 | Content-Type: text/plain
```

**متى تستخدم هذا:** إذا كان محتواك لا يتغير كثيراً، أو كنت تريد انعدام العبء وقت البناء،
أو كنت تدير الملف يدوياً. ويعمل بالطريقة نفسها على Cloudflare Pages وVercel وNetlify وأي مضيف Astro
آخر.

## النهج 2، نقطة نهاية TypeScript مع `getCollection()`

يطابق Astro الامتداد المزدوج `.txt.ts` ويتعامل مع
`src/pages/llms.txt.ts` كنقطة نهاية API تستجيب على العنوان
`/llms.txt`. في وضع SSG (الإعداد الافتراضي)، يعيد Astro تصييره مسبقاً إلى ملف ثابت `dist/llms.txt` وقت البناء، من دون كلفة وقت التشغيل.
src/pages/llms.txt.ts    نسخ     

```
// src/pages/llms.txt.ts
// Astro treats src/pages/foo.ext.ts as a route for /foo.ext
// In SSG mode (default), it pre-renders to dist/llms.txt at build time.

import type { APIRoute } from 'astro';
import { getCollection } from 'astro:content';

export const GET: APIRoute = async () => {
// Replace 'docs' with your actual content collection name
const docs = await getCollection('docs');

const lines = [
'# My Site',
'',
'> One-sentence description of what this site is about.',
'',
'## Documentation',
'',
...docs
.filter((d) => !d.data.draft)
.sort((a, b) => (a.data.order ?? 999) - (b.data.order ?? 999))
.map((d) => `- [${d.data.title}](https://yoursite.com/${d.id}/): ${d.data.summary ?? ''}`.trimEnd()),
'',
'## Optional',
'',
'- [Changelog](https://yoursite.com/changelog/): version history.',
];

return new Response(lines.join('\n'), {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};

```

تفترض نقطة النهاية وجود مجموعة `docs`. ومنذ Astro 6، يجب أن تستخدم جميع مجموعات
المحتوى واجهة Content Layer API: تُعرَّف المجموعات وقت البناء في `src/content.config.ts`
(وليس `src/content/config.ts`) مع أداة تحميل (loader)، على سبيل المثال:
src/content.config.ts    نسخ     

```
// src/content.config.ts
// Build-time collections are defined here, each with a loader (Content Layer API).
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const docs = defineCollection({
loader: glob({ base: './src/content/docs', pattern: '**/*.{md,mdx}' }),
schema: z.object({
title: z.string(),
summary: z.string().optional(),
order: z.number().optional(),
draft: z.boolean().optional(),
}),
});

export const collections = { docs };

```

النقاط الأساسية:

- استبدل `'docs'` مع اسم مجموعتك الفعلي من `src/content.config.ts`. 
- لم تعد المدخلات تملك الخاصية `slug`: استخدم `entry.id` لبناء عناوين URL. والمعرّفات
التي تولّدها أداة التحميل المدمجة `glob()` تُحوَّل إلى صيغة slug. 
- استبعد المسودات قبل إنشاء الخريطة: `!d.data.draft`. 
- يتضمن التعليق في كل سطر (`: short note`) اختياري لكنه موصى به بشدة، لأنه يمنح نماذج
اللغة الكبيرة سياقاً عن كل صفحة من دون أن تضطر إلى جلبها. 
- اضبط دائماً `Content-Type: text/plain; charset=utf-8` في الاستجابة.     
تحذير

وضع مخرجات SSR

إذا كنت تستخدم  output: 'server'  في  astro.config.mjs ، تعمل
نقطة النهاية عند كل طلب. وللنشرات عالية الحركة، أضف
export const prerender = true;  في أعلى الملف لفرض العرض المسبق الثابت حتى في وضع الخادم.

## إضافة `llms-full.txt`

الـ [llms-full.txt](/ar/llms-full-txt/) يضم الملف المصاحب متن كل صفحة بالكامل، وهو مفيد
لمسارات RAG وعملاء نماذج اللغة الذين يريدون المجموعة كلها دفعة واحدة. أنشئ نقطة نهاية موازية:
src/pages/llms-full.txt.ts    نسخ     

```
// src/pages/llms-full.txt.ts
// Generates the full-content companion file.
// Each entry gets its full Markdown body inlined, useful for RAG pipelines.

import type { APIRoute } from 'astro';
import { getCollection } from 'astro:content';

export const GET: APIRoute = async () => {
const docs = await getCollection('docs');
const sections: string[] = [];

for (const doc of docs.filter((d) => !d.data.draft)) {
sections.push(
`# ${doc.data.title}`,
'',
`URL: https://yoursite.com/${doc.id}/`,
'',
doc.body ?? '', // raw, uncompiled Markdown/MDX body (undefined if retainBody is false)
'',
'---',
'',
);
}

return new Response(sections.join('\n'), {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};

```

يحتوي `doc.body` على المتن الخام غير المُصرَّف لمدخل Markdown أو MDX، ما يُبقي المخرجات
خالية من وسوم HTML. وتكون قيمته `undefined` عند ضبط الخيار `retainBody` في أداة
التحميل على `false`، ومن هنا الرجوع إلى سلسلة نصية فارغة.

## مواقع Starlight: `starlight-llms-txt`

بالنسبة إلى التوثيق المبني باستخدام Starlight، تولّد الإضافة المجتمعية [starlight-llms-txt](https://delucis.github.io/starlight-llms-txt/) الملفات `llms.txt` و`llms-full.txt` و`llms-small.txt` من محتوى
الموقع. وتُصان في مستودع GitHub الشخصي لـ Chris Swithinbank (`delucis`)، وليس في
منظمة
`withastro`. ويعلن الإصدار 0.12.0 (المنشور في 15 سبتمبر 2026) الاعتماديات النظيرة
`astro ^7.0.0` و`@astrojs/starlight >=0.41.0`. ويلزم تحديد عنوان URL في
`site`:
astro.config.mjs, Starlight plugin    نسخ     

```
// astro.config.mjs
import starlight from '@astrojs/starlight';
import { defineConfig } from 'astro/config';
import starlightLlmsTxt from 'starlight-llms-txt';

export default defineConfig({
site: 'https://example.com/', // required by the plugin
integrations: [
starlight({
title: 'My Docs',
plugins: [starlightLlmsTxt()],
}),
],
});

```

## تحقّق بعد البناء
verify    نسخ     

```
# Build the project
npx astro build

# Check static output (works for both approaches in SSG mode)
cat dist/llms.txt

# Or start preview server and curl:
npx astro preview &
curl http://localhost:4321/llms.txt
curl http://localhost:4321/llms-full.txt
```

بعد النشر، الصق عنوان URL المباشر في [المدقّق](/ar/validator/)
لتأكيد مطابقة المواصفة: عنوان H1 واحد بالضبط، وصياغة روابط صالحة (`- [title](https://...)`)، جميع عناوين URL مطلقة ولا أقسام فارغة.

## أي نهج تختار

- **ثابت `public/llms.txt`**، وهو الأفضل للمواقع التي تتحدث نادراً. بلا
عبء، ولا TypeScript مطلوب، ويعمل في كل مكان. 
- **نقطة نهاية TypeScript `src/pages/llms.txt.ts`**، وهو الأنسب لمواقع
التوثيق ذات الصفحات المنشأة تلقائياً بكثرة. ويبقى الملف متزامناً تلقائياً عند كل بناء من دون
تعديلات يدوية.   
&rarr; [دليل الإنشاء الكامل](/ar/how-to-create/) &middot;
[دليل Next.js](/ar/llms-txt-nextjs/) &middot;
[دليل WordPress](/ar/llms-txt-wordpress/)

## المصادر

- [ llmstxt.org، اقتراح المجتمع ](https://llmstxt.org/)
- [ Astro، مجموعات المحتوى ](https://docs.astro.build/en/guides/content-collections/)
- [ Astro، المرجع البرمجي لمجموعات المحتوى ](https://docs.astro.build/en/reference/modules/astro-content/)
- [ Astro، الترقية إلى الإصدار 6 ](https://docs.astro.build/en/guides/upgrade-to/v6/)
- [ Astro، نقاط النهاية ](https://docs.astro.build/en/guides/endpoints/)
- [ توثيق starlight-llms-txt ](https://delucis.github.io/starlight-llms-txt/)
- [ الشيفرة المصدرية لـ starlight-llms-txt (delucis/starlight-llms-txt) ](https://github.com/delucis/starlight-llms-txt)
