I like hugo, its easy to work with and blazing fast!
This post is just to document a few changes I recently did with my website and some notes for myself. Kind of a meta post really.
Improve iframe loading for faster page load
For a static site, almost instant page load is expected, and should be verified by lighthouse as such.
I attached an iframe to share code/result for
one of the blog posts
and that was slowing down the page load significantly. It pulls in stuff from the third party and it loads the amount of code it needs to load.
The cause was simple to diagnose really. Page was not loaded till I fetched all that extra js stuff. The fix was pretty simple as well. I added loading="lazy" to the iframe.
Nothing new, just that I basically forgot to add that there in the first place.
Style your quote and text blocks
Since I use a theme, the standard quote looks hella fancy!
> This is a standard quote
appears to be
This is a standard quote
But this is not enough! I added block styling that could render a standard set of text blocks like below -
Render Hooks allow custom templates to override markdown rendering functionality.
Hugo docs1
Let’s take a peek under the hood.
Image handling and adding a caption
I render a gif for
one of my blog posts
, and I wanted to figure out how to add caption to it, and to images in general.
I have render-image.html set up as a standard code.
It just added a different flavor and allowed me to learn a few new image related html components like
<figure>
and
<figcaption>
that I didn’t know existed before.
Here, the figcaption element handles caption for the rendered image.
Are you motivated by this caption?
Handling both local and remote link rendering
Along with images, we also have a render-link.html in our code.
// /layouts/_default/_markup/render-link.html
{{ $link := .Destination }}
{{ $isRemote := strings.HasPrefix $link "http" }}
{{- if not $isRemote -}}
{{ $url := urls.Parse .Destination }}
{{- if $url.Path -}}
{{ $fragment := "" }}
{{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
{{- with .Page.GetPage $url.Path }}{{ $link = printf "%s%s" .RelPermalink $fragment }}{{ end }}{{ end -}}
{{- end -}}
{{ .Text | safeHTML }}
and then I can write something like
[markdown render hooks](https://gohugo.io/templates/render-hooks/ 'Link to render hooks documentation')