跳到正文
DEV Community· thriving_adder·· 46 分鐘前AI 評分54

如何為文件網站生成 llms.txt,並用 Web to Markdown & llms.txt 製作初稿

Generate an llms.txt for your docs site

AI 導讀

llms.txt 是供 AI 智能體快速找到網站重要頁面的精簡 Markdown 導覽;本文説明其格式、手動編寫方法,以及如何用作者自建的 Web to Markdown & llms.txt Actor 生成初稿。

正文

Agents that read your documentation often have to wade through navigation, cookie banners and other page chrome before they reach the actual content. An llms.txt file is a short, curated Markdown map of a site — proposed at llmstxt.org — that points them at the pages that matter.

This post explains the current format, shows how to write a file by hand (often the right first step), and then shows how to generate a first draft with Web to Markdown & llms.txt, an Apify Actor I built and publish as thriving_adder. I earn when it is used. You do not need the Actor to publish an llms.txt.

What an llms.txt looks like

The proposal is now in its second version (updated August 2026). The file is Markdown, usually published at /llms.txt, or at a sub-path such as /docs/llms.txt if it should only cover that section of the site.

The only required part is an H1 with the project or site name. After that, the usual structure is:

# Title

> Optional description goes here

Optional details go here

## Section name

- [Link title](https://link_url): Optional link details

## Optional

- [Link title](https://link_url)

A few rules that matter when you write or edit one:

  • The H1 is required. The blockquote is a short summary of the project.
  • Between the summary and the first H2 you can add notes, but not more headings.
  • Each H2 introduces a list of links. Every item is a Markdown link, optionally followed by a colon and a one-line description.
  • By convention, a section named Optional holds secondary links an agent can skip when it needs a shorter context.

The file is meant to stay small enough to fit in a context window. The detail lives on the pages you link to. The proposal also encourages clean Markdown versions of those pages (for example page.md next to the HTML) and rel="describedby" / rel="alternate" hints so clients can find them. That part is useful, but you can publish a useful llms.txt without it.

For a small docs site, writing the file yourself is often enough. Pick the 10–20 pages an agent should read first, give each a clear title and one-line description, and put secondary material under ## Optional. Several documentation platforms (Mintlify, GitBook, and some WordPress plugins, among others) can also generate a file automatically. After you publish it, test it: give an agent only the file and ask questions about your product.

The rest of this post is for when you want a first draft to edit, generated from a site you already have.

Generate a first draft

The Actor fetches public pages over HTTP (no headless browser), strips menus, footers and cookie banners, reads titles and descriptions, groups pages by URL path, and writes a spec-compliant llms.txt. It discovers pages from the site's sitemap, or from home-page links if there is no usable sitemap. By default it respects robots.txt and AI opt-outs (noai in robots tags, and robots.txt rules that block common AI crawlers such as GPTBot). JavaScript-only pages come back with the error code EMPTY_CONTENT and are not charged.

Use this on a site you own or have permission to work with. Review and edit the file before you publish it. Converting a page does not give you the right to republish someone else's content.

Cost

Prices below are from the live Store listing on 25 November 2026. Check that page before you run anything, in case they have changed.

Event Price
Actor start $0.00005 (one event per GB of memory, minimum one; the default 512 MB run counts as one event)
Page converted to Markdown $0.001
llms.txt generated $0.02

The $0.02 llms.txt price covers reading and listing up to maxPagesPerSite pages in that file. If you also turn on generateLlmsFullTxt, each included page is charged as a page conversion ($0.001) as well. Failed, non-HTML, blocked, and robots.txt or AI-opt-out skipped pages are free.

A 10-page llms.txt draft therefore costs about $0.02 plus the start fee. The Actor requires a run cap (maxTotalChargeUsd) of at least $0.03; you only pay for events that actually happen, not the cap.

Apify's Free plan includes $5 of monthly usage and does not require a card (apify.com/pricing, checked 25 November 2026).

One API call

Create a free Apify account and copy an API token from Console → Settings → API & Integrations. Replace APIFY_TOKEN in the request below. The Python 3 docs URL is only a public example so you can see the shape of the output — point llmsTxtSites at your own docs home, or at a sub-path such as https://example.com/docs/, when you generate a file you intend to publish.

This calls Apify's public synchronous endpoint, which waits for the run to finish (up to 300 seconds) and returns the dataset items as JSON. Ten pages is usually well under that limit. Set a long enough client timeout.

curl -sS --max-time 300 -X POST \
  "https://api.apify.com/v2/acts/thriving_adder~web-to-markdown-llms-txt/run-sync-get-dataset-items?maxTotalChargeUsd=0.03" \
  -H "Authorization: Bearer APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "llmsTxtSites": [{ "url": "https://docs.python.org/3/" }],
    "maxPagesPerSite": 10
  }'

The same call in JavaScript:

const response = await fetch(
  "https://api.apify.com/v2/acts/thriving_adder~web-to-markdown-llms-txt/run-sync-get-dataset-items?maxTotalChargeUsd=0.03",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer APIFY_TOKEN",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      llmsTxtSites: [{ url: "https://docs.python.org/3/" }],
      maxPagesPerSite: 10,
    }),
  },
);

const items = await response.json();
if (!response.ok) {
  throw new Error(`Run failed: ${response.status} ${JSON.stringify(items)}`);
}

const site = items.find((item) => item.type === "llms-txt");
if (!site || site.error) {
  throw new Error(site?.error ?? "No llms.txt row in the result");
}

console.log(`${site.site}: ${site.pageCount} pages via ${site.discovery}`);
console.log(site.llmsTxt);

The site row (type is "llms-txt") includes:

  • llmsTxt — the file text
  • pageCount — how many pages were listed
  • discovery — sitemap, home-page-links, or sitemap+home-page-links
  • sections — the H2 groups it built from URL paths
  • existingLlmsTxt — whether the site already publishes /llms.txt
  • llmsTxtUrl — a download URL for the file in the run's key-value store

Here is a shortened example of a previously generated draft for the public Python 3 docs, so you can see the format (not something to publish as your own):

# Python documentation

> The official Python documentation.

This file lists the main pages of docs.python.org/3/ for large language models, following the llms.txt proposal (https://llmstxt.org).

## Main

- [Python 3.15 documentation](https://docs.python.org/3/): The official Python documentation.
- [About this documentation](https://docs.python.org/3/about.html): Python's documentation is generated from reStructuredText sources using Sphinx...

## Faq

- [Python Frequently Asked Questions](https://docs.python.org/3/faq/index.html): General Python FAQ, Programming FAQ, Design and History FAQ...

Copy-paste versions of this script, plus a curl one-pager and a Python example that writes Markdown chunks for RAG, are in the MIT-licensed examples repo under web-to-markdown/.

After you get the file

  1. Read it. Drop pages an agent does not need. Tighten the blockquote summary. Move secondary links under a section named ## Optional.
  2. Check existingLlmsTxt so you do not overwrite a file you already publish without meaning to.
  3. If the draft included pages you wanted to skip, rerun with includeUrlPattern or excludeUrlPattern (regular expressions, for example /(tag|author|page)/).
  4. Publish the edited file at /llms.txt or at the sub-path it should cover, then test it with an agent.

If you also want a single file that contains the cleaned Markdown of every listed page, set "generateLlmsFullTxt": true. Each of those pages is then charged at $0.001, so a 10-page llms-full.txt is about $0.03 plus the start fee. Raise maxTotalChargeUsd to 0.05 if you use this option. Some teams keep that file internal; some publish it next to llms.txt.

Clean Markdown for individual pages

The same Actor can convert specific public URLs to cleaned Markdown, with optional heading-aware chunks for embeddings. This uses the urls field, not llmsTxtSites. A two-page run with 400-token chunks looks like this and costs $0.002 plus the start fee:

curl -sS --max-time 300 -X POST \
  "https://api.apify.com/v2/acts/thriving_adder~web-to-markdown-llms-txt/run-sync-get-dataset-items?maxTotalChargeUsd=0.03" \
  -H "Authorization: Bearer APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      { "url": "https://www.python.org/about/" },
      { "url": "https://docs.python.org/3/tutorial/index.html" }
    ],
    "chunkTokens": 400,
    "chunkOverlapTokens": 40
  }'

Each successful page row includes markdown, title, description, wordCount, tokensEstimate, and, when chunkTokens is greater than 0, a chunks array with heading paths. Email addresses and phone numbers are redacted by default.

Only convert pages you are allowed to use. The publisher's copyright still applies.

Limits worth knowing

  • There is no headless browser. Pages that render their content only in JavaScript return EMPTY_CONTENT (free). Most docs, blogs and company sites that are server-rendered work.
  • Only public http(s) pages. No logins, cookies or paywalls. Localhost and private-network addresses are rejected and not charged.
  • respectRobotsTxt and respectAiOptOuts default to true. Skipped pages are free. Turn those off only for sites you own or have permission for.
  • maxPagesPerSite defaults to 25 and accepts 1–500. A short llms.txt usually means the sitemap or home page did not expose more allowed URLs, or you hit the cap.
  • If the synchronous endpoint times out (HTTP 408 after 300 seconds), start a smaller run or use Apify's asynchronous run API instead.

If something looks wrong, open an issue on the Actor's Issues tab with the URL and the input you used.

來源:DEV Community · dev.to