Angular 中的 llms.txt

从 Angular 应用提供 llms.txt 只需在 public/ 文件夹中放置一个文件,无需配置。

最近更新:

文件放在哪里

自 Angular 17 起,CLI 会脚手架生成一个 public/ 项目根目录中的文件夹。其内容会逐字复制到构建输出根目录,因此文件位于 public/llms.txt 会在 https://yourdomain.com/llms.txt ,无需额外配置。

public/ 文件夹中的方法

  1. 如果文件夹不存在,请创建: mkdir -p public
  2. 添加文件: touch public/llms.txt
  3. 编写你的内容(请参阅 操作指南生成器 了解格式):
# Your Site Name

> One-sentence description of your site for LLM context.

## Core pages

- [Page title](https://yourdomain.com/page/): brief description.
- [Another page](https://yourdomain.com/other/): brief description.
  1. 构建并部署: ng build。文件会生成到输出根目录。

旧版项目(assets 数组)

在 v17 之前创建的 Angular 项目使用 src/assets/ 以及 assets 数组 于 angular.json。那里的文件将以 /assets/,而不是根目录, 这并非放置 llms.txt。最简洁的解决方法是添加一个 public/ 文件夹,并确保它已列入 assets 数组(较新的 CLI 配置默认已包含它):

// angular.json (build options)
"assets": [
  { "glob": "**/*", "input": "public" }
]

这会将 public/llms.txt ,输出到根目录,并在以下地址提供: /llms.txt.

验证设置

部署后,打开 https://yourdomain.com/llms.txt 。它应在浏览器中以纯文本加载。你也可以通过终端确认内容类型:

curl -sI https://yourdomain.com/llms.txt | grep -i content-type
# expect: content-type: text/plain

下一步:让文件与你的真实页面保持同步,并考虑一个更完整的 llms-full.txt。不确定格式是否正确?请通过 验证器另请参阅 VercelNetlify 指南,了解各托管平台的具体说明。

来源