
# SEO والبحث

يوفّر Fumadocs البحث. ويضيف Onedocs مساعدات لخريطة الموقع وملفي robots.txt وllms.txt، مُهيّأة جميعها كمسارات في App Router لـNext.js. للاطلاع على بيانات الصفحة الوصفية وصور Open Graph، راجع `onedocs/metadata` و`onedocs/og` في [مرجع API](https://onedocs.inline0.dev/ar/docs/api-reference#metadata).

## البحث

يستخدم Onedocs بحث Orama المضمّن من Fumadocs. أنشئ مسار API:

```ts title="src/app/api/search/route.ts"
import { source } from "@/lib/source";
import { createFromSource } from "fumadocs-core/search/server";

export const { GET } = createFromSource(source);
```

يستعلم مربع البحث الذي يضيفه `RootProvider` عن `/api/search` افتراضيًا، لذا لا يلزم إعداد آخر.

## خريطة الموقع

أنشئ خريطة موقع على `/sitemap.xml`:

```ts title="src/app/sitemap.ts"
import { generateSitemap } from "onedocs/seo";
import meta from "../../content/docs/meta.json";

const baseUrl = "https://yourdomain.com";

export default function sitemap() {
  return generateSitemap({
    baseUrl,
    pages: meta.pages ?? [],
  });
}
```

يسرد `generateSitemap` جذر الموقع، ثم عنصر URL لكل إدخال في `pages` ضمن `/docs`. تُتخطى الإدخالات التي تبدأ بـ`---` (فواصل الشريط الجانبي)، ويُحوّل `index` إلى `/docs` نفسه. تُقرأ الإدخالات كما هي، لذا تحتاج الصفحات داخل المجلدات الفرعية إلى إدخالات خاصة بها، مثل `"guides/setup"`.

## Robots.txt

أنشئ ملف robots.txt على `/robots.txt`:

```ts title="src/app/robots.ts"
import { generateRobots } from "onedocs/seo";

const baseUrl = "https://yourdomain.com";

export default function robots() {
  return generateRobots({ baseUrl });
}
```

ينشئ هذا ما يلي:

```
User-Agent: *
Allow: /

Host: https://yourdomain.com
Sitemap: https://yourdomain.com/sitemap.xml
```

## LLMs.txt

يساعد [LLMs.txt](https://llmstxt.org/) مساعدات الذكاء الاصطناعي على فهم توثيقك. يستطيع Onedocs إنشاء نسختين: ملخصة وكاملة المحتوى.

### النسخة الملخصة

أنشئ `/llms.txt` بعناوين الصفحات وأوصافها:

```ts title="src/app/llms.txt/route.ts"
import { createLLMsSource, generateLLMsText } from "onedocs/llms";
import { source } from "@/lib/source";
import config from "../../../onedocs.config";

export async function GET() {
  const llmsSource = createLLMsSource(source);
  const text = await generateLLMsText(llmsSource, {
    title: config.title,
    description: config.description,
  });

  return new Response(text, {
    headers: { "Content-Type": "text/plain; charset=utf-8" },
  });
}
```

يبدأ الملف بالعنوان والوصف، ويسرد كل صفحة بصيغة `- Title: URL` مع وصفها، وينتهي بإشارة إلى `/llms-full.txt`. تقبل الدالتان المصدر المغلّف من `createLLMsSource`، وليس مصدر Fumadocs نفسه، وتعيدان وعدًا.

### نسخة المحتوى الكامل

أنشئ `/llms-full.txt` بالتوثيق الكامل:

```ts title="src/app/llms-full.txt/route.ts"
import { createLLMsSource, generateLLMsFullText } from "onedocs/llms";
import { source } from "@/lib/source";

export async function GET() {
  const llmsSource = createLLMsSource(source);
  const text = await generateLLMsFullText(llmsSource);

  return new Response(text, {
    headers: { "Content-Type": "text/plain; charset=utf-8" },
  });
}
```

تُكتب كل صفحة بعنوانها وURL ووصفها وMarkdown المعالَج، مع `---` بين الصفحات.

يأتي نص الصفحة من Markdown المعالَج في MDX الخاص بـFumadocs، وهو معطّل افتراضيًا. من دونه، لا يحتوي `llms-full.txt` إلا على العناوين وعناوين URL والأوصاف ([#3](https://github.com/inline0/onedocs/issues/3)). فعّله في `source.config.ts`:

```ts title="source.config.ts"
import { defineDocs } from "fumadocs-mdx/config";

export const docs = defineDocs({
  dir: "content/docs",
  docs: {
    postprocess: {
      includeProcessedMarkdown: true,
    },
  },
});
```

## خيارات الإعداد

### خيارات خريطة الموقع

```ts
generateSitemap({
  baseUrl: "https://yourdomain.com",
  pages: ["index", "getting-started", "configuration"],
  docsPath: "/docs", // Default: "/docs"
});
```

### خيارات Robots

```ts
generateRobots({
  baseUrl: "https://yourdomain.com",
  sitemapPath: "/sitemap.xml", // Default: "/sitemap.xml"
});
```

## ما الذي ستحصل عليه

بعد إعداد هذه المسارات:

| URL | الوظيفة |
|-----|--------------|
| `/api/search?query=...` | نقطة نهاية البحث API |
| `/sitemap.xml` | خريطة موقع XML لمحركات البحث |
| `/robots.txt` | ملف Robots يتضمن مرجعًا إلى خريطة الموقع |
| `/llms.txt` | ملخص لمساعدات الذكاء الاصطناعي |
| `/llms-full.txt` | توثيق كامل لمساعدات الذكاء الاصطناعي |
