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

posted @   TaylorShi  阅读(1189)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示