Hugo-Customization

Posted on February 6, 2019

A list about how I customize Hugo and why I did the change, the post will be updated continuously.

1. fractions

Network Engineer should care about this, because it shows wrong IP/mask format with default value:

fractions with default value
fractions with default value
Disable it in config.toml:
[blackfriday]
    fractions = false

2. hrefTargetBlank

This default value of the option is false which means external links(The wording was corrected to “absolute” from ’external’ on Hugo official doc). I prefer to change the value to true.

3. baseurl and canonifyURLs

canonifyURLs option should be to true for SEO purpose, baseurl should be configured at the same time. For my case (config.toml):

baseurl = "https://blog.gainskills.top"
canonifyURLs = true

Then, add following content to Hugo template:

<link rel="canonical" href="{{ .Permalink }}">

The site might be failed to load on local machine after the change because it failed to bind to the domain. The resolution is: add --baseURL when running Hugo locally.

./hugo_osx/hugo server --baseURL http://127.0.0.1

4. .Pages or .Site.RegularPages

Since .Pages contains the urls of tag/category page, I prefer to use .Site.RegularPages for sitemap/robots.txt.

5. structured-data

Following Google Docs for structured-data.

Tools

6. Asset minimization

Update @ Mar-09-2019

With this feature, the resource will be minified for better performance

  1. Location of the static resource

    Moving the static resource to the folder: assets. You can check the theme repository as an example.

  2. The way to call the resource

    resources.Get will be used instead of linking the resource directly. Here is the sample:

    <!-- Custom CSS -->
    {{ $huxcss := resources.Get "css/hux-blog.css" }}
    {{ $huxstyle := $huxcss | resources.Minify }}
    <!-- JavaScript -->
    {{ $jqueryjs := resources.Get "js/jquery.js" }}
    {{ $jqueryscript := $jqueryjs | resources.Minify }}
    <script src="{{ $jqueryscript.Permalink }}"></script>

Hugo-Customization


donation

Scan the QR code using WeChat

comments powered by Disqus