15.9 Digest Functions: md5, sha256, base64Encode, base64Decode

Alright, let’s talk about making digital fingerprints and passing secret notes. In the world of Hugo, that’s the job of the crypto and encoding functions: md5, sha256, base64Encode, and base64Decode. These are your go-to tools for creating checksums, obscuring data in URLs, or working with basic encoding. They’re not for encrypting your secret diary—that’s a different conversation—but they are incredibly useful for the day-to-day grunt work of building a site.

15.8 File Functions: readFile, readDir, fileExists

Alright, let’s get our hands dirty with the filesystem. This is where Hugo stops being just a static site generator and starts feeling like a proper programming language. The readFile, readDir, and fileExists functions are your direct line to the raw content of your project. They are incredibly powerful, but with great power comes the great responsibility of not accidentally shipping your TODO.md file to production. The Workhorses: readFile and readDir Think of these as your cat and ls commands, but baked right into your templates. Their primary job is to read files from your project’s root, not from the built site’s public directory. This is a crucial distinction. You’re working with your source material.

15.7 Comparison: eq, ne, lt, le, gt, ge, and, or, not

Alright, let’s talk about making decisions. In Hugo-land, you’re not just describing content; you’re building logic to shape it. That’s where these comparison and logic functions come in. They’re the if/else statements in your template’s brain, and frankly, they’re a bit of a mixed bag. Some are brilliant in their simplicity, others will make you wonder what the designers were thinking that day. Let’s get into it. The Core Comparison Gang These are your workhorses: eq, ne, lt, le, gt, ge. They stand for equals, not equals, less than, less than or equal to, greater than, and greater than or equal to. You know, the classics.

15.6 Date Functions: now, dateFormat, time, duration

Right, let’s talk about dates and times. You’d think this would be straightforward, but it’s a surprisingly fertile ground for frustration. Hugo, thankfully, gives us a solid toolkit to wrestle this chaos into submission. We’re going to cover the core functions that let you get the current moment, format it beautifully, and calculate durations. Forget everything you know about JavaScript’s Date object; Hugo’s way is both simpler and, dare I say, more sensible.

15.5 URL Functions: absURL, relURL, urlize, anchorize

Right, let’s talk about making Hugo actually talk to the web. Because let’s be honest, a static site that can’t link to its own pages or format a URL correctly is about as useful as a chocolate teapot. Hugo’s URL functions are your toolkit for making sure that doesn’t happen. They’re the difference between a href="/about" that works on localhost and explodes when you deploy to a subdirectory, and one that just works, everywhere.

15.4 Type Conversion: int, float, string, jsonify, unmarshal

Right, let’s talk about making your data play nice with others. In any template, you’re constantly juggling types. Hugo pulls your data from all sorts of places—front matter, data files, site configurations—and it doesn’t always arrive in the format you need. That’s where this toolkit of conversion functions comes in. They’re your Swiss Army knife for politely, or sometimes forcefully, asking a value to be something else. The Basics: int, float, and string These are your workhorses. They do exactly what you’d expect, but with a few Hugo-specific quirks you need to know about.

15.3 Collection Functions: where, first, last, after, sort, shuffle, group

Right, let’s get our hands dirty with Hugo’s collection functions. These are your power tools for wrangling your content into submission. Think of them as the filters and sorters for your data—the logic that turns a messy pile of content into the exact list you need for your nav, your featured posts, or your “related articles” section. The most important thing to remember is that these functions don’t change your original collection. They return a new, filtered, or sorted version of it. This is a core Hugo principle: data transformation should be side-effect free. It keeps things predictable, which is something we can all get behind.

15.2 Math Functions: add, sub, mul, div, mod, math.Round

Right, let’s talk math. Not the soul-crushing calculus from your university days, but the simple, practical kind you need to wrangle numbers on your website. Hugo provides a basic arithmetic toolkit because, let’s be honest, sometimes you need to do more than just add two strings together. These functions are your first line of defense against static, lifeless numbers. The core operations are exactly what you’d expect: add, sub, mul, div, and mod. They do what they say on the tin. But here’s the first “gotcha” Hugo throws at you: their argument order is a bit… unconventional. You’d think sub 5 3 would give you 2, right? Nope. It gives you -2. Why? Because Hugo’s functions almost universally take their arguments in reverse Polish notation, or as I like to call it, “the argument order is backwards.”

15.1 String Functions: printf, lower, upper, title, trim, replace, truncate

Alright, let’s talk about text. Because let’s be honest, most of what you’re building with Hugo is just glorified text wrangling. You’re taking content written by humans (who are, famously, inconsistent) and trying to make it look presentable for other humans. It’s a messy job, but Hugo’s string functions are your first line of defense. These are the digital equivalent of a trusty multi-tool: not always glamorous, but absolutely essential for not looking like an amateur.

— joke —

...