无意中发现一个项目 ai.robots.txt ,它列出了大部分的与 AI 公司和 LLM 培训相关的网络爬虫的开放列表,于是我想着可以集成到博客中,每次构建拉取项目最新的 robots.txt 就行
大概没人会愿意自己的博客被AI训练吧,有人会愿意吗?
稍微思考了一下,有不少的方式可以实现,例如:
Github Action每次提交时自动拉取最新的robots.txt,或者定时拉取- 构建过程中拉取,如果是使用了
Github Page,那么在构建的过程中拉取最新的robots.txt(同理,我用的是 zeabur 平台部署,那么在 zbpack.json 中修改构建命令就行) - 在
package.json的构建命令中加上拉取文件的指令 - …
用 Github Action 的话,可能出现大量冗余的commit记录,并且浪费不必要的资源。如果使用 zeabur 的脚本,那这样锁死了平台,迁移不方便。如果在 package.json 中修改,那就方便很多了,也符合单一职责原则,下面是基本示例
// ... existing code ...
"scripts": {
"dev": "astro dev",
"prebuild": "DOWNLOAD_URL=$(curl -s https://api.github.com/repos/ai-robots-txt/ai.robots.txt/releases/latest | jq -r '.assets[0].browser_download_url') && wget -O public/robots.txt \"$DOWNLOAD_URL\"",
"build": "astro build",
"preview": "astro preview",
},
// ... existing code ...
prebuild 会自动在 build 之前自动构建。当然,我们可以给加上windows的适配,或者当无法拉取的时候依旧可以继续执行,或者让其更加符合单一职责原则…
// ... existing code ...
"scripts": {
"dev": "astro dev",
"pre:fetch:robots": "DOWNLOAD_URL=$(curl -s https://api.github.com/repos/ai-robots-txt/ai.robots.txt/releases/latest | grep 'browser_download_url' | head -n 1 | cut -d '\"' -f 4) && wget -O public/robots.txt \"$DOWNLOAD_URL\"",
"pre:install:d2": "curl -fsSL https://d2lang.com/install.sh | sh -s --",
"prebuild": "(npm run pre:fetch:robots; npm run pre:install:d2) || exit 0",
"build": "astro build",
"preview": "astro preview",
},
// ... existing code ...
这里以我实际的博客项目为例,构建之前因为需要拉取 robots.txt 并且下载 d2,所以 prebuild 中执行这两条命令
删除了 jq 排除了不存在该命令的情况,windows下无法使用 true 所以修改成了
exit 0,其他的虽然还有点不够优雅,不过问题不大





















