the mad geek

mad.geek.nz

... something something inspirational but not too trite should go here.

the mad geek

2 minutes read

https://pixabay.com/photos/newborn-hand-tiny-finger-4748020/

Picking up from last time we have a dirt simple hugo site; applying a simple theme, now we are going to maake a couple of customisations to the template.

Next in this series

Wild Assumptions

You have a Google Analytics (GA) account; ready to go.

Background Information

Partial templates have a specific lookup order (see the official documentation on Partials for details); tldr Hugo will look in the ‘local’ directory first then the theme directory e.g.

  1. layouts/partials/*<PARTIALNAME>.html
  2. themes/<THEME>/layouts/partials/*<PARTIALNAME>.html

Add GA to Head

So we are going to want to grab the element partial form the template that renders out the head element. For hugo-future-imperfect-slim this will be themes\hugo-future-imperfect-slim\layouts\partials\head.html. We want to grab that file and copy it to your local partials directory which in our case will be layouts\partials\head.html

With a local copy of the file that renders out the head element we want to hack that up a little and insert {{ template "_internal/google_analytics.html" . }} before the end of the head closure (</head>) e.g.

Figure 1

Update Configuration

Finally you will need to crack open your config.tomi file and set your googleAnalytics setting to your UA code; if the setting doesnt exist create it

Figure 2

Closing thoughts

Were barely scratchign the surface here; the main take away is that if you want to hack up some HTML look for a configuration setting that you can toggle in the tomi file; failing that identify the partial that is generating the HTML you want to change; make a copy in your local site; and slash and hack until it looks the way you want it.

Key resources are the Hugo Offical Documentation with the links below being ones that are usefull for the hack and slash.

Recent posts

Categories

About

cofee, software, photography, random stuff