安装NPM插件

1
npm install hexo-generator-baidu-sitemap --save


添加自定义js

1
2
3
4
5
6
7
8
9
10
11
function randomPost() {
fetch('/baidusitemap.xml').then(res => res.text()).then(str => (new window.DOMParser()).parseFromString(str, "text/xml")).then(data => {
let ls = data.querySelectorAll('url loc');
while (true) {
let url = ls[Math.floor(Math.random() * ls.length)].innerHTML;
if (location.href == url) continue;
location.href = url;
return;
}
})
}


在_config.butterfly.yml菜单内添加按钮

1
2
menu:
随机访问: javascript:randomPost(); || fa-solid fa-shuffle


在_config.yml内修改你的url

1
2
3
# URL
## Set your station url here. For example, if you use GitHub Page, set url as 'https://username.github.io/post'
url: https://username.github.io/post