Synopsis
Here I provide an example of static website creation using the HUGO generator hosted with Github Pages, which is expected to be widely useful for professional purposes. Moreover, the general procedures and tips here should be hopefully useful for amateur HUGO users like me.
This work is licensed under CC BY-SA 4.0
Github Pages repository
- Create a new Github repository named
<user>.github.io
where<user>
is your Github username. By default, websitehttps://<user>.github.io
will load theindex.html
in the root of this repository. Even if this repository has private visibility, contents in this repository will still be publicly accessible via HTTP once your site is deployed. - By default, once you push to this repo, Github Pages will be automatically set up and your site will be deployed.
HUGO with the PaperMod theme
- Install HUGO following the official Installation guide. With this tutorial you do not need to install the GO interpreter. However,
git
is required for installation and upgrade of HUGO themes. - Once
hugo
is in your search path, create a new website directory under the working directory withhugo new site <site_dir> --format yaml
. Your website contents will be stored in<site_dir>
. - Change directory to
<site_dir>
and then run the following commands to install the PaperMod theme:git clone https://github.com/adityatelange/hugo-PaperMod themes/PaperMod --depth=1
. - By default,
hugo.yaml
is used as the single site generation configuration file. Refer to the PaperMod demo site configuration file and the PaperMod documentation for configuration details. - To create a new post, use
hugo new content post/<post_name>.md
. This will create a new markdown file for your new post atcontent/post/<post_name>.md
. If you have a customized template atarchetypes/post.md
, the new file will be filled accordingly (more detail below). - Personal preferences and tips are included in the next section below.
Optional functionalities
Here I include personal notes on functionalities used in my site.
Chroma-based syntax highlighting
HUGO provides Chroma as the default code highlighter, which performs server-side syntax highlighting of code fences and/or inlines. Once your website is built with hugo
or tested with hugo serve
, code styling is hardcoded in the HTML+CSS of your site.
Apart from Chroma, the PaperMod theme provides an alternative client-side highlighter Highlight.js. Follow the steps below to set-up Chroma highlighting properly. Refer to the PaperMod documentation for more information.
- Edit the configuration file
hugo.yaml
to disable Highlight.js and configure Chroma behavior. Refer to the HUGO highlighting documentation for details.
|
|
- Refer to the style gallery to choose your preferred style. Once the style is specified in the configuration file, generate the CSS class file. Create directories as needed.
|
|
- With this syntax highlighting should be enabled for code fences. You may explicitly specify syntax right after the starting triple backticks.
|
|
- Highlighting of inline code spans requires explicit usage of the built-in highlight shortcode. Refer to the HUGO forum post for details.
- To configure rendering of tabs in your code, put the following CSS code in your static files (e.g., creating a new CSS
assets/css/extended/tabwidth.css
):
|
|
- Some of the highlight settings can be set per code block, see an example below. Refer to the HUGO docs for more details. See an example below:
|
|
|
|
Client-side math typesetting with KaTeX
At this point, the easiest way for math typesetting is client-side rendering using either KaTeX or MathJax. For KaTeX-based typesetting see below or the PaperMod docs. The key point here is that we would like to load the KaTeX (with auto-render extension) only when required.
- Create a partial template in
layouts/partials/helpers/katex.html
. You may want to check KaTeX Auto-render extension page for version updates. You may also host the files in your Github Pages repository. Create directories as needed.
|
|
- If in-line equations are desired, add an additional script element to the partial created above:
|
|
- To load the KaTeX template in headers, add the following to
layouts/partials/extend_head.html
. Create the file if needed.
|
|
- To enable math rendering in a page, add parameter
math: true
to the front matter of the content file. To enable math rendering globally, add parametermath: true
to the configuration file. - Some examples below.
Inline math example (use single dollar sign $
): $log(\frac{I_0}{I})=A=\varepsilon l c$
Block math example (use double dollar sign $$
):
$$
\rho (x, t) = \frac{N}{\sqrt{4 \pi D t}}e^{-\frac{x^2}{4Dt}}
$$
Content template
HUGO archetypes are templates used for new content. Because posts are the typical content I put on my website, I created a post template at archetypes/post.md
. When new content is created with hugo new content post/.../new_post.md
, the template is evaluated for the new content.
For an example template, refer to the PaperMod docs.
Images
HUGO provides the following methods for working with images in a post.
- Markdown image which is part of the markdown standard implementation.
- HUGO built-in shortcode
figure
which is a wrapper of HTMLfigure
tag.
An example for markdown image:
|
|
An example for the figure
shortcode:
|
|
optional caption compatible with math typesetting when backslash escaped $a=\frac{b}{c}$
Note on resources path
One straightforward way for specifying path to the image is the absolute path (root being thecontent
folder of the HUGO project). Alternatively, you can use relative path directly if page bundle organization is used.