The theme I used is PaperMod, and this article uses it as an example.
All paths must use relative paths (do not add leading slashes)!
Table of Contents#
If you want to display a table of contents on the article page, please pay attention to the following configuration:
params:
showToc: true # Globally display the table of contents
tocopen: true # Globally expand the table of contents (the table of contents is collapsed by default)
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
defaultContentLanguageInSubdir: true
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 the 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:
# When defaultContentLanguageInSubdir: true
public/
├── zh-cn/ # Default language (Chinese) content
│ └── posts/
└── en/ # Other language content
└── posts/
# When defaultContentLanguageInSubdir: false
public/
├── posts/ # Default language (Chinese) content
└── en/ # Other language content
└── posts/
You need to configure the multilingual content directory:
languages:
zh-cn:
languageName: "简体中文"
contentDir: "content/zh-cn" # content/<lang>
# ... Other multilingual configuration can be written here
en:
languageName: "English"
contentDir: "content/en"
# ...
Under the multilingual configuration, the effective paths for search.md
and archive.md
are:
content/
├── zh-cn/
│ ├── posts/
│ ├── search.zh-cn.md # search.<lang>.md
│ └── archive.md
└── en/
├── posts/
├── search.en.md
└── archive.md
The URLs for the above two can be kept generally set in hugo.yaml
:
languages:
zh-cn:
menu:
main:
- identifier: "search"
name: "搜索"
url: "search"
weight: 1
- identifier: "archives"
name: "归档"
url: "archives"
weight: 2
Search#
To support the search function, you must configure the following in hugo.yaml
:
outputs:
home:
- HTML
- RSS
- JSON # JSON is key for search support
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
:
@import url('https://cdn.jsdelivr.net/npm/ubuntu-mono/css/ubuntu-mono.min.css?display=swap');
@import url('https://cdn.jsdelivr.net/npm/harmonyos-sans-font/css/harmonyos-sans.min.css?display=swap');
@import url('https://cdn.jsdelivr.net