Discuz! 3.4 如何生成 llms.txt 文件的具体方法
Discuz! 3.4 如何生成 llms.txt 文件的具体方法## 一、手动创建 llms.txt(推荐快速上手)由于 Discuz 3.4 没有现成插件,最可靠的方式是手动创建 llms.txt 文件并上传到网站根目录。
### 步骤 1:创建 llms.txt 文件
使用文本编辑器(如 VS Code、Notepad++)创建 `llms.txt`,内容结构如下:
```markdown
# [你的论坛名称]
> [论坛一句话描述,如:专注于XX领域的综合性技术交流社区]
[论坛名称] 成立于 [年份],是一个基于 Discuz! X3.4 搭建的在线社区,拥有 [用户数] 注册用户,日均发帖量 帖。
## 核心版块
- [版块名称1](https://yourforum.com/forum-1-1.html) : [版块描述]
- [版块名称2](https://yourforum.com/forum-2-1.html) : [版块描述]
- [版块名称3](https://yourforum.com/forum-3-1.html) : [版块描述]
## 精华内容
- [精华帖标题1](https://yourforum.com/thread-12345-1-1.html) : [帖子简介]
- [精华帖标题2](https://yourforum.com/thread-12346-1-1.html) : [帖子简介]
## 用户指南
- [注册与登录](https://yourforum.com/member.php?mod=register) : 新用户注册流程说明
- [发帖规范](https://yourforum.com/forum.php?mod=guide) : 社区发帖规则与指南
- [积分说明](https://yourforum.com/home.php?mod=spacecp&ac=credit) : 论坛积分获取与使用
## 关于我们
- [社区介绍](https://yourforum.com/portal.php) : 论坛发展历程与愿景
- [联系方式](https://yourforum.com/forum.php?mod=viewthread&tid=contact) : 管理员联系方式
## Optional
- [友情链接](https://yourforum.com/misc.php?mod=link) : 合作伙伴网站链接
- [归档内容](https://yourforum.com/forum.php?mod=guide&view=archive) : 历史精华帖归档
```
### 步骤 2:上传到 Discuz 根目录
通过以下方式之一上传文件:
| 方式 | 操作路径 |
|------|----------|
| **FTP 工具**(如 FileZilla) | 连接到服务器,上传到 `wwwroot/` 或 `public_html/` 目录 |
| **宝塔面板** | 文件 → 进入网站根目录 → 上传文件 |
| **cPanel 文件管理器** | File Manager → 进入 public_html → 上传 |
| **SSH 命令** | `scp llms.txt user@server:/var/www/html/` |
### 步骤 3:验证访问
在浏览器访问 `https://yourforum.com/llms.txt`,确保文件可正常显示 。
---
## 二、使用自动化工具生成(适合大型论坛)
如果你的论坛内容较多,可以使用第三方工具自动生成 llms.txt。
### 推荐工具:
| 工具 | 特点 | 适用场景 |
|------|------|----------|
| **llms-txt.io**| 免费在线生成,输入域名自动爬取 | 中小型论坛 |
| **Firecrawl LLMs.txt Generator**| API 支持,可深度爬取 | 大型论坛 |
| **SiteSpeakAI LLMs.txt Generator**| 免费在线工具,自动生成 | 快速试水 |
| **llmstxt by dotenv**| 开源 CLI 工具,基于 sitemap.xml | 有技术能力的站长 |
### 使用 llms-txt.io 的步骤:
1. 访问 https://llms-txt.io
2. 输入你的论坛域名
3. 工具会自动爬取网站结构
4. 下载生成的 `llms.txt` 和 `llms-full.txt`
5. 上传到 Discuz 根目录
---
## 三、开发 Discuz 插件(技术方案)
如果你有开发能力,可以创建一个简单的 Discuz 插件自动生成 llms.txt。
### 插件开发思路:
```php
// 文件:source/plugin/llms_txt/llms_txt.class.php
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class plugin_llms_txt {
function generate_llms_txt() {
global $_G;
$content = "# {$_G['setting']['bbname']}\n\n";
$content .= "> {$_G['setting']['bbname']} 是一个基于 Discuz! X3.4 的在线社区\n\n";
// 获取版块列表
$forums = C::t('forum_forum')->fetch_all_by_status(1);
$content .= "## 核心版块\n\n";
foreach($forums as $forum) {
if($forum['type'] != 'group') {
$url = "https://{$_G['setting']['domain']['default']}/forum-{$forum['fid']}-1.html";
$content .= "- [{$forum['name']}]({$url}) : {$forum['description']}\n";
}
}
// 获取精华帖
$threads = C::t('forum_thread')->fetch_all_by_digest(1, 10);
$content .= "\n## 精华内容\n\n";
foreach($threads as $thread) {
$url = "https://{$_G['setting']['domain']['default']}/thread-{$thread['tid']}-1-1.html";
$content .= "- [{$thread['subject']}]({$url})\n";
}
// 保存到根目录
$file_path = DISCUZ_ROOT.'./llms.txt';
file_put_contents($file_path, $content);
return true;
}
}
```
### 插件功能:
- 后台管理页面,一键生成 llms.txt
- 定时任务自动更新
- 自定义版块和帖子筛选规则
---
## 四、关键配置与优化建议
### 1. 服务器配置(Nginx/Apache)
添加 HTTP 头标识 llms.txt :
**Nginx 配置:**
```nginx
location = /llms.txt {
add_header X-Robots-Tag "llms-txt";
add_header Content-Type "text/plain; charset=utf-8";
}
```
**Apache 配置(.htaccess):**
```apache
<Files "llms.txt">
Header set X-Robots-Tag "llms-txt"
</Files>
```
### 2. 阻止搜索引擎索引(可选)
在 `robots.txt` 中添加 :
```
User-agent: *
Disallow: /llms.txt
Disallow: /llms-full.txt
```
### 3. 定期更新策略
| 更新频率 | 触发条件 | 操作 |
|----------|----------|------|
| **实时** | 新增精华帖、重要版块变更 | 手动重新生成 |
| **每周** | 常规内容更新 | 通过插件自动更新 |
| **每月** | 全面审查内容结构 | 使用工具重新爬取 |
---
## 五、验证与测试
完成部署后,进行以下验证:
1. **可访问性测试**:`curl https://yourforum.com/llms.txt`
2. **格式验证**:使用 https://llms-txt.io/validator 检查格式
3. **AI 引用测试**:在 ChatGPT、Claude 中提问"你的论坛名称 + 相关内容",观察是否被引用
---
## 总结
| 方案 | 难度 | 成本 | 适用场景 |
|------|------|------|----------|
| **手动创建** | 低 | 免费 | 内容较少的小型论坛 |
| **工具生成** | 低 | 免费/按需付费 | 中大型论坛 |
| **开发插件** | 高 | 开发成本 | 需要自动化的大型社区 |
**推荐路径**:先用 llms-txt.io 等工具生成初版文件,手动调整优化后上传。随着论坛发展,再考虑开发专用插件实现自动化更新。
页:
[1]