Follow Installation doc to install Hugo and PaperMod.
Git Submodule Method is recommended, which keeps your repo independent and tidy by seperating your configs and posts from the theme’s source code.
Notice: Don’t forget to add a .gitignore
file in your repo, like this:
|
|
Following are the tutorials of configuring PaperMod. You can reproduce the features by simply copy the corresponding code snippets or just clone my github page repo and replace my posts with yours.
Check PaperMod doc and Hugo quick start for more details. PaperMod exampleSite source is also a good start.
Configuration
Home Info
Follow the home info mode doc to show welcome message and social links on home page.
Add following to your hugo.yaml
, you can modify as you like:
|
|
More social icons are available in papermod icons.
Code Snippets:
Menus
Construct main menu in the top-right corner.
First, you need to specify menu entries and their URL routes in hugo.yaml
:
|
|
weight
is used to control the order of entries.
Code Snippets:
Tags page will be automatically generated (see hugo defualt taxonomies), while additional works are needed to generate Archive and Search pages.
Archive Page
Create Archive page content/archives.md
:
|
|
Code Snippets:
Search Page
Add following to your hugo.yaml
:
|
|
Create Search page content/search.md
:
|
|
Code Snippets:
Zoom in Image on Click
The issue comment provides a solution using medium-zoom, which works perfectly.
Add this to layouts/partials/extend_footer.html
to zoom an image and dim the background on click:
|
|
Code Snippets:
Demostration:
Latex Support
Papermod has a guide to setup KaTeX.
Create a partial layouts/partials/math.html
.
Notice: In order to support $
as delimiter, you need to call the renderMathInElement
to config Auto-render Extention as following:
|
|
Include the partial in extend_head.html
:
|
|
Then you can globally enable KaTex in hugo.yaml
as below or manually add math: true
in posts’ front matter:
|
|
Code Snippets:
Demostration:
|
|
Inline math: $E=mc^2$
Block math: $$ E=mc^2 $$
Show Lastmod Time as Date
Set date of every post in frontmatter is tooooo troublesome and hard to maintain. Luckily, we can configure dates to show file’s last modification timestamp.
Add this to hugo.yaml
:
|
|
Code Snippets:
Edit Link
Edit link for posts is the “Suggest Changes” button on this page, through which you can access the source file easily.
Add following to hugo.yaml
, you should change the URL
to your repo that contains the post’s source file:
|
|
It will link to $URL/posts/post-name.md
.
Code Snippets:
Syntax Highlighter
Using Hugo’s syntax highlighter “chroma” to config the code block’s line number, style and so on.
Code Snippets:
Demostration:
|
|
Host on Github Pages
Host your site on Github Pages and setup Github Actions, so that Github will rebuild and deploy your site automatically whenever you push a change. Hugo provides a guide to build the workflow.
Code Snippets:
Render Raw HTML in Markdown
Hugo does not render raw HTML by default. As a result, you cannot embed vedios using <iframe>
, superscript using <sup>
or insert collapsible sections using <details>
, etc. Though you can achieve the same by Hugo Shortcodes, you may prefer the more direct way: Insert pure HTML in Markdown.
Just enable the unsafe
option of Goldmark Markdown renderer in hugo.yaml
to make it work.
|
|
Code Snippets:
Demostration:
Change Content Width
This issue comment provides a nice solution.
Add following to assets/css/extended/theme-vars.css
:
|
|
Code Snippets:
Change Fonts
You can use fonts from Google Fonts.
- Find a font on Google Fonts.
- Get embed code for Web (several lines of html and css).
- Copy the html parts to
layouts/partials/extend_head.html
. - Copy the css parts to
assets/css/extended/blank.css
(adjust css selector according to your needs, e.g.body
,code
,.post-content
…).
Code Snippets:
Or download fonts like DroidSansM Nerd Font into static/fonts/
, then create assets/css/extended/fonts.css
with the following code:
|
|
And specify font-family
in assets/css/extended/blank.css
with the following code:
|
|
View Count
This blog is a great tutorial to count page views and site visits using busuanzi API.
Code Snippets:
Copying and editing the theme code could make things less elegant than before, but it’s a necessary compromise.
Q & A
How to specify image path?
Check this, there are two ways to reference a image in markdown.
My preferred way is:
- Put all images in
static/images
. - And reference an image by
![img](/images/test.png)
.
BTW, add #center
after image link to center it, see doc.
How to generate posts with desired default frontmatter?
- Create
archetypes/default.md
with the frontmatter template only . - Exec
hugo new content content/posts/new.md
.