试着给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

原文地址:https://www.cnblogs.com/craigtaylor/p/13785872.html