Rebuild my blog (static)

The enemy is back…

It’s so difficult this time. When I was preparing my resume, I found that my blog was gone. My dearest blog, which I had accompanied for a year and was well-received, was sacrificed. Wuwuwuwu

Don’t be impatient, don’t be impatient, learn a lesson, what is the first thing? I will definitely not use dynamic blogs anymore. I used workpress for my first blog in my freshman year. The server management tool I used at that time was the famous Pagoda. Although I still don’t use it now. I am using it, hahaha, but I will definitely never use it again in the future. Do you remember the second generation blog? The second generation blog is the blog I just sacrificed. It was built using docker and survived for two years (sophomore to junior year). The server was changed halfway through, but thanks to Docker’s elegant Portability haha, so my blog survives.

So why did it fail this time? ? ? The hanging date is September 1, 2023. The reason is that Java malfunctioned and it was found that the swtich space was insufficient. Then, I was ready to transplant and repair it, but I really felt that I couldn’t maintain it. I hope that my blog can survive for a few years, more than ten years, or even decades or hundreds of years.

So, start from scratch!!!

Choose a suitable blog template

I have used vuepress to take notes before, but vuepress is not particularly suitable for what I am doing now, because I am already visually exhausted, hahaha, and it is very uncomfortable to watch, so I used an open source project that I like very much, and many of you are familiar with it. Top open source project: hugo, GitHub address is:

The next step is to choose a suitable theme. I chose based on several popular themes.

Install Hugo

I am keen on source code. I can change the code and submit PR at any time, so I use the source code to build:

❯ git clone
❯ cd hugo
❯ go build
❯ mv hugo /usr/bin

Deploy theme

Choose the theme we use:

❯ git clone themes/PaperMod --depth=1

# If you want to update the theme latercd themes/PaperMod
❯ git pull

Use git submodule with

The code may be submitted to Github, so the git of external modules containing subprojects can be managed with git submodule.

❯ git submodule add --depth=1 themes/PaperMod
❯ git submodule update --init --recursive # needed when you reclone your repo (submodules may not get cloned automatically)

Note: You may use --branch v7.0 to end of above command if you want to stick to specific release.

Update theme using method 2:

❯ git submodule update --remote --merge

Add theme to hugo.toml:

It is recommended to use yaml or toml. I prefer to use yaml haha. Of course, you can use the tool to convert it at will.

baseURL = ''
languageCode = 'en-us'
title = 'cubxxw is blog'
theme = "PaperMod"

enableRobotsTXT = true
buildDrafts = false
buildFuture = false
buildExpired = false
googleAnalytics = "UA-123-45"
pygmentsUseClasses = true

disableXML = true
minifyOutput = true

env = "production"
title = "ExampleSite"
description = "ExampleSite description"
keywords = [ "Blog", "Portfolio", "PaperMod" ]
author = "Me"
images = [ "<link or path of image for opengraph, twitter-cards>" ]
DateFormat = "January 2, 2006"
defaultTheme = "auto"
disableThemeToggle = false
ShowReadingTime = true
ShowShareButtons = true
ShowPostNavLinks = true
ShowBreadCrumbs = true
ShowCodeCopyButtons = false
ShowWordCount = true
ShowRssButtonInSectionTermList = true
UseHugoToc = true
disableSpecial1stPost = false
disableScrollToTop = false
comments = false
hidemeta = false
hideSummary = false
showtoc = false
tocopen = false

   favicon = "<link/abs url>"
   favicon16x16 = "<link/abs url>"
   favicon32x32 = "<link/abs url>"
   apple_touch_icon = "<link/abs url>"
   safari_pinned_tab = "<link/abs url>"

   text = "Home"
   icon = "/apple-touch-icon.png"
   iconHeight = 35

   enabled = false
   title = "ExampleSite"
   subtitle = "This is subtitle"
   imageUrl = "<img location>"
   imageWidth = 120
   imageHeight = 120
   imageTitle = "my image"

     name = "Posts"
     url = "posts"

     name = "Tags"
     url = "tags"

   Title = "Hi there 👋"
   Content = "Welcome to my blog"

   name = "twitter"
   url = ""

   name = "stackoverflow"
   url = ""

   name = "github"
   url = ""

SiteVerificationTag = "XYZabc"

SiteVerificationTag = "XYZabc"

SiteVerificationTag = "XYZabc"

   hidden = true
   hiddenInList = true
   hiddenInSingle = true

   URL = "<path_to_repo>/content"
   Text = "Suggest Changes"
   appendFilePath = true

   isCaseSensitive = false
   shouldSort = true
   location = 0
   distance = 1_000
   threshold = 0.4
   minMatchCharLength = 0
   keys = [ "title", "permalink", "summary", "content" ]

identifier = "categories"
name = "categories"
url = "/categories/"

identifier = "tags"
name = "tags"
url = "/tags/"

identifier = "example"
name = ""
url = ""

noClasses = false

Then create a file:


title: "My 1st post"
date: 2020-09-15T11:30:03+00:00
# weight: 1
# aliases: ["/first"]
tags: ["first"]
author: "Me"
# author: ["Me", "You"] # multiple authors
showToc: true
TocOpen: false
draft: false
hidemeta: false
comments: false
description: "Desc Text."
canonicalURL: "https://canonical.url/to/page"
disableHLJS: true # to disable highlightjs
disableShare: false
disableHLJS: false
hideSummary: false
searchHidden: true
ShowReadingTime: true
ShowBreadCrumbs: true
ShowPostNavLinks: true
ShowWordCount: true
ShowRssButtonInSectionTermList: true
UseHugoToc: true
     image: "<image path/url>" # image path/url
     alt: "<alt text>" # alt text
     caption: "<text>" # display caption under cover
     relative: false # when using page bundles set this to true
     hidden: true # only hide on current single page
     URL: "<path_to_repo>/content"
     Text: "Suggest Changes" # edit text
     appendFilePath: true # to append file path to Edit link

It can be used by creating archetypes/

❯ hugo new --kind post archetypes/

**All examples below use yml/yaml format, I recommend using yml instead of toml as it is easier to read. **

Of course, as a cloud-native configuration file, yaml is more loved by me than toml :love_letter:

Basic commands of hugo

Added content:

You can use the hugo new command to add new content, for example:

❯ hugo new posts/

This command will generate the content/posts/ file,

Then, edit the content/posts/ file to add your content.

Generate all content:

❯ hugo

The above command will generate all pages and place them in the public/ directory.

You can use the hugo server command to preview your website locally:

❯ hugo server -D

The -D parameter means including draft content. Then, visit http://localhost:1313 in your browser to view your site.

Define path

By default, the path is strongly related. For example, in which directory you define it, the path is the path of this directory, but this is not absolute.

For example, the above:

❯ hugo new posts/

The default access URL for this post will usually be:

  • http://localhost:1313/posts/my-first-post/

Note the following points:

  1. Ending Slash: Hugo generates “pretty URLs” by default, which means they will end with a slash. You can modify this behavior in Hugo’s configuration file.
  2. Draft and Publish: Newly created posts are in draft status by default (draft: false in the header information of the post). If you use hugo server to preview your site without adding the -D parameter, you will not see the draft. In order to preview draft content, you need to use hugo server -D.
  3. Custom path: If you want to define a custom path for a specific post, you can specify it using the url attribute in the front matter of the post.

Theme configuration

In the next environment, we start our theme configuration. The configuration of the theme enriches hugo’s theme.

###Default theme dark/light

     # defaultTheme: light
     # defaultTheme: dark
     defaultTheme: auto # to switch between dark or light according to browser theme

Archives Layout

Create a page with in the content directory with the following content

├── config.yml
├── content/
│ ├── <--- Create here
│ └── posts/
├── static/
└── themes/
     └── PaperMod/

and add the following:

title: "Archive"
layout: "archives"
url: "/archives/"
summary: archives

NOTE: The Archives layout does not support multilingual month translations.

start up

Start using hugo server:

❯ hugo server

Then visit: http://localhost:1313/


Click Moon to support setting Light and Dark.

Normal mode (default mode)

Use the 1st entry as some information:

     Title: Hi there 👋
     Content: My name is Xinwei(bear) Xiong. My loyalty is to adventure 🤖
     - name: twitter
     - name: stackoverflow
     - name: github
     - name: zhihu
     - name: linkedin
     - name: bilibili
     - name: youtube
       url: https://https//
     - name: liberapay
     - name: email
     - name: weibo

Profile mode

Display Index/Home as a full page with social links and images

Add the following content to the configuration file:

         enabled: true
         title: "<Title>" # optional default will be site title
         subtitle: "This is subtitle"
         imageUrl: "<image link>" # optional
         imageTitle: "<title of image as alt>" # optional
         imageWidth: 120 # custom size
         imageHeight: 120 # custom size
             - name: Archive
             url: "/archive"
             - name: Github
             url: ""

     socialIcons: #optional
         - name: "<platform>"
             url: "<link>"
         - name: "<platform 2>"
             url: "<link2>"

Add BreadCrumb navigation above the article title to show subsections and home page navigation

     ShowBreadCrumbs: true

It is possible to disable the cover page for specific pages:

ShowBreadCrumbs: false

Edit post link

Adds a button that suggests changes by linking to the edit destination using the article’s file path.

For site configuration purposes:

         URL: "<gitlab user>/<repo name>/tree/<branch name>/<path to content>/"
         Text: "Suggest Changes" # edit text
         appendFilePath: true # to append file path to Edit link

Modifications can be made for individual pages:

     URL: "<path_to_repo>/content"
     Text: "Suggest Changes" # edit text
     appendFilePath: true # to append file path to Edit link

Icons Emoticons & Icons

Configuration file variables


Use GitHub actions for deployment and integrate some advanced commands in Makefile

The following is the configuration of the Makefile:

##################################=> common commands <=######### ####################################
# ========================== Capture Environment ===================== ==========
# get the repo root and output path
# ================================================= =============================

# define the default goal

SHELL := /bin/bash
DIRS=$(shell ls)


#include the common makefile
COMMON_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
# ROOT_DIR: root directory of the code base
ifeq ($(origin ROOT_DIR),undefined)
ROOT_DIR := $(abspath $(shell cd $(COMMON_SELF_DIR)/. && pwd -P))
# OUTPUT_DIR: The directory where the build output is stored.
ifeq ($(origin OUTPUT_DIR),undefined)
OUTPUT_DIR := $(ROOT_DIR)/_output
$(shell mkdir -p $(OUTPUT_DIR))

# BIN_DIR: The directory where the build output is stored.
ifeq ($(origin BIN_DIR),undefined)
$(shell mkdir -p $(BIN_DIR))

ifeq ($(origin TOOLS_DIR),undefined)
$(shell mkdir -p $(TOOLS_DIR))

ifeq ($(origin TMP_DIR),undefined)
$(shell mkdir -p $(TMP_DIR))

ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --tags --always --match="v*" --dirty | sed 's/-/./g') #v2.3.3.631.g00abdc9b.dirty

# Check if the tree is dirty. default to dirty(maybe u should commit?)
ifeq (, $(shell git status --porcelain 2>/dev/null))
GIT_COMMIT:=$(shell git rev-parse HEAD)

# COMMA: Concatenate multiple strings to form a list of strings
COMMA := ,
# SPACE: Used to separate strings
# SPACE: Replace multiple consecutive Spaces with a single space

## run-default: Run hugo server with default mode.
@$(TOOLS_DIR)/hugo server -D --gc -p 13132 --config config.default.yml

## run-profile-mode: Run hugo server with profile mode.
@$(TOOLS_DIR)/hugo server -D --gc -p 13133 --config config.profileMode.yml

## chroma-css: Generate chroma css.
@$(TOOLS_DIR)/hugo gen chromastyles --style=dracula > assets/css/lib/chroma-dark.css
@$(TOOLS_DIR)/hugo gen chromastyles --style=github > assets/css/lib/chroma-light.css

## run: Run hugo server.
.PHONY: run
run: tools.verify.hugo
@$(TOOLS_DIR)/hugo server -D --gc -p 13131 --config config.yml

## build: Build site with non-production settings and put deliverables in ./public
.PHONY: build
build: tools.verify.hugo module-check
@$(TOOLS_DIR)/hugo --cleanDestinationDir --minify --environment development

## module-check: Check if all of the required submodules are correctly initialized.
.PHONY: module-check
@git submodule status --recursive | awk '/^[+-]/ {err = 1; printf "\033[31mWARNING\033[0m Submodule not initialized: \033[34m%s\033[0m\n", $$2} END { if (err != 0) print "You need to run \033[32mmake module-init\033[0m to initialize missing modules first"; exit err }' 1>&2

## module-update: Updating themes
module-update: tools.verify.hugo
@git submodule update --remote --merge

## clean: Clean all builds.
.PHONY: clean
@echo "===========> Cleaning all builds TMP_DIR($(TMP_DIR)) AND BIN_DIR($(BIN_DIR))"
@-rm -vrf $(TMP_DIR) $(BIN_DIR)
@echo "============> End clean..."

## help: Show this help info.
.PHONY: help
help: Makefile
@printf "\n\033[1mUsage: make <TARGETS> ...\033[0m\n\n\\033[1mTargets:\\033[0m\n\n"
@sed -n 's/^##//p' $< | awk -F':' '{printf "\033[36m%-28s\033[0m %s\n", $$1, $$2} ' | sed -e 's/^/ /'

################################## Tools ############## #######################


## tools.verify.%: Check if a tool is installed and install it
.PHONY: tools.verify.%
@echo "===========> Verifying $* is installed"
@if [ ! -f $(TOOLS_DIR)/$* ]; then GOBIN=$(TOOLS_DIR) $(MAKE) tools.install.$*; fi
@echo "===========> $* is install in $(TOOLS_DIR)/$*"

## tools: Install a must tools
.PHONY: tools
tools: $(addprefix tools.verify., $(BUILD_TOOLS))

## tools.install.%: Install a single tool in $GOBIN/
.PHONY: tools.install.%
@echo "===========> Installing $,The default installation path is $(GOBIN)/$*"
@$(MAKE) install.$*

.PHONY: install.addlicense
@$(GO) install

.PHONY: install.hugo
@$(GO) install

Of course, Makefile is for local. If it is a remote server, you need to rely on github actions:

# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Pages

   # Runs on pushes targeting the default branch
     branches: ["main"]

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

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
   contents: read
   pages: write
   id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
   group: "pages"
   cancel-in-progress: false

# Default to bash
     shell: bash

   #Build job
     runs-on: ubuntu-latest
       HUGO_VERSION: 0.114.0
       - name: Install Hugo CLI
         run: |
           wget -O ${{ runner.temp }}/hugo.deb${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
           && sudo dpkg -i ${{ runner.temp }}/hugo.deb
       - name: Install Dart Sass
         run: sudo snap install dart-sass
       - name: Checkout
         uses: actions/checkout@v3
           submodules: recursive
       - name: Setup Pages
         id: pages
         uses: actions/configure-pages@v3
       - name: Install Node.js dependencies
         run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
       - name: Build with Hugo
           # For maximum backward compatibility with Hugo modules
           HUGO_ENVIRONMENT: production
           HUGO_ENV: production
         run: |
             --minify \
             --baseURL "${{ steps.pages.outputs.base_url }}/"
       - name: Upload artifact
         uses: actions/upload-pages-artifact@v2
           path: ./public

   # Deployment job
       name: github-pages
       url: ${{ steps.deployment.outputs.page_url }}
     runs-on: ubuntu-latest
     needs: build
       - name: Deploy to GitHub Pages
         uses: actions/deploy-pages@v2

Comment plugin

To add a comment, create an html file


and paste the code provided by your review provider

Also add this in config

     comments: true

I use: This is a plugin based on GitHub comments


Hugo supports the simultaneous creation of websites in multiple languages.

languages should define the available languages in a section of the site configuration.

Translate by file name

  1. /content/
  2. /content/

The first file is specified as English and linked to the second file. The second file is specified in French and linked to the first file.

Their language is specified based on the language code added as a suffix to the file name.

Content fragments are linked together as translated pages by having the same path and base filename.

If the file does not have a language code, it will be assigned a default language.

Translation by content directory

Of course, you can also translate based on the file directory. The system uses a different content directory for each language. The content directory for each language is set using the contentDir parameter.

     contentDir: content/english
     languageName: English
     weight: 10
     contentDir: content/french
     languageName: Français
     weight: 20

The value of contentDir can be any valid path - even an absolute path reference. The only restriction is that content directories cannot overlap.

The final example is as follows:

  1. /content/english/
  2. /content/french/

The first file is specified as English and linked to the second file. The second file is specified in French and linked to the first file.

Their language is specified based on the content directory in which they are located.

Content fragments are linked together as translation pages by having the same path and base name (relative to their language content directory).

Bypass default link

Any pages sharing the same translationKey set in the cover will be linked as the translated page, regardless of base name or location.

Consider the following example:

  1. /content/
  2. /content/
  3. /content/presentation/
translationKey: about

By setting the translationKey front matter parameter to about in all three pages, they will be linked as translation pages.

Use hugo new content to generate multilingual content

Given below are the translated files:

For the same directory:

hugo new content posts/
hugo new content posts/

For different directories:

hugo new content content/en/posts/
hugo new content content/de/posts/
hugo new content content/zh/posts/
hugo new content content/fr/posts/
hugo new content content/es/posts/
hugo new content content/zh-tw/posts/

We add the following parameters to our configuration file:

     languageName: English
     weight: 1
     languageName: Français
     weight: 2
     languageName: Spanish
     weight: 3

Now, our languages will be available using site.Languages and sorted by Weight. The lower…the higher the priority. As we will cover later, it is highly recommended to put the default language first.