参考文章

sed的使用
find的使用

注

在hexo根目录下创建 urls.txt 文件

该文件用于保存你的 hexo 网站的所有网址

然后创建脚本文件 auto-p.sh 用于推送urls.txt文件


> urls.txt
echo "清除urls文件"
hexo g | find ./public -name "*.html" >> urls.txt
sed -i 's/\.\/public\//https:\/\/darktom.gitee.io\//' urls.txt
echo "usls.txt生成"
curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://darktom.gitee.io&token=你的token"
echo "主动推送完成"


# 组要在public目录下的index.html文件路径(相对)查找出来,sed替换 ./public/ 为 你的网址主域名就可以了。
# 百度站长 主动推送
# 例如 http://data.zz.baidu.com/urls?site=https://darktom.gitee.io&token=**** 准入秘钥
# 百度站长 api主动推送脚本 生成所有 站点网址 在urls.txt 然后 curl将其上传
# hexo g | grep -r html ./public > urls.txt

结果是这样就表示成功了

success

success: 50表示成功推送网址个数
remain : 表示当日剩下可推送网址的个数

最好不要频繁推送,因为在搜索引擎爬虫来说,多次提交相同的链接,会让其工作更加繁重、且大多工作无效,自然对你的推送额自动调低。
这个推送额还会随你的网站访问次数来向应调整。

当然该种方法不够智能,每次回重复提交链接,当文章数目多了的话,每一次提交链接数太多,多提交几次,一天的提交额就没了,还得亏百度的提交额多,bing每天就10个那肯定就不行了。所以下方的插件就更方便了。

hexo-submit-urls-to-search-engine API推送插件

插件介绍

使用过程中心得:
在插件属性配置时


hexo_submit_urls_to_search_engine:
submit_condition: count #链接被提交的条件,可选值:count | period 现仅支持count
count: 1 # 提交最新的10个链接
period: 900 # 提交修改时间在 900 秒内 15分钟内 的链接
google: 0 # 是否向Google提交,可选值:1 | 0(0:否;1:是)
bing: 1 # 是否向bing提交,可选值:1 | 0(0:否;1:是)
baidu: 1 # 是否向baidu提交,可选值:1 | 0(0:否;1:是)
txt_path: submit_urls.txt ## 文本文档名, 需要推送的链接会保存在此文本文档里
baidu_host: 'https://darktom.gitee.io' ## 在百度站长平台中注册的域名
baidu_token: ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里!
bing_host: https://darktom.gitee.io ## 在bing站长平台中注册的域名
bing_token: ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里!
google_host: https://darktom.gitee.io ## 在google站长平台中注册的域名
google_key_file: Project.json #存放google key的json文件,放于网站根目录(与hexo _config.yml文件位置相同),请不要把json文件内容直接发布在公众仓库里!
replace: 1 # 是否替换链接中的部分字符串,可选值:1 | 0(0:否;1:是)
find_what: https://gitee.com/darktom/darktom.git
replace_with: https://darktom.gitee.io



如下开始还不知道 replace的作用,直到报错了才知道

不适用replace,当你又是,gitee仓库路径名与gitee账户名相同的话,他生成的url是以repo开头即https://gitee.com/darktom/darktom.git/ 你的文章;这样提交的链接与你在百度还是bing添加的网站域名 https://darktom.gitee.io(实际域名)是不同的,当你提交链接时,就会提示该网站域名不同,提交失败。
所以才有了repalce的用武之地。

当然引起上面问题的终极原因是,_config.yml中url的配置应该是 https://darktom.gitee.io(实际域名),而不是你的git仓库url。这种问题会出现在所有有用到url的地方,比如sitemap的生成、html页面中文章的地址都会以url前缀开头。
在站长平台提交的域名也是 应为实际域名,而不是git仓库的url。

使用建议:
目前该插件只支持count,count设置为1,每一次写完一篇文章就将其链接提交就好。主要是将所有的文章生成时间排序,然后去其前几个的链接,而且暂时不支持有更新时间决定提交的链接(感觉这个也没啥用)。

文章更新时间是自动在hexo g过程中。生成完就是在html页面中了。

// 以下是该插件生成提交urls文件的代码 (genenrator.js)

var fs = require('fs');

const getFileUpdatedDate = (path) => {
const stats = fs.statSync(path)
return stats.mtime;
}

module.exports = function(locals) {
var log = this.log;
var config = this.config;
var submit_condition = config.hexo_submit_urls_to_search_engine.submit_condition
var count = config.hexo_submit_urls_to_search_engine.count;
var period = config.hexo_submit_urls_to_search_engine.period;
var urlsPath = config.hexo_submit_urls_to_search_engine.txt_path;
var cjh_replace = config.hexo_submit_urls_to_search_engine.replace;

if (submit_condition == 'count') {
log.info("Generating urls for last " + count + " posts");

// get last posts
var urls = [].concat(locals.posts.toArray())
.map(function(post) {
return {
"date": post.updated || post.date,
"permalink": post.permalink
}
})
.sort(function(a, b) {
return b.date - a.date;
})
.slice(0, count)
.map(function(post) {
var cjhLink = post.permalink
if (cjh_replace == 1) {
var find_what = config.hexo_submit_urls_to_search_engine.find_what;
var replace_with = config.hexo_submit_urls_to_search_engine.replace_with;
cjhLink = cjhLink.replace(find_what, replace_with);
}
return cjhLink;
})
.join('\n');

log.info("Posts urls generated in " + urlsPath + "\n" + urls);

return {
path: urlsPath,
data: urls
};
} else if (submit_condition == 'period') {
log.info("Generating urls for period");
var find_what = config.hexo_submit_urls_to_search_engine.find_what;
// get last posts
var temp = [];
var urls = [].concat(locals.posts.toArray())
.map(function(post) {

var t = {
"date": post.updated,
"permalink": post.permalink
}
// var str = t.date.replace(/-/g, "/");
var from = new Date(t.date);
let _to = ((new Date()).getTime() - from.getTime()) / 1000;
// log.info(t.date + "/" + t.permalink + "/" + _to);
if (_to < period) { temp.push(t); }

});

// log.info(temp);




if (temp.length == 0) {
log.info("None of posts to post");
return {
path: null,
data: null
}
}

urls = temp.map(function(post) {
var cjhLink = post.permalink
log.info(cjhLink + " 最后更新于 " + (new Date()).toLocaleString(post.date, "yyyy-MM-dd hh:mm:ss"))
if (cjh_replace == 1) {

var replace_with = config.hexo_submit_urls_to_search_engine.replace_with;
cjhLink = cjhLink.replace(find_what, replace_with);

}
return cjhLink;
})
.join('\n');

log.info("Posts urls generated in " + urlsPath + "\n" + urls);

return {
path: urlsPath,
data: urls
};

} else {
log.info("Please check config.hexo_submit_urls_to_search_engine.submit_condition!!!");
}
};