Jask

Jask

记录简简单单的生活
twitter
follow
email
telegram
tg_channel

搭建hugo静态博客(部署篇)

1. 准备工作#

2. 创建库和环境#

  • 在 GitHub 中Create a new repository

    • 名字:yourusername.github.com
  • 创建 TOKEN

    • 账户 - 设置 - Develop Settings-Personal access tokens
    • Expiration 设置永不
    • 勾选repoworkflow

  • 链接 Token 到repository

    • 打开库 - 设置
    • 新建密钥。名称 TOKEN

3. 本地创建 workflow#

  • 在 your-blog-site 目录里面依次创建.github/workflows/hugo_de.yaml
name: deploy

# 代码提交到main分支时触发github action
on:
  push:
    branches:
      - dev

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
        - name: Checkout
          uses: actions/checkout@v4
          with:
              fetch-depth: 0

        - name: Setup Hugo
          uses: peaceiris/actions-hugo@v3
          with:
              hugo-version: "latest"
              extended: true

        - name: Build Web
          run: hugo -D

        - name: Deploy Web
          uses: peaceiris/actions-gh-pages@v4
          with:
              PERSONAL_TOKEN: ${{ secrets.TOKEN }} #TOKEN是刚才在库里面创建的名字,按照你的填。
              EXTERNAL_REPOSITORY: your-username/your-repository-name
              PUBLISH_BRANCH: main
              PUBLISH_DIR: ./public
              commit_message: auto deploy

这个自动程序是将你本地未部署的文件发布到 dev 分支,然后 Action 自动部署到 main 分支

4. 部署到 GitHub#

  • 在主目录下输入:
git init
git add .
git commit -m "update"
git branch -M dev
git remote add origin https://github.com/your-username/your-repository-name.git
git push -u origin dev
  • 设置 GitHub Page
    • repository-setting-general-Default branch:main
    • repository-setting-page-Deploy from a branch:main
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.