Hugo Usage
Using Notices functionality within this theme
The "Notices" shortcode enables you to call out pieces of information - sidebars, warnings, tips, etc.
To create a notice on a page, you can use the notice
shortcode.
You use the notice
shortcode, with the first parameter being one of note
, info
, tip
, and warning
. Then add a title for your
note in quotes as the second parameter. The inner body of the note can be whatever markdown you want to create.
The following shortcode syntax within a markdown doc:
1{{% notice note "Note" %}}
2This is a standard "note" style.
3{{% /notice %}}
will render as:
This is a standard "note" style.
The other three variants follow.
Here is the "info" style.
Here is a "tip" variant of a notice.
Here is the "warning" flavor of a notice.
Also note that the content of a notice can contain anything you could put on a normal page - as shown below:
This is a notice that has a lot of various kinds of content in it.
- Here is a bulleted list
- With more than one bullet
- And even more than one level
Code blocks are fine here, too....
1public void SayHello()
2{
3 Console.WriteLine("Hello, world!");
4}
If you're using VS Code for your editing, copy the .vscode\clarity.code-snippets
file into a .vscode
root folder on your repo. This will enable you to type
note
then <tab>
then choose with up/down arrows which flavor notice you want, then <tab>
again to provide a title, then <tab>
to add your content!
To use the snippet, you need to first enable quickSuggestions for Markdown (one time only):
- Go to
Preferences->Settings
then search forquickSuggestions
- Follow the link to Edit in settings.json
- Toward the bottom of the file, paste in the following JSON:
1"[markdown]": {
2 "editor.quickSuggestions": true
3 }
- Close and save the settings.
Emoji can be enabled in a Hugo project in a number of ways.
The emojify
function can be called directly in templates or Inline Shortcodes.
To enable emoji globally, set enableEmoji
to true
in your site's configuration and then you can type emoji shorthand codes directly in content files; e.g.
π :see_no_evil:
π :hear_no_evil:
π :speak_no_evil:
The Emoji cheat sheet is a useful reference for emoji shorthand codes.
N.B. The above steps enable Unicode Standard emoji characters and sequences in Hugo, however the rendering of these glyphs depends on the browser and the platform. To style the emoji you can either use a third party emoji font or a font stack; e.g.
1.emoji {
2 font-family: Apple Color Emoji, Segoe UI Emoji, NotoColorEmoji, Segoe UI Symbol, Android Emoji, EmojiSymbols;
3}
Mathematical notation in a Hugo project can be enabled by using third party JavaScript libraries.
In this example we will be using KaTeX
- Create a partial under
/layouts/partials/math.html
- Within this partial reference the Auto-render Extension or host these scripts locally.
- Include the partial in your templates like so:
1{{ if or .Params.math .Site.Params.math }}
2{{ partial "math.html" . }}
3{{ end }}
- To enable KaTex globally set the parameter
math
totrue
in a project's configuration - To enable KaTex on a per page basis include the parameter
math: true
in content files
Note: Use the online reference of Supported TeX Functions
Examples
Block math: $$ \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } } $$
This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme.
Headings
The following HTML <h1>
β<h6>
elements represent six levels of section headings. <h1>
is the highest section level while <h6>
is the lowest.
H1
H2
H3
H4
H5
H6
Paragraph
Xerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum rerum idem sintibus eiur? Quianimin porecus evelectur, cum que nis nust voloribus ratem aut omnimi, sitatur? Quiatem. Nam, omnis sum am facea corem alique molestrunt et eos evelece arcillit ut aut eos eos nus, sin conecerem erum fuga. Ri oditatquam, ad quibus unda veliamenimin cusam et facea ipsamus es exerum sitate dolores editium rerore eost, temped molorro ratiae volorro te reribus dolorer sperchicium faceata tiustia prat.
Itatur? Quiatae cullecum rem ent aut odis in re eossequodi nonsequ idebis ne sapicia is sinveli squiatum, core et que aut hariosam ex eat.
Images
Local image, alt text as caption
The following image is located within the Hugo site. Because it has alt text but no title text, the caption is generated by the alt text.
Remote image, specified caption
The following image is loaded from a remote URL. The alt text is the same (for screen readers and in cases when the image doesn't load) but because a separate title is provided, the title is used for the caption:
Image with alt text and no caption
Alt text is always recommended for SEO, accessibility and in cases when images don't load. However, you don't necessarily always want an image to have a caption. In that case, use a title with one space:
Blockquotes
The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a footer
or cite
element, and optionally with in-line changes such as annotations and abbreviations.
Blockquote without attribution
Tiam, ad mint andaepu dandae nostion secatur sequo quae. Note that you can use Markdown syntax within a blockquote.
Blockquote with attribution
Don't communicate by sharing memory, share memory by communicating.
β Rob Pike1
Tables
Tables aren't part of the core Markdown spec, but Hugo supports supports them out-of-the-box.
Name | Age |
---|---|
Bob | 27 |
Alice | 23 |
Inline Markdown within tables
Italics | Bold | Code |
---|---|---|
italics | bold | code |
Code Blocks
Code block with backticks
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>Example HTML5 Document</title>
6</head>
7<body>
8 <p>Test</p>
9</body>
10<!-- this line is extraneous 2Error from server (Forbidden): deployments.apps is forbidden: User "chiptest" cannot create resource "deployments" in API group "apps" in the namespace "default" -->
11</html>
Code block indented with four spaces
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example HTML5 Document</title>
</head>
<body>
<p>Test</p>
</body>
</html>
Code block with Hugo's internal highlight shortcode
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>Example HTML5 Document</title>
6</head>
7<body>
8 <p>Test</p>
9</body>
10</html>
List Types
Ordered List
- First item
- Second item
- Third item
Unordered List
- List item
- Another item
- And another item
Nested list
- Fruit
- Apple
- Orange
- Banana
- Dairy
- Milk
- Cheese
Other Elements β abbr, sub, sup, kbd, mark
GIF is a bitmap image format.
H2O
Xn + Yn = Zn
Press CTRL+ALT+Delete to end the session.
Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures.
Lorem est tota propiore conpellat pectoribus de pectora summo. Redit teque digerit hominumque toris verebor lumina non cervice subde tollit usus habet Arctonque, furores quas nec ferunt. Quoque montibus nunc caluere tempus inhospita parcite confusaque translucet patri vestro qui optatis lumine cognoscere flos nubis! Fronde ipsamque patulos Dryopen deorum.
- Exierant elisi ambit vivere dedere
- Duce pollice
- Eris modo
- Spargitque ferrea quos palude
Rursus nulli murmur; hastile inridet ut ab gravi sententia! Nomine potitus silentia flumen, sustinet placuit petis in dilapsa erat sunt. Atria tractus malis.
- Comas hunc haec pietate fetum procerum dixit
- Post torum vates letum Tiresia
- Flumen querellas
- Arcanaque montibus omnes
- Quidem et
Vagus elidunt
Mane refeci capiebant unda mulcebat
Victa caducifer, malo vulnere contra dicere aurato, ludit regale, voca! Retorsit colit est profanae esse virescere furit nec; iaculi matertera et visa est, viribus. Divesque creatis, tecta novat collumque vulnus est, parvas. Faces illo pepulere tempus adest. Tendit flamma, ab opes virum sustinet, sidus sequendo urbis.
Iubar proles corpore raptos vero auctor imperium; sed et huic: manus caeli Lelegas tu lux. Verbis obstitit intus oblectamina fixis linguisque ausus sperare Echionides cornuaque tenent clausit possit. Omnia putatur. Praeteritae refert ausus; ferebant e primus lora nutat, vici quae mea ipse. Et iter nil spectatae vulnus haerentia iuste et exercebat, sui et.
Eurytus Hector, materna ipsumque ut Politen, nec, nate, ignari, vernum cohaesit sequitur. Vel mitis temploque vocatus, inque alis, oculos nomen non silvis corpore coniunx ne displicet illa. Crescunt non unus, vidit visa quantum inmiti flumina mortis facto sic: undique a alios vincula sunt iactata abdita! Suspenderat ego fuit tendit: luna, ante urbem Propoetides parte.
Hugo ships with several Built-in Shortcodes for rich content, along with a Privacy Config and a set of Simple Shortcodes that enable static and no-JS versions of various social media embeds.
Instagram Simple Shortcode
YouTube Privacy Enhanced Shortcode
Twitter Simple Shortcode
Owl bet you'll lose this staring contest π¦ pic.twitter.com/eJh4f2zncC
— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021
See documentation https://gohugo.io/content-management/shortcodes/#tweet for more details
Vimeo Simple Shortcode
Page bundles are an optional way to organize page resources within Hugo.
You can opt-in to using page bundles in Hugo Clarity with usePageBundles
in your site configuration or in a page's front matter. Read more about usePageBundles
.
With page bundles, resources for a page or section, like images or attached files, live in the same directory as the content itself rather than in your static
directory.
Hugo Clarity supports the use of leaf bundles, which are any directories within the content
directory that contain an index.md
file. Hugo's documentation gives this example:
1content
2βββ about
3β βββ index.md
4βββ posts
5β βββ my-post
6β β βββ content1.md
7β β βββ content2.md
8β β βββ image1.jpg
9β β βββ image2.png
10β β βββ index.md
11β βββ my-other-post
12β Β Β βββ index.md
13β
14βββ another-section
15 βββ ..
16 Β Β βββ not-a-leaf-bundle
17 βββ ..
18 Β Β βββ another-leaf-bundle
19 Β Β βββ index.md
In the above example `content` directory, there are four leaf bundles:about: This leaf bundle is at the root level (directly under
content
directory) and has only theindex.md
.my-post: This leaf bundle has the
index.md
, two other content Markdown files and two image files. image1 is a page resource ofmy-post
and only available inmy-post/index.md
resources. image2 is a page resource ofmy-post
and only available inmy-post/index.md
resources.my-other-post: This leaf bundle has only the
index.md
.another-leaf-bundle: This leaf bundle is nested under couple of directories. This bundle also has only the
index.md
.The hierarchy depth at which a leaf bundle is created does not matter, as long as it is not inside another leaf bundle.
Advantages to using page bundles
The image below is part of the bundle of this page, and is located at content/post/bundle/building.png
. Because it's within this page's bundle, the markup for the image only has to specify the image's filename, building.png
.
If you ever change the name of the directory in which this Markdown file and the image reside, the reference to the image would not need to be updated.
In addition to more cleanly organizing your content and related assets, when using page bundles, Hugo Clarity will automatically generate markup for modern image formats, which are smaller in file size.
For instance, when you reference an image like building.png
, Hugo Clarity will check to see if the same image (based on filename) exists in WebP, AVIF or JXL formats. If you inspect the image above, you'll see a <source>
element for building.webp
, because that file is also present. Hugo Clarity will only include the markup if these images exist.
Browsers that support these formats and the <picture>
element will load them, while browsers that do not will fall-back to the default image. Read more about this process.
Finally, note that page assets can be further managed and refined within the page's front matter if you wish, and are not limited to images alone.
Disadvantages to using page bundles
Page resources in a bundle are only available to the page with which they are bundled β that means you can't include an image with one page and then reference it from another.
Images that are being used in multiple places are more appropriate for your Hugo assets
directory. Unlike files in the Hugo static
directory, files in the assets
directory can be run through Hugo Pipes, which includes image processing.