2021 02 20 自动部署Hugo静态博客
文章目录
Hugo静态博客自动部署
两个Github Repos:原始Repo: PDCA-blog 和目标Repo: hustbill.github.io
所有的原始博客文件(post/2021-02-20-post*.md) 存放在原始Repo: PDCA-blog ,Hugo Build出来的public文件夹则存放在目标Repo: hustbill.github.io。
以前都是手动运行脚本提交,并且部署到目标Repo。每次需要2-5秒时间,总归是有点不方便。
今天上午,参考了这篇博文:Automate your GitHub Pages Deployment using Hugo and Actions,有了peaceiris/actions-gh-pages, 可以自动调用Hugo build,把原始Repo: PDCA-blog 更新文件,重新build,并且部署到目标Repo: hustbill.github.io,完全不需要人工干预,省心省力。
剩下的只需要安心写字了。
详细步骤
Read Create SSH Deploy Key, create your SSH deploy key, and set the deploy_key option like the following
- Generate your deploy key with the following command.
|
|
Add your private key as a secret with name ACTIONS_DEPLOY_KEY in the Hugo Source Repository. Navigate to Your Hugo Source Repository > Settings > Secrets > Add new secrets and the name the secret as ACTIONS_DEPLOY_KEY and paste the contents of master file in the value.
Add your public key as deployment key in the GitHub pages repository Navigate to Your GitHub pages Repository > Settings > Deploy Key> Add new deploy key and set title something you can relate to the private key (like Public Key for my site deploy) and paste the contents of master.pub file in the value.
Add below file .github/workflows/pages.yml location of your Hugo source code and replace username/external-repository with your GitHub username and GitHub pages repository name.
|
|
Hugo publish 截图
Check the hugo publish status: repo -> Actions
参考链接
文章作者 Hustbill billyzhang2010@gmail.com
上次更新 2021-02-20