试着给VuePress添加全局禁止爬取支持,基于vuepress-plugin-robots
背景
有时候,我们有些内部网站希望不被外部抓取,那么我们可以借助vuepress-plugin-robots
来生成robots.txt
文件,来告诉爬虫不要抓取页面。
安装
npm install vuepress-plugin-robots
项目地址:https://github.com/HiYue/vuepress-plugin-robots
配置
准备一个sitemap.xml
文件,位置随意,路径和下文对应上就行。
<xml version="1.0" encoding="UTF-8" />
在.vuepress/config.js
中追加项plugins
-robots
plugins: {
'robots': {
host: "http://www.example.com",
disallowAll: true,
sitemap: "/assets/xml/sitemap.xml",
},
}
其中,
- host是必填项,填写网站域名,
disallowAll
是true,代表禁止所有爬虫,如果要放开,需要设置成false- sitemap是必填项
效果
编译完成后
我们将得到一个robots.txt
文件,路径是:http://www.example.com/robots.txt
同时得到一个sitemap.xml
文件,路径是:http:///www.example.com/assets/xml/sitemap.xml
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步