Hexo 每天自动提交网站url到搜索引擎

百度收录很蛋疼
在此之前用过@小康写的hexo-baidupush很不错。

由于Bing和Google只爬sitemap.xml收录已经很快了,但总是爬sitemap.xml效率肯定没Api提交的快。
自己写了Bing的定时自动提交,目前还不支持Google定时自动提交,因为Google的API提交方式很鸡肋

Google indexing API有两个问题

  1. 账户安全密钥不能被泄露(谷歌只支持这种提交方式,对于没有后台的hexo来说是很致命的)
  2. API提交只能使用json,而这个json格式只能包含一个网站url链接
    不能多url放到一个json里,所以需要多次请求提交(baidu、bing、只需一次请求)

Google 最优提交方案是本地提交(能解决以上两个问题)
如果你有什么好的处理方案欢迎与我交流

正文

安装插件

COPY
1
npm i hexo-seo-autopush --save

配置

在hexo 的config.yml里添加

hexo-seo-autopush配置

COPY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# enable: 开启/关闭 推送
# count: 每次提交最新的10篇文章
# https://github.com/lete114/hexo-seo-autopush
hexo_seo_autopush:
baidu:
enable: true
count: 100
bing:
enable: true
count: 10
google:
enable: true
count: 10
google_file: google_service_account.json # 谷歌服务账户

添加Google Push配置和解决push后没有GitHub Actions .github\workflows\AutoPush.yml文件的问题

COPY
1
2
3
4
5
6
7
8
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
- type: git
repo: https://github.com/lete114/Test.git
branch: main
ignore_hidden: false # 忽略隐藏文件及文件夹(目录)
- type: GooglePush # 谷歌提交

获取站长平台密钥

Baidu Key

  1. 打开百度站长平台,点击左侧的普通收录https://ziyuan.baidu.com/

Bing Key

  1. 打开Bing站长平台,https://www.bing.com/webmasters/home
  2. 点击右上角头像 旁边的齿轮,跟着下图操作

Google Key

  1. 打开Google indexing API官网
  2. 选择创建项目,点击继续
  3. 点击转到凭据页面
  4. 跟着如下图片步骤
    GoogleProof
    GoogleAddProof
    GoogleNone
    GoogleKey
    json文件内的内容
    COPY
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    {
    "type": "service_account",
    "project_id": "elated-guild-298003",
    "private_key_id": "cf58d669c0e8c8e082b2c403ade5e2548078e384",
    "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDEAJw89yeylRrA\nB+bzOAfQQNgOCABIwEKCy5mMxWSaiXy2RktyCJWjMR2Pgz770NJgClQHPJjsFn0c\nukHufpnuiX3VPlimLANPCRFdU/qp+yiaw4quIhYF1UZJkhmhL30anghUcvi+r9hQ\nw+RwcKrgA4EUzqUJaPdvjtzSoo315PPGfR91ASD5S8gE02yVI8igtYMX7v2x1JYR\n7PwHJwOVemiM9lot8ilvoUbV4BU0vSlwFoxKMJAbEXTmJjEKQi9992rcMW0GzXO8\ncHldUUtURXkt3VFjYTH27KhHiTkTXw+uZRBu1rkubDJkS8lGIWN7Fc/r4HMMCVTu\nXPS6HbJ/AgMBAAECggEANSS7OBaFd3jRL3cVCiZLjA5A5pEJzq/+eKtOn2oYDISx\nwVRO+YTVWdGj47kg1zM4D11NikbGaeDxHFxuKwW9o/04lpyYebneTcw2Hpl6EiOs\nz0WssOlCEmPQ8nrAI0GWiKSHuqoPwtg37TIoGsqZsjKRCby759DDokZYnm3/0sc+\niEllT0ZyBZhGDzyguVLEdCIR2P02q/hQzLyd6ejWGGwZebImbGoILhmuOjVrco0p\nV0JbrrNskjM5Epe7w+CpGftEASJ7Dxa8oj0qIT6cyAipra2AZAGnG9jrLcWpJuhu\nvNeDIFnTfpNEac+khXZZE2++MIQfTX9wGJc8tox2vQKBgQD6yiNvAL7sxExiy6ER\ntLtFQ3bvmMpKRFGvFOyPOtMbmjZ3D1GEtNNKGH4v1TI+tncEy7Q5Dm7nWwpi8yvL\nbh8xKghelAc/CU1nw0xDEDCkMbAwpFg5A5ZDImy3LZsQh0kNXniIMy1vMSt5yLKS\n80gXQKGCxG8t3rP8Qd/2a55g1QKBgQDIExP1nG9sHJaigmitEUwr0Ow6Shqr56Me\nd7995gaV1oLWWCQzrXt/viWkb1W5ZGIxzcWNWz99m4CbvqfewRr598Eenald0csN\nVcIEk+0C+6KqA+jU9Tfs2zow/C7JuKULP2N++o0EoSz/ngokP7f1yLOYbr507v/R\n0cLElQBQAwKBgAbxDWYHKUG4dTzO0hiBXiWepm4fVooTtgcYlyunvywmapeFDwaT\nUr3cS7HbPtbJiiXR1Z02rw8sT+9JN88brzVXKoAjrMer5D6ZA0Vf71i8H1pZUi/R\nz5jwHP48/uvIMtdx4/gxInLPc5qdWYQDw90Q5ueNtF4aqfSzhhV2CR45AoGBAJN9\nPOF6iMjx6jmyWOf8MGK8iOgPaMoA4Ea9j/SHdaNPlvPb1hQid0AcNDObv14Dmj+M\nqW0jLxKxZ4VobufPAsvyz/J51zjKRx11cqldQwNH7QnYB/O1MZzxn1wtC3C5JTG9\ncONSYFJhXoKxRliigEI3ye089jnNVdifAS1ZiflxAoGBANTX1fEMEeNuYU0v3rtd\n5CkPZg4TNZ+y2MGl5xR1LdIgrJ8c9xKoW4rpp7SsOIvHpWX494f90D7o9uFEGSQ4\nyQK53jVzJ0ekGV5BdPF3n3/2j2VEqFLHi7LL4CJSxr6ci7OfBoHOGE8odhevQCCK\njnFzEin0QsBEgIC73fBh6XcH\n-----END PRIVATE KEY-----\n",
    "client_email": "[email protected]",
    "client_id": "103034240916368863393",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/googleindexing%40elated-guild-298003.iam.gserviceaccount.com"
    }
  5. 打开谷歌站长平台
    GoogleAddUser
    GoogleAddEmail

配置博客仓库

  1. Name必须是baidu_tokenbing_apikey(不区分大小写)
    Secrets
  2. 添加完成后
    Secrets-token

谷歌的一些问题

触发谷歌提交的命令是hexo d

由于谷歌需要配合Google indexing API平台提供的json进行提交,而这个json格式不能泄露
为防止json泄露只能本地提交,将json放到hexo根目录可自定义重命名(必须对应插件的配置)

如果你的使用Github Actions自动部署的话请把仓库设置为私有
GoogleConfig

提交成功返回状态码

以上步骤完成后即可hexo d部署了

  1. 看看Github仓库是否上传成功
  2. 点击Actions查看是否执行
  3. 点击Auto Push—->build—–>点击第2步自动提交
    如图43行
    COPY
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    // baidu返回的结果
    {
    "remain": 2060, // 表示当天剩余的可推送url条数
    "success": 47 // 成功推送的url条数
    }
    // bing返回结果(错误)
    {
    "ErrorCode": 2, // 错误
    "Message": "ERROR!!! Quota remaining for today: 2, Submitted: 47"
    // Message:表示 你目前只剩2个url推送,而你现在推送的是47条url
    // bing新用户开始每日只有10个推送额,据我了解连续推送10天(这我也不确定)
    // 如果出现这个错误的话,你就只能先手动添加等系统给你分配额了(分配9999)
    }
    // bing返回结果(成功)
    {"d":null}
  4. Google 返回状态码
    成功返回
    COPY
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Google response:  {
    urlNotificationMetadata: {
    url: 'https://blog.lete114.top/article/hexo-seo-autopush.html',
    latestUpdate: {
    url: 'https://blog.lete114.top/article/hexo-seo-autopush.html',
    type: 'URL_UPDATED',
    notifyTime: '2020-12-08T02:31:32.871417693Z'
    }
    }
    }
    出现此错误需要翻墙
    COPY
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    FetchError: request to https://www.googleapis.com/oauth2/v4/token failed, reason: connect ETIMEDOUT 172.217.27.138:443
    at ClientRequest.<anonymous> (D:\Lete\GitHub\Hexo-Butterfly\node_modules\node-fetch\lib\index.js:1461:11)
    at ClientRequest.emit (events.js:321:20)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:321:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
    message: 'request to https://www.googleapis.com/oauth2/v4/token failed, reason: connect ETIMEDOUT 172.217.27.138:443',
    type: 'system',
    errno: 'ETIMEDOUT',
    code: 'ETIMEDOUT',
    config: {
    method: 'POST',
    url: 'https://www.googleapis.com/oauth2/v4/token',
    data: {
    grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
    assertion: 'eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJnb29nbGVpbmRleGluZ0BzdGF0ZWx5LXRyYW5zaXQtMjk3NzE1LmlhbS5nc2VydmljZWFjY291bnQuY29tIiwic2NvcGUiOiJodHRwczovL3d3d
Authorship: Lete乐特
Article Link: https://blog.imlete.cn/article/hexo-seo-autopush.html
Copyright: All posts on this blog are licensed under the CC BY-NC-SA 4.0 license unless otherwise stated. Please cite Lete乐特 's Blog !