1.8.0 • Published 4 months ago

hexo-seo-submit v1.8.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

自动或手动提交您的网站信息至搜索引擎(谷歌,bing,百度)。支持配置 GitHub ActionsCoding Jenkins 来适配不同平台的 CI

CI status NPM version NPM downloads

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.ymldeploy

deploy:
  type: git
  repo: https://github.com/<username>/<project>
  ignore_hidden: false # 忽略隐藏文件及文件夹(目录)

复制申请凭证中获取的值,注意粘贴时需去除引号name 可以直接复制表格

npm.io

NameValue说明
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
  1. 在项目 => 持续集成 => 构建计划 中创建构建计划

npm.io npm.io 2. 创建完后点 去设置 在基础信息中,将 配置来源 选择为 使用代码库中的 Jenkinsfile节点配置池 需要选择可以连接 google 的节点,若无此需求可随意

npm.io 3. 在 触发规则 中可配置触发条件,例如:main 分支提交时触发和定时触发等。注意点保存

npm.io npm.io 4. 在 变量与缓存 中添加环境变量

npm.io

变量都不需要引号,复制粘贴 google_private_key 时需保持格式正确,建议连带引号复制,再去除即可

NameValue说明
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

本地 deploypush 到搜索引擎

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根配置项
sortBystring排序依据,createdupdated ,优先使用引擎中的字段created
countinteger生成 url 的数量,优先使用引擎中的字段10
fileRootPathstring生成文件的根路径,将生成在 root/public/fileRootPath 目录,如果你不想分散在 public 目录中,则可以使用该字段'',即 root/public/
includePathsarray包含的路径规则,支持 * 通配符,优先级高于 excludePaths,当冲突时,以 includePaths 为准
excludePathsarray排除的路径规则,支持 * 通配符,
CIobject持续集成配置
CI.enableboolean是否启用持续集成false
CI.cronstringCRON 表达式,指定任务调度时间,注意在 actions 中的时区,且仅在 platformgithub 时有效0 4 * * *
CI.platformstringgithubcodinggithub
CI.branchstring触发操作的分支名称,仅在 github 时有效master
baiduobject百度搜索引擎配置
baidu.enableboolean是否启用百度搜索引擎false
baidu.pathstring生成 urls 文件的路径baidu.txt
baidu.countinteger生成 urls 的数量
baidu.sortBystring排序依据baidu.tokenstring百度搜索引擎的 token
baidu.includePathsarray
baidu.excludePathsarray
googleobject谷歌搜索引擎配置
google.enableboolean是否启用谷歌搜索引擎true
google.pathstringgoogle.txt
google.accountKeysJSonFilestring谷歌账户密钥文件路径,默认 root 目录寻找google.json
google.countinteger
google.sortByinteger
google.proxystringhttps proxy,如果你是 clash 一般默认为 http://127.0.0.1:7890
bingobject必应搜索引擎配置
bing.enableboolean是否启用必应搜索引擎true
bing.apiKeystring必应搜索引擎的 API 密钥
bing.sortBystring
bing.pathstringbing.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

注意事项

  1. 搜索引擎中的 path 更改时注意后缀应于默认值保持一致
  2. google 连接缓慢?请使用 proxy 字段
  3. google push 失败?请注意 google_private_key 的格式

申请凭证

Baidu

百度站长平台 => 普通收录 => 资源提交 中得到 token

http://data.zz.baidu.com/urls?site=https://ksh7.com&token=***********

npm.io

效果查看,一般 T+1,或查看 actions 中的运行日志。

npm.io

Google

  1. 进入 Web Search Indexing API,选择 项目 并启用 API,没有可新建。

npm.io

  1. 点击 管理 按钮,进入 凭据 菜单,选择 创建凭据 => 服务账号

npm.io

  1. 填写 服务账号ID服务名称 可选,随后直接点击 完成

npm.io

  1. 点击创建好的服务账号,点击 密钥 => 添加密钥,选择 创建新密钥,选择 JSON 格式,点击 创建,下载 json 文件

npm.io

内容如下,在 github secrets 中分别对应 google_private_keygoogle_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"
}
  1. 打开 Google Search Console设置 => 用户和权限 => 添加用户,邮箱为上述 json email,权限请选择 拥有者

npm.io

  1. 打开 https://console.cloud.google.com/apis/api/indexing.googleapis.com/metrics,选择你的项目,进行验证

npm.io

Bing

  1. 打开 https://www.bing.com/webmasters/home,选择谷歌账号登录(可同步 Google Search Console,无需再验证)

npm.io

  1. 点击右上角的 设置 => API 访问 => 复制 API 密钥 即可

npm.io

  1. URL 提交菜单中可验证

npm.io

参考

hexo-seo-submit docs

Hexo-SEO-AutoPush

hexo-url-submission

1.2.0

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago

1.8.0

4 months ago

1.7.0

4 months ago

1.6.0

4 months ago

1.5.0

5 months ago

1.4.1

5 months ago

1.4.0

5 months ago

1.3.0

5 months ago

0.12.0

5 months ago

0.13.0

5 months ago

0.14.0

5 months ago

0.15.0

5 months ago

0.11.0

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.0

1 year ago