試着給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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM