16 Hexo迁移Hugo

为什么迁移 Hugo

  • Hugo 使用比 Hexo 简单, 只有单独的一个二进制文件
  • 苦于 HexoNodeModule 管理
  • 迁移成本更低, 结合 Github Action 实现 Markdown 文章发布, 自动更新至静态站
  • 规划:加入自定义域名以及做静态资源CDN做的加速


1、 之前基本所有的博客都托管与 github,这次也不例外, 复用,创建两个项目

  • template 仓库
  • private 仓库


  • 仓库 添加 settings -> Deploy keys -> Add Deploy Key (将公钥添加进去、注意允许 Write)
  • 仓库 添加 settings -> Actions secrets -> New Repository Secret ( NAME : ACTION_DEPLOY_KEY, Value: 私钥 )

3、git clone 仓库

git clone
# 初始化站点【--force 强制初始化】
hugo new site . --force

# content site 
# data json数据 or 其他
# static 静态文件
# themes 主题

# 后面可以执行 hugo new posts/ 创建新的文章
hugo new posts/

# 具体参考 进行操作

# 选择一个主题 可以选择
git submodule add themes/ananke 
# 后面的参照各个主题设置咯

# 本地测试
hugo serve

# 生成最小的静态文件, 会生成 public 文件
hugo --minify  

迁移 hexo 博客进入 hugo


整合 Github Action

新建 Github Action 描述文件 .github/workflows/deploy.yml

# This is a basic workflow to help you get started with Actions
name: Deploy on Main Branch

# Controls when the action will run. 
  # Triggers the workflow on push or pull request events but only for the main branch
    branches: [ main ]
    branches: [ main ]
#  schedule:
#    - cron: '0 21 * * *' # 定时任务

  # Allows you to run this workflow manually from the Actions tab

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
  # This workflow contains a single job called "build"
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2 #
          hugo-version: 'latest'
          extended: true
      - name: Build
        # 注意强制更新 git submodule 下载,否则生成的主题没有 html 文件哦
        run: |
          git submodule update --init --recursive
          hugo --minify --debug          

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3 #
          deploy_key: ${{ secrets.ACTION_DEPLOY_KEY }} # 这里的 ACTION_DEPLOY_KEY 则是上面设置 Private Key的变量名
          external_repository: PinkHello/ # Pages 远程仓库 
          publish_dir: ./public
          keep_files: false # remove existing files
          publish_branch: master  # deploying branch
          commit_message: ${{ github.event.head_commit.message }}

so 完美 迁移Hexo 迁移Hexo

最后修改于 2021-05-11