1. 前言
主要介绍使用gitee-publish
自动更新Gitee Pages
,不用每次发布后,还要手动去更新。
仓库地址:https://gitee.com/hepingxm/gitee-pages-autopublish
2. 安装
npm
下载慢的先设置淘宝镜像。
npm config set registry https://registry.npm.taobao.org
安装gitee-publish
npx cross-env PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors/ npm install -g gitee-publish
别问我为啥前面多了个PUPPETEER_DOWNLOAD_HOST
,都怪墙太厚,冒得办法。
3.配置
先介绍两种使用方式。
方式一: 使用配置文件的方式
gitee-publish --conf 配置文件路径 【ps:只支持绝对路径】
配置文件示例
{
"account": "xxx", // gitee 账户
"password": "xxx", // gitee密码
"repository": "xxx", // 仓库名,请写全名,不支持模糊查询
"outputimgpath": "" // 执行过程中的快照图片输出路径, 不填则不输出【ps:只支持绝对路径】
}
方式二: 命令行参数方式
gitee-publish -c gitee账户 -p gitee密码 -r gitee仓库名 -o 执行过程中的快照图片输出路径
// or
gitee-publish --account=gitee账户 --password=gitee密码 --repository=gitee仓库名 --outputimgpath=执行过程中的快照图片输出路径
因为使用gitee-publish
时,遇见'$eval' of null
错误。详情可见传送门
所以要修改源代码,才能正常运行。
找到node安装目录\node_modules\gitee-publish\index.js
原因是取仓库名称时,多了个span
。
所以要去掉,需要修改两个地方。
第94行
// let repositoryNameInfo = await repositoryItem.$('h4 > span > span > span')
let repositoryNameInfo = await repositoryItem.$('h4 > span > span')
第109行
// const repositoryDom = document.querySelector(`#search-projects-ulist > :nth-child(${index + 1}) > h4 > span > span > span > a`)
const repositoryDom = document.querySelector(`#search-projects-ulist > :nth-child(${index + 1}) > h4 > span > span > a`)
使用技巧:如果嫌弃命令太长,可以新建一个auto.bat`文件,将命令丢进去即可。
更新时间:2020/10/28 08:30:04
更新内容:添加 auto.bat 脚本内容
将auto.bat
脚本丢到博客根目录中即可。(为了执行hexo
命令。)
gitee-publish
命令需要配置环境变量。(比如:node安装目录\node_global
, 添加到 path
)
@echo off
call hexo clean
call hexo g
call hexo d
:: 自动更新 Gitee Pages
call gitee-publish -c yezhechenyang -p your_password -r yezhechenyang
pause