Introduction to Hugo

Hugo is a fast and modern static site generator written in Go, suitable for scenarios with high performance requirements.

  • It has an extremely fast build speed.
  • It is cross-platform (Windows, macOS, Linux).
  • It has powerful themes.

With Hugo, you can build:

  • Personal blogs
  • Company websites
  • Knowledge bases
  • Various types of documentation

The number of stars for Hugo has been steadily increasing year by year, which shows that it is very popular.

Star History Chart

Installation

macOS

Homebrew

brew install hugo

Linux

sudo apt install hugo

Windows

Precompiled Binaries

After installation, you can verify it by running the command hugo version.

Getting Started

hugo new site demo
cd demo
git init
git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/paper
echo "theme = 'paper'" >> hugo.toml
hugo server

SEO Optimization

๐ŸŒŸ Page Keywords and Description

---
title: "Building a Hugo Blog"
keywords:
- hugo
- build blog
- seo

description: "how to build a Hugo blog with SEO optimization"
---

i18n

๐ŸŒŸ Recommended approach:

โ”œโ”€โ”€ demo.en.md
โ””โ”€โ”€ demo.zh-cn.md

Then add the following configuration to hugo.toml:

# Set default language ["en", "zh-cn", "fr", "pl", ...]
defaultContentLanguage = "en"
# Website language (note CN is capitalized here) ["en", "zh-CN", "fr", "pl", ...]
languageCode = 'en'
# Whether to include CJK characters
hasCJKLanguage = true
# Whether to use emoji codes
enableEmoji = true

defaultContentLanguageInSubdir = false  # Don't use subdirectories for language separation

[languages]
  [languages.en]
    languageCode = "en"
    languageName = "English"
    weight = 1

  [languages.zh-CN]
    languageCode = "zh-CN"
    languageName = "Simplified Chinese"
    weight = 2

Deployment

๐ŸŒŸ Upload to GitHub and deploy to personal server via Action

name: hugo push to github pages

on:
  push:
    branches:
    - main

jobs:
  build-deploy:
    runs-on: ubuntu-24.04
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true

    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2
      with:
        hugo-version: '0.146.6'
        extended: true

    - name: Build
      run: HUGO_ENV=production hugo --gc --minify


    - name: Deploy to Server
      uses: appleboy/scp-action@v0.1.7
      with:
        host: ${ secrets.SERVER_HOST }
        username: ${ secrets.SERVER_USER }
        password: ${ secrets.SERVER_PASSWORD }
        source: "public/*"
        target: "/www/wwwroot/hugo/"

โš ๏ธ Note: You need to provide SERVER_HOST, SERVER_USER, and SERVER_PASSWORD configurations in your GitHub project settings: Settings -> Secrets and variables -> Actions -> New repository secret, then fill in the key and value.