hexo-seo-submit v1.8.0
自动或手动提交您的网站信息至搜索引擎(谷歌,bing,百度)。支持配置 GitHub Actions
或 Coding Jenkins
来适配不同平台的 CI
star 后使用,效果更佳~~
📦 Install
npm install hexo-seo-submit
yarn add hexo-seo-submit
pnpm add hexo-seo-submit
🔨 Usage
直达文档:hexo-seo-submit docs
在 hexo/_config.yml
中配置 hexo-seo-submit
hexo-seo-submit:
sortBy: updated # created | updated, default created
count: 2 # set all engine count, default 10
fileRootPath: hexo-seo-submit # will generate in root/public/fileRootPath, default '', root/public/
# includePaths & excludePaths: set all engine path rules
# includePaths has higher priority than excludePaths when conflict
# find path rules in https://www.npmjs.com/package/wildcard-match
includePaths: ['/posts/npm*'] # match path: /posts/npm-test1, /posts/npm/test1
excludePaths: ['/posts/*', '/posts/y?rn']
CI:
enable: true
cron: 0 4 * * *
platform: github # github | coding, default gitHub
branch: main # actions trigger branch, default master
baidu:
enable: true # default false
path: baidu.txt # default google.txt
count: 1
token: you baidu token
sortBy: created
# overwrite root config includePaths(same excludePaths)
includePaths: ['/posts/y*']
google:
enable: true
path: google-url.txt # default google.txt
# find path in root
accountKeysJSonFile: google.json # path.join(process.cwd(), path)
count: 2
# maybe required
proxy: http://127.0.0.1:7890
bing:
enable: true
apiKey: your bing api key
sortBy: created # default created
path: bing.json
github 中使用
如果在 github actions
中运行,可如下简化
hexo-seo-submit:
CI:
enable: true
baidu:
enable: true
google:
enable: true
bing:
enable: true
注意!生成后的 actions
文件路径为:public/.github/workflows/hexo-seo-submit.yml
,由于点开头的文件或文件夹默认被 hexo-deployer-git
忽略,你需要在 _config.yml
的 deploy
中
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
可尝试直接复制粘贴引号内的内容~
图一:复制粘贴引号内的内容 图二:复制粘贴包含引号内容,再去除引号
coding 中使用
hexo-seo-submit:
CI:
enable: true
platform: coding
baidu:
enable: true
google:
enable: true
bing:
enable: true
在项目 => 持续集成 => 构建计划
中创建构建计划
2. 创建完后点
去设置
在基础信息中,将 配置来源
选择为 使用代码库中的 Jenkinsfile
。节点配置池
需要选择可以连接 google 的节点,若无此需求可随意
3. 在
触发规则
中可配置触发条件,例如:main
分支提交时触发和定时触发等。注意点保存
4. 在
变量与缓存
中添加环境变量
变量都不需要引号
,复制粘贴 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 |
本地 deploy
时 push
到搜索引擎
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
本地执行 hexo deploy
时,hexo-seo-submit
会将 public
中生成的 urls
提交至搜索引擎、你需要将申请的 Baidu token、Bing apikey、Google json 填入。如果你的网络环境连接 google
较慢的话,可以尝试使用 proxy
字段,支持 https
。最后需要在 deploy
中配置
参数
hexo-seo-submit 配置参数描述
参数 | 类型 | 描述 | 默认值 | |||||
---|---|---|---|---|---|---|---|---|
hexo-seo-submit | 根配置项 | |||||||
sortBy | string | 排序依据,created 或 updated ,优先使用引擎中的字段 | created | |||||
count | integer | 生成 url 的数量,优先使用引擎中的字段 | 10 | |||||
fileRootPath | string | 生成文件的根路径,将生成在 root/public/fileRootPath 目录,如果你不想分散在 public 目录中,则可以使用该字段 | '' ,即 root/public/ | |||||
includePaths | array | 包含的路径规则,支持 * 通配符,优先级高于 excludePaths ,当冲突时,以 includePaths 为准 | ||||||
excludePaths | array | 排除的路径规则,支持 * 通配符, | ||||||
CI | object | 持续集成配置 | ||||||
CI.enable | boolean | 是否启用持续集成 | false | |||||
CI.cron | string | CRON 表达式,指定任务调度时间,注意在 actions 中的时区,且仅在 platform 为 github 时有效 | 0 4 * * * | |||||
CI.platform | string | github 或 coding | github | |||||
CI.branch | string | 触发操作的分支名称,仅在 github 时有效 | master | |||||
baidu | object | 百度搜索引擎配置 | ||||||
baidu.enable | boolean | 是否启用百度搜索引擎 | false | |||||
baidu.path | string | 生成 urls 文件的路径 | baidu.txt | |||||
baidu.count | integer | 生成 urls 的数量 | ||||||
baidu.sortBy | string | 排序依据 | baidu.token | string | 百度搜索引擎的 token | |||
baidu.includePaths | array | |||||||
baidu.excludePaths | array | |||||||
google | object | 谷歌搜索引擎配置 | ||||||
google.enable | boolean | 是否启用谷歌搜索引擎 | true | |||||
google.path | string | google.txt | ||||||
google.accountKeysJSonFile | string | 谷歌账户密钥文件路径,默认 root 目录寻找 | google.json | |||||
google.count | integer | |||||||
google.sortBy | integer | |||||||
google.proxy | string | https proxy,如果你是 clash 一般默认为 http://127.0.0.1:7890 | ||||||
bing | object | 必应搜索引擎配置 | ||||||
bing.enable | boolean | 是否启用必应搜索引擎 | true | |||||
bing.apiKey | string | 必应搜索引擎的 API 密钥 | ||||||
bing.sortBy | string | |||||||
bing.path | string | bing.json |
使用命令执行
npx hexo-seo-submit -h
# or
npx hexo-seo-submit google -h
# 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> -k "$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
的格式
申请凭证
Baidu
百度站长平台 => 普通收录
=> 资源提交
中得到 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
注意,在 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,
设置 => 用户和权限 => 添加用户
,邮箱为上述json email
,权限请选择拥有者
Bing
- 打开 https://www.bing.com/webmasters/home,选择谷歌账号登录(可同步
Google Search Console
,无需再验证)
- 点击右上角的
设置 => API 访问 => 复制 API 密钥
即可
URL 提交
菜单中可验证
参考
5 months ago
5 months ago
5 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago