目录

hugo 博客自动发布

加快文章发布速度

旧方法

  1. 写完博客
  2. 运行hugo命令生成静态页面
  3. 打包
  4. 上传到服务器
  5. 在服务器上解压缩
  6. 发布完成

新方法

  1. 写完博客
  2. 本地运行 sh autopublish.sh
  3. 发布完成

效果

发布博客从原先5分钟变成现在1秒钟

代码

脚本1(放本地)
autopublish.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/bin/bash
cd your-hugo-website-project-location # 你自己Hugo路径
echo "cd project folder success"
rm -rf ./public # 当前目录里已经生成的静态文件删除
# hugo 不会帮忙删,不删的话老有上次的残余
hugo # 生成静态文件
git add . 
echo "added"
git commit -m "提交备注(自己改)" 
echo "commited"
git push
echo "pushed"
ssh root@2c2m sh auto_pull
echo "remote pull"

脚本2(放服务器上/root目录内)
autopull.sh

1
2
3
4
5
6
7
8
cd ~/hugo-website/
ls
git pull
echo "pull finished"
rm -rf /data/www/
echo "rm finished"
cp -r ~/hugo-website/public/. /data/www
echo "cp finished"

解决云服务器上每次git pull都要输密码的问题

1
2
git config  credential.helper store
git pull # 输一遍码云密码,以后就不用再输了

结论

可以利用码云做跳板更新腾讯云服务器上的文件,效果不错
本文用到的操作有:改hosts、linux免密登录、在码云上创建项目、git基本操作