llms.txt لـ Hugo

نهجان: ملف ثابت في static/ (بلا إعداد ويعمل في كل مكان)، أو تنسيق مخرجات مخصص يولّد llms.txt تلقائياً من محتواك وقت البناء.

آخر تحديث:

الخيار 1: ملف ثابت (موصى به)

ينسخ Hugo كل شيء في static/ الدليل مباشرةً إلى public/ ناتج البناء. ضع llms.txt هناك، وسيُقدَّم على /llms.txt على أي منصة استضافة، من دون حاجة إلى تغييرات في إعداد Hugo.

static/llms.txt, directory structure
# Hugo, zero-config static approach
#
# Place your file at: static/llms.txt
# Hugo copies everything in static/ directly to the public/ output directory.
# Your file will be served at /llms.txt on any host.
#
# Project structure:
# your-hugo-site/
# ├── static/
# │   └── llms.txt   ← add this
# ├── content/
# ├── layouts/
# └── hugo.toml
#
# No config changes needed. Run "hugo" and it appears in public/llms.txt.

بعد تشغيل hugo، ستجد public/llms.txt في مخرجات البناء لديك. انشر public/ إلى Cloudflare Pages أو Vercel أو GitHub Pages أو أي مضيف ثابت.

الخيار 2: تنسيق إخراج مخصص

يتيح لك نظام تنسيق مخرجات Hugo توليد أي نوع ملف من محتواك باستخدام قوالب Go. عرّف LLMSTXT التنسيق في إعداداتك، ثم أنشئ القالب؛ وسيبني Hugo public/llms.txt تلقائياً في كل hugo تشغيله.

الخطوة 1: أضف تنسيق الإخراج إلى إعداداتك

hugo.toml
# hugo.toml, define the llmstxt custom output format

[outputs]
  home = ["HTML", "RSS", "LLMSTXT"]

[outputFormats.LLMSTXT]
  mediaType = "text/plain"
  baseName = "llms"
  isPlainText = true
  notAlternative = true

هل تستخدم YAML؟ الإعداد نفسه:

hugo.yaml
# hugo.yaml, same config in YAML

outputs:
  home:
    - HTML
    - RSS
    - LLMSTXT

outputFormats:
  LLMSTXT:
    mediaType: text/plain
    baseName: llms
    isPlainText: true
    notAlternative: true

الإعدادات الرئيسية هي mediaType = "text/plain" (حتى يكتب Hugo ملفاً نصياً عادياً)، baseName = "llms" (ينتج llms.txt، و notAlternative = true (يخفي <link rel="alternate"> في HTML لديك).

كتابة القالب

أنشئ القالب في layouts/index.llmstxt.txt. يستخدم Hugo الـ الرئيسية قالب للإخراج على مستوى الجذر. وهذه نسخة بسيطة تسرد كل الصفحات العادية:

layouts/index.llmstxt.txt, simple
{{/* layouts/index.llmstxt.txt */}}
{{/* Hugo home template for the llmstxt output format */}}
# {{ .Site.Title }}

> {{ .Site.Params.description }}

{{ with .Site.Params.llmstxtContext }}{{ . }}

{{ end -}}
## Pages

{{ range .Site.RegularPages -}}
- [{{ .Title }}]({{ .Permalink }}): {{ with .Description }}{{ . }}{{ else }}{{ .Summary | plainify | truncate 120 }}{{ end }}
{{ end }}

للموقع ذي أقسام المحتوى المتعددة (مدونة وتوثيق وبرامج تعليمية)، نظّم المحتوى حسب القسم:

layouts/index.llmstxt.txt, by section
{{/* layouts/index.llmstxt.txt, organized by section */}}
# {{ .Site.Title }}

> {{ .Site.Params.description }}

{{ range .Site.Sections -}}
## {{ .Title }}

{{ range .Pages -}}
- [{{ .Title }}]({{ .Permalink }}): {{ with .Description }}{{ . }}{{ else }}{{ .Summary | plainify | truncate 100 }}{{ end }}
{{ end }}
{{ end -}}

## Optional

- [Homepage]({{ .Site.BaseURL }}): site entry point.
content/docs/getting-started.md
---
# content/docs/getting-started.md
title: "Getting started"
description: "Install the CLI, run your first command, and deploy in under 5 minutes."
draft: false
---

Your content here...

النشر

  • Cloudflare Pages، اضبط أمر البناء على hugo ودليل النشر إلى public. وستقدم Cloudflare Pages public/llms.txt في /llms.txt من CDN العالمية التابعة لهم. راجع دليل Cloudflare Pages لتوصيات رؤوس التخزين المؤقت.
  • Vercel، يُكتشف Hugo تلقائياً. اضبط أمر البناء على hugo ودليل الإخراج إلى publicراجع دليل Vercel لخيارات التخزين المؤقت على الحافة.
  • صفحات GitHub، استخدم سير عمل GitHub Actions يعمل hugo وينشر public/ إلى gh-pages الفرع. وسيُقدَّم الملف على العنوان https://your-org.github.io/llms.txt.
  • أي مضيف ثابت, انشر public/ الدليل. وسيكون الملف في الجذر ويُقدَّم بصورة صحيحة.

تحقّق

افحص محلياً أولاً:

Local verification
hugo
ls public/llms.txt          # should exist
cat public/llms.txt          # check content
https_proxy="" hugo server
curl http://localhost:1313/llms.txt

بعد النشر:

Production verification
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8

ثم الصق عنوان URL في المدقّق لفحص كامل للتوافق مع المواصفة.

أدلة ذات صلة

المصادر