banner
zzzhizhi

Hi, zzzhizhi

Coding is love, coding to the world is full of love!
github
x
follow
bilibili
telegram
discord user
email

Summary of Hugo Blog Setup Experience

The theme I used is PaperMod, and this article uses it as an example.

All paths must use relative paths (do not add a leading slash)!

Table of Contents#

If you want to display a table of contents on the article page, please pay attention to the following configuration:

Multilingual#

The configuration here can easily go wrong. If you, like me, enjoy creating multilingual blogs, please pay attention to the following configuration:

defaultContentLanguage: zh-cn

  • Sets the default language of the website to Simplified Chinese
  • Affects the URL structure generated by Hugo
  • Determines the language identifier for default content

Do not modify the above configuration unless you really need to change the default language.

defaultContentLanguageInSubdir: true

  • Controls whether the default language content is placed in a subdirectory
  • true: The default generated path is zh-cn/posts/
  • false: The default generated path is posts/

Example:

You need to configure the multilingual content directory:

Under the multilingual configuration, the effective paths for search.md and archive.md are:

The URLs for the above two can remain generally set in hugo.yaml:

To support the search function, the following configuration must be made in hugo.yaml:

Fonts#

I want to use Ubuntu Mono for English, HarmonyOS Sans SC for Chinese, and JetBrains Mono for code, so I made the following configuration.

Create themes/PaperMod/assets/css/extended/fonts.css:

Code Block Background Color#

The default brightness of the code block background color is very low (very dark), so I modified it.

In themes/PaperMod/assets/css/common/post-single.css at line 206, you can see that the --code-block-bg variable determines the background color of the code block:

A global search revealed that themes/PaperMod/assets/css/core/theme-vars.css has two declarations for this variable:

Changing both to rgb(43, 43, 43) will suffice.

Comments#

I use Giscus, which is a comment system implemented using GitHub Discussions.

Please ensure:

  • The blog repository is public; otherwise, visitors will not be able to view Discussions.
  • The giscus app is installed; otherwise, visitors will not be able to comment and respond.
  • The Discussions feature has been enabled in the repository.

Then visit the Giscus website, and configure it as required.

After configuration, content like the following will appear under the "Enable giscus" title:

Create layouts/partials/comments.html and copy and paste the obtained <script> tag into it.

Ensure that comments are enabled in hugo.yaml:

Deployment#

After running the hugo -D command, Hugo will build the static blog in the public directory. Generally, the public directory is deleted before each build to ensure that the newly built content is correct.

In this case, I want to deploy only the static blog to the repository, not the entire Hugo framework. So I wrote a Shell script:

Since it was inconvenient to maintain, I switched to creating a separate source branch and deployment branch within the same repository. Thus:

Combined with the CI/CD provided by Cloudflare Pages, a single script can achieve one-click push updates.

Do not configure baseURL in hugo.yaml, as this will cause all deployed unique preview URLs to be redirected to baseURL.

Example of hugo.yaml#

This is the hugo.yaml I used.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.