Hugo博客的脚本快速发布博客

hugo使用脚本发布文章

前言

由于Hexo博客的生成速度太慢了,所以我开始使用Hugo博客
https://weirdchun.github.io/

写博客

当使用Hugo博客后,写文章的姿势

hugo new post/202001-xxxxxx.md

生成静态文件

使用hugo命名,就会在public生成博客页面

hugo

发布博客

进入public文件

cd public

常规git操作

git add .
git commit -m "blog"
git remote add origin https://github.com/Weirdchun/Weirdchun.github.io.git
git push -u origin master

使用脚本发布博客

新建deploy.sh文件

每次发布都得进行上面四步,太麻烦了,使用脚本代替!

  1. 在MyBlog根站点新建一个文件命名deploy.sh,写入git操作代码
#!/bin/bash

echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"

# Build the project.
hugo # if using a theme, replace by `hugo -t <yourtheme>`

# Go To Public folder
cd public
# Add changes to git.
git add -A

# Commit changes.
msg="rebuilding site `date`"
if [ $# -eq 1 ]
  then msg="$1"
fi
git commit -m "$msg"

# Push source and build repos.
git push github master

# Come Back
cd ..

双击deploy.sh文件

双击后将开始部署,但是得输入Github账号与密码后才会自动部署。
Tip:每次都得输入密码非常麻烦,我们需要Git免登录

打开Git Bash,

  1. 在C盘MINGW64 ~$ 模式下,touch创建文件 .git-credentials:
touch .git-credentials
  1. 用vim编辑此文件,
vim .git-credentials
  1. 输入内容格式
https://username:password@github.com
  1. 最后执行
git config --global credential.helper store
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值