前言
hexo-seo-submit 插件,支持在 Github 和 Coding 平台中每天自动提交你的最新文章链接(或本地手动)至搜索引擎,让搜索引擎更快的收录你的文章。同样也支持命令行调用,支持多种场景~
插件由 typescript 编写,支持自动部署。有编码能力且有需求的话可以提 PR 哦~
现在很多插件都支持了 actions 中的自动化,由于早期入手 Hexo 时,追求访问速度(双线部署)选择 coding部署静态资源,也由于距离 github 过于遥远的原因~ 时常连接不上他。
哈哈,coding 虽然有优点不多,总归离得近~
点点 Star,感谢感谢~~
需要快速开发 Hexo 插件的同学,可以使用 corgii 快速生成插件模板,支持 typescript 哦。
pnpm dlx corgii@latest <folder-name>
# or
pnpm dlx corgii@latest
安装
npm install hexo-seo-submit
yarn add hexo-seo-submit
pnpm add hexo-seo-submit
使用
更改配置后,需要 hexo generate 后部署
在 github actions 中使用
在根目录中的 _config.yml 中配置插件。
需要注意!生成后的 actions 文件路径为:root/public/.github/workflows/hexo-seo-submit.yml,由于点开头的文件或文件夹默认被 hexo-deployer-git忽略,你需要在 _config.yml 的 deploy 中增加 ignore_hidden 配置。
若你不需要 deploy 的相关配置可忽略。
默认触发分支为 master,可自行更改
_config.yml
hexo-seo-submit: CI: # cron: 0 4 * * * # branch: master # default master enable: true baidu: enable: true google: enable: true bing: enable: true deploy: type: git repo: https://github.com/<username>/<project> # 注意~ ignore_hidden: false # 忽略隐藏文件及文件夹(目录)
配置环境变量
复制申请凭证中获取的值,注意粘贴时需去除引号。name 可以直接复制表格
| Name | Value | 说明 |
|---|---|---|
| baidu_token | 百度的 token | |
| bing_apikey | 必应的 apikey | |
| google_private_key | —–BEGIN PRIVATE KEY—–\n…..\n—–END PRIVATE KEY—–\n | 谷歌的 private_key |
| google_client_email | 谷歌的 client_email |
谷歌的 private_key 在带引号或不带引号复制粘贴时,在 actions 变量输入框中将表现不一(如下的图一和图二)。带引号复制粘贴会在使用时转义 换行符(\n => \\n or \\\\n),目前理论解决该问题,若遇到 routines::unsupported 可尝试直接复制粘贴引号内的内容~
图一:复制粘贴引号内的内容
图二:复制粘贴包含引号内容,再去除引号
[{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/google-key-1.webp","alt":"复制引号内的内容","title":""},{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/google-key-2.webp","alt":"复制的内容包含引号","title":""}]
在 Coding 中使用
启用后,运行 hexo generate 会在 public 下生成 Jenkinsfile。与 github CI 不同的是,触发规则和构建计划需要手动配置。
_config.yml
hexo-seo-submit: CI: enable: true platform: coding baidu: enable: true google: enable: true bing: enable: true
创建 构建计划
项目 => 持续集成 => 构建计划 创建一个新的构建计划。(注意~ 请选择使用代码库中的 Jenkinsfile)
[{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmmxy07h9j30b40ug76k.webp?imageMogr2/thumbnail/!50p","dataset":{"originPic":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmmxy07h9j30b40ug76k.webp","thumbnail":""}},{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmmt10atqj31ts11e4ed.webp?imageMogr2/thumbnail/!50p","dataset":{"originPic":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmmt10atqj31ts11e4ed.webp","thumbnail":""}}]
配置节点池
如果你需要提交至 Google 的话,需要在构建计划设置 基础信息 中选择可以连接 Google 的节点
配置触发
在 触发规则 中可配置触发条件,例如:main 分支提交时触发和定时触发等。注意点保存
[{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmn9pfhxvj32i00tmtl6.webp?imageMogr2/thumbnail/!50p","dataset":{"originPic":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmn9pfhxvj32i00tmtl6.webp","thumbnail":""}},{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmn9p74jxj316e0yctfb.webp?imageMogr2/thumbnail/!50p","dataset":{"originPic":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmn9p74jxj316e0yctfb.webp","thumbnail":""}}]
配置变量
变量都不需要引号,复制粘贴 google_private_key 时需保持格式正确,建议连带引号复制,再去除即可
| Name | Value | 说明 |
|---|---|---|
| baidu_token | 百度的 token | |
| bing_apikey | 必应的 apikey | |
| google_private_key | —–BEGIN PRIVATE KEY—–\n…..\n—–END PRIVATE KEY—–\n | 谷歌的 private_key |
| google_client_email | 谷歌的 client_email |
[{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmn9q8iowj31p80mkk08.webp?imageMogr2/thumbnail/!50p","dataset":{"originPic":"https://static.ksh7.com/post/docs-hexo-seo-submit/0085UwQ9gy1hqmn9q8iowj31p80mkk08.webp","thumbnail":""}},{"url":"https://static.ksh7.com/post/docs-hexo-seo-submit/google-key-3.webp","alt":"","title":""}]
本地 deploy
本地执行 hexo deploy 时,hexo-seo-submit 会将 public 中生成的 urls 提交至搜索引擎、
你需要将申请的 Baidu token、Bing apikey、Google json 填入。如果你的网络环境连接 google 较慢的话,可以尝试使用 proxy 字段,支持 https。
最后在 deploy 中配置启用该插件即可。
hexo-seo-submit:
baidu:
enable: true
token: you baidu token
google:
enable: true
accountKeysJSonFile: google.json
proxy: http://127.0.0.1:7890
bing:
enable: true
apiKey: your bing api key
# 注意在此处配置
deploy:
- type: hexo-seo-submit
详细参数
命令行使用
help
npx hexo-seo-submit -h
# or
npx hexo-seo-submit google -h
command
# baidu
$ npx hexo-seo-submit baidu -t <your baidu token> -s https://ksh7.com -f baidu.txt
# bing
# must .json file, Eg: { siteUrl: 'https://ksh7.com', urlList: ['xxx'] }
$ npx hexo-seo-submit bing -k <you bing api key> -f examples/files/bing.json
# google
# use Environment variables
$ export PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n..."
$ npx hexo-seo-submit google -f examples/files/baidu.txt -p http://127.0.0.1:7890 -m <your client_email here> -key "$PRIVATE_KEY"
# use json file
$ npx hexo-seo-submit google -f examples/files/baidu.txt -p http://127.0.0.1:7890 -a examples/files/google-keys.json
注意事项
- 搜索引擎中的
path更改时注意后缀应于默认值保持一致 google连接缓慢?请使用proxy字段google push失败?请注意google_private_key的格式- 插件在
CI中会抛出错误,但不会终止任务,首次需观察日志输出。
申请凭证
百度
百度站长平台 => 普通收录 => 资源提交 中得到 token
http://data.zz.baidu.com/urls?site=https://ksh7.com&token=***********
效果查看
一般 T+1,或查看 actions 中的运行日志。
启用 Web Search Indexing API
创建 服务账号
点击 管理 按钮(API启用后即可看到),进入 凭据 菜单,选择 创建凭据 => 服务账号
填写 服务账号ID ,服务名称 可选,随后可直接点击 完成
创建 密钥
点击创建好的服务账号,点击 密钥 => 添加密钥,选择 创建新密钥,选择 JSON 格式,点击 创建,下载 json 文件
内容如下,在 github secrets 中分别对应 google_private_key、google_client_email。如果你为本地部署的话,该文件将是 accountKeysJSonFile 字段的值。
注意,在 github 中,复制 private_key 时不需要 引号,在 coding 中复制需要 引号
{
"private_key": "-----BEGIN PRIVATE KEY-----\nxxxxxx\n-----END PRIVATE KEY-----\n",
"client_email": "googleindexing@elated-guild-298003.iam.gserviceaccount.com"
}
授权 Google Search Console
验证
Bing
关联资源
API 密钥
点击右上角的 设置 => API 访问 => 复制 API 密钥 即可
验证
URL 提交菜单中可验证
结
star star ~
























