10.8 Global Page Resources in the assets/ Directory

Right, let’s talk about your assets/ directory. This isn’t just a junk drawer for your random files; it’s a meticulously organized, pre-compiled treasure chest. Think of it as your project’s VIP lounge. Files in here get special treatment: they’re bundled directly into your final application, untouched by the usual processing that other files (like those in lib/ or static/) might go through. Their names are hashed for cache-busting glory, and their original folder structure is (mostly) respected. It’s the first place you should reach for when you need an image, a font, a PDF, or any other static resource that’s core to your pages.

10.7 Resource Metadata: Titles, Names, and Params

Right, let’s talk about the little nametags and sticky notes you can slap onto your pages. This isn’t just bureaucratic nonsense; this is how you tell Hugo what a page is, so it can do clever things with it later. We’re talking about the metadata that lives at the top of your .md files in what’s called the “front matter.” This is the control panel for your content. The Front Matter Formats: YAML, TOML, or JSON. Pick Your Poison. Hugo is a polyglot and supports three formats for this data. YAML is the default and what you’ll see in most examples because it’s relatively human-friendly. TOML is a bit more explicit (which some people love), and JSON is, well, JSON. The choice is yours, but consistency is key. Don’t be that person with a mix of all three; your future self will hate you.

10.6 Applying Image Filters: Blur, Grayscale, Overlay

Right, let’s talk about making your images less… well, boring. Or too busy. Or just plain weird. Image filters are the digital equivalent of slapping a filter on your vacation photos, except here we’re doing it with code, which is infinitely cooler and gives you way more control. We’re going to manipulate the very pixels themselves. Don’t worry, it’s less scary than it sounds. The core idea is simple: you take the raw pixel data from an image—usually an array of Color objects or a memory buffer—and you run each pixel through a function to transform it. A blur function might average a pixel with its neighbors. A grayscale function will crush its vibrant color into a shade of gray. It’s pixel alchemy.

10.5 Responsive Images: srcset Generation

Right, let’s talk about responsive images. You’ve been here before: you write a nice <img src="hero.jpg">, it looks perfect on your retina MacBook Pro, and then you get an angry email from someone on a spotty 3G connection whose phone just downloaded a 4MB file meant for a desktop. We’ve all been that villain. The goal is simple: serve the right image to the right device. The implementation, well, the W3C committee had a few cups of coffee and got thorough.

10.4 Converting to WebP and AVIF

Right, let’s talk about making your images stop clogging the internet’s pipes. You’ve got your PNGs and JPEGs, the old warhorses. They work. They’re also, by modern standards, hilariously inefficient. Serving a 2MB JPEG in 2023 is like showing up to a drone race with a carrier pigeon—it gets the job done, but everyone is judging you. We’re converting those hefty files to WebP and AVIF. Why both? Because while WebP is the established, widely-supported champion, AVIF is the new kid on the block who’s somehow even better at compression. Your goal is to serve AVIF to browsers that understand it (they’ll thank you with blazing fast loads) and provide WebP as a solid fallback for everyone else. The process isn’t magic, it’s just a bit of command-line (or script) wrangling.

10.3 Image Processing: Resize, Crop, Fit, Fill

Right, let’s talk about making your images behave. You’ve got this beautiful, massive 6000x4000 pixel photo from your fancy camera, and you need to shoehorn it into a 300x300 pixel spot in your layout. You can’t just slap it in there and hope for the best. The browser will do it, but it’ll look terrible, slow your site to a crawl, and your users on mobile data plans will personally curse your name. We’re better than that. We’re going to tell the browser exactly how to handle this, and we’re going to do it with a few key tools: resize, crop, fit, and fill.

10.2 Accessing Resources in Templates: .Resources.Match and .Resources.Get

Right, let’s talk about finding your stuff. You’ve dumped a bunch of images, CSS, and JavaScript files into your assets directory, and Hugo has faithfully processed them. Now you need to pull them into your templates. This is where .Resources gets off the bench, but it’s not as straightforward as you might hope. Hugo, in its infinite wisdom, decided that slapping a simple resources/images/cat.jpg path into your template would be too easy. Instead, we have a slightly more arcane, but ultimately more powerful, system.

10.1 Page Resources: Files in a Leaf Bundle

Alright, let’s talk about stuffing your site with files. You’ve got your content in Markdown, but a website isn’t made of words alone. You need images, PDFs, maybe a weird favicon.ico you made in a fit of inspiration at 2 AM. This is where Page Resources come in. Think of a Leaf Bundle as a self-contained folder for each of your pages. It’s not just the index.md file; it’s everything that goes with that page. Hugo’s genius here is its brutal, beautiful simplicity: any file you drop into the same directory as your index.md (or _index.md for sections) becomes a page resource for that page. Hugo automatically knows about it, can process it, and, crucially, can link to it.

— joke —

...