Blog
AI & Machine Learning·6 min read

什么是 llms.txt,为什么你的网站可能需要一个

llms.txt 规范实用指南——如何让你的网站对 AI 模型更友好,以及为什么这对可发现性很重要。

Jo Vinkenroye·January 13, 2025
什么是 llms.txt,为什么你的网站可能需要一个

如果你最近关注 AI 领域,大概已经听说过 llms.txt。你可以把它想象成 robots.txt,但专门面向 LLM(大语言模型)

它解决什么问题

LLM 有一个根本性的问题:上下文窗口(context window)。它们一次只能处理这么多文本。当 AI 试图理解你的网站时,会遇到几个问题:

  • HTML 太乱了 — 导航、广告、脚本和实际内容全混在一起
  • 网站体量太大 — 大多数站点有几百个页面
  • 结构千差万别 — 每个网站的做法都不一样

把一个复杂的网站转换成 LLM 真正能用的格式,是很难的事。这就是 llms.txt 存在的意义

什么是 llms.txt?

Jeremy Howard(Answer.AI 联合创始人)在 2024 年 9 月提出了这个规范。它本质上是一个放在网站根目录的 markdown 文件,提供:

  • 网站的简要概述
  • 每个板块是关于什么的
  • 指向重要内容的链接及描述
  • 帮助 AI 理解你提供什么的上下文

它是一个专门为机器打造的精选索引

格式

就是纯 markdown。基本结构如下:

# Site Name
> Brief tagline or description
## About
A paragraph explaining what this site is and who it's for.
## Site Structure
- Homepage: / - What visitors find here
- Documentation: /docs - Technical guides and API references
- Blog: /blog - Articles and updates
## Key Pages
- [Getting Started](/docs/getting-started) - First steps for new users
- [API Reference](/docs/api) - Complete API documentation
## Contact
- Email: hello@example.com
- GitHub: github.com/example

实际案例

以下是我在自己网站上用的:

# Jo Vinkenroye - Web Application Developer
> Building ERP systems, SaaS platforms, and modern web applications
## About
Senior developer with 13+ years of experience specializing in
React, Next.js, blockchain development, and AI integration.
## Site Structure
- Homepage: / - Overview of skills, experience, and projects
- Experience: /experience - Detailed work history
- Blog: /blog - Technical articles and project write-ups
## Blog Posts
- Building a Tamagotchi on Garmin: /blog/garmigotchi
- Ad-Forge - AI-Powered Ad Generation: /blog/ad-forge

你应该添加一个吗?

说实话:目前还没有主要的 AI 公司正式声明他们在爬取时使用 llms.txt。这是一个提案标准,不是已采纳的标准

但采用率在增长。Anthropic、Cloudflare、Vercel、Cursor——都已经实现了。Mintlify 在 2024 年底把它推广到了所有托管文档

适合添加的情况:

  • 你有文档或技术内容
  • 你想在可能重要的事情上抢先一步
  • 你在为 AI 原生的内容发现做准备
  • 10 分钟搞定,零成本

可以跳过的情况:

  • 你的网站主要是视觉内容
  • 你在等正式的广泛采纳

在 Next.js 中实现

如果你用的是 Next.js App Router,可以创建一个动态路由:

// app/llms.txt/route.ts
Export async function GET() {
const content = `# Your Site Name
> Your tagline here
## About
Your description...
## Key Pages
- Homepage: / - Main landing page
- Blog: /blog - Articles and guides
`;
return new Response(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
});
}

对于博客文章等动态内容,你可以用代码自动生成:

// app/llms.txt/route.ts
Import { getAllPosts } from '@/lib/blog';
Export async function GET() {
const posts = getAllPosts();
const blogSection = posts
.map(post => `- ${post.title}: /blog/${post.slug}`)
.join('\n');
const content = `# My Site
## Blog Posts
${blogSection}
`;
return new Response(content, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}

工具和资源

一些可以帮你搞定这件事的工具:

  • llms_txt2ctx — 用于解析和生成上下文的命令行工具
  • vitepress-plugin-llms — VitePress 集成
  • docusaurus-plugin-llms — Docusaurus 集成
  • GitBook — 为所有托管文档自动生成

更大的图景

不管 llms.txt 最终是否成为通用标准,它要解决的问题不会消失。AI 模型会持续需要对网页内容的结构化访问

通过现在就实现它,你在:

  1. 让你的内容对当前的 AI 工具更易获取
  2. 为未来可能的广泛采纳做准备
  3. 从 AI 优先的角度思考内容

最后一点可能是最有价值的。随着 AI 成为人们发现内容的主要方式,机器可读性变得和人类可读性一样重要

结论

llms.txt 简单、低成本,但随着 AI 原生发现的增长,回报可能很可观。几分钟就能实现,同时向外界表明你的网站已经为 AI 优先的互联网做好了准备

查看官方规范了解更多细节,或者看看 AnthropicVercel 是怎么做的

Stay Updated

Get notified about new posts on automation, productivity tips, indie hacking, and web3.

No spam, ever. Unsubscribe anytime.

Comments

Related Posts