Hugo 框架

7/8/2024 Hugo

# Hugo 框架

# 介绍


# 使用

# Hugo 安装

# 安装 golang
curl -sS https://webi.sh/golang | sh

# 安装 prebuilt Dart Sass(一般用不到)

# 安装 Hugo
curl -sS https://webi.sh/hugo | sh

# 快速搭建

  • 快速搭建
# 初始化项目
hugo new site hugo-demo

cd hugo-demo

# 克隆主题
git clone [email protected]:biaslab/hugo-academic-group.git themes/hugo-academic-group

# 删除主题 git
rm -rf themes/hugo-academic-group/.git

cp -av themes/hugo-academic-group/exampleSite/* .

cp config.toml hugo.toml

# 本地预览
hugo server --watch

# 构建
hugo --minify
  • 若 GitHub Pages 已绑定域名,可在 ./static 目录中添加含域名的 CNAME 文件

  • 设置 hugo.toml 配置文件中的 baseurl 的参数值为 https://username.github.io/repo


  • 目录结构
.
├── archetypes/
│   └── default.md
├── content/
├── hugo.toml    # 配置文件
├── static/
└── themes/

# 部署

  • GitHub Actions 示例
name: Hugo deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
          fetch-depth: 0
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: 'latest'
          # extended: false
      - name: Build
        run: hugo --minify
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v4
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
Last Updated: 7/16/2024, 6:18:48 AM