背景
有時候,我們有些內部網站希望不被外部抓取,那么我們可以借助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