介绍
HUGO是由 Go 语言实现的静态网站生成器。简单、易用、高效、易扩展、快速部署。
GitHub Actions是一个 CI / CD 工具,用于自动化 GitHub 中的测试,构建和部署过程。
步骤
1:创建 GitHub 仓库
创建创建 GitHub 仓库并命名为<your GitHub username>.github.io。
2:安装 HUGO 并创建项目
在 Window 10 上安装 HUGO 需要在官方仓库的releases页面下载最新版本 HUGO 的编译文件到本地并配置环境变量。
# 创建项目hugo new <your GitHub username>.github.io# 安装主题git clone --depth 1 --recursive https://github.com/gohugoio/hugoThemes.git themes# 本地运行hugo server -D
复制代码
3:将 HUGO 项目推送至 GitHub 仓库
# 初始化仓库git init# 将全部文件添加到暂存区git add *# 提交暂存区代码git commit -m "创建HUGO项目"# 创建主分支git branch -M main# 配置远程Github仓库git remote add origin https://github.com/<your GitHub username>/<your GitHub username>.github.io.git# 推送代码到远程Github仓库git push -u origin main
复制代码
4:创建 GitHub 的 token
在https://github.com/settings/tokens页面生成 token(勾选 repo)并复制到粘贴板。
5:将 token 添加到 Github 仓库密钥配置中
在<your GitHub username>.github.io仓库的Setting->Secrets页面创建创库密钥ACTIONS_DEPLOY_KEY并把 token 粘贴到 value 中。
6:创建 GitHub Action 配置文件
在<your GitHub username>.github.io仓库创建workflows/hugo.yml配置文件。
name: HUGOon: pushjobs: deploy: runs-on: ubuntu-18.04 steps: - name: Git checkout uses: actions/checkout@v2
- name: Update theme run: git submodule update --init --recursive - name: Setup hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: "0.64.0"
- name: Build run: hugo --minify
- name: Deploy uses: peaceiris/actions-gh-pages@v3 with: personal_token: ${{ secrets.ACTIONS_DEPLOY_KEY }} external_repository: <your GitHub username>/<your GitHub username>.github.io publish_dir: ./public user_name: <your GitHub username> user_email: <your GitHub email> publish_branch: gh-pages
复制代码
7:在 Github Pages 访问部署的静态网站
http://<your GitHub username>.github.io
链接
Hgohugoio/hugo
Hugo: Deploy Static Site using GitHub Actions
资源
hugo_0.80.0_Windows-64bit 提取码:1111
评论