Advanced Hugo tips
It's hard sometimes to find what is really important. Here are some useful examples you will need to create a good Hugo site. You will find related files in vendor/Andygrond/hugonette/doc/hugo
folder of the Hugonette
project. You can also download it from GitHub.
Site config
By default /config.toml
or /config.yaml
is a project configuration file. But more convenient is to use /config
folder. Define there your environments:
development
is for Hugo web server:hugo server
staging
is for local generation to Hugonette project:hugo -e staging
_default
is for production ready generation:hugo
In the exaple files you will find debug
variable definition, which is used below.
Sass CSS extension
All .scss
files gather in /assets
folder. Assuming you use main.scss
as the main file, add following code to the partials/head.html
This configuration code prepares CSS file with SourceMap for debugging, or compresses it for production, and adds fingerprint to avoid using old version from cache.
Please be aware: if you want to customize any .scss
file, you must move from theme to project not only this file, but also a file which contains its @import
declaration.
JS library
List all needed JavaScript libraries in the configuration /config/_default/params.yaml
Move the files to /assets/js
folder. Use this code to place all .js
in the partial js.html
The code appends all files into the $js
array and next does the right action according to debug
variable. In this example, for debugging purposes every file will be published in separate <script>
line. For production all files are packed in one file, minified and fingerprinted.
Menu
You can manage a menu by JavaScript, Latte template or Hugo. Any way has its own pros and cons. You can even mix the techniques to achieve what you need. Now quick tutorial for Hugo.
Define menu variables in /config/_default/params.yaml
You should define native menu ID and/or submenu ID in the front matter of every page.
Then refer to this data in your partial:
Last updated