9.6 Using hugo new Effectively in Your Workflow

Right, let’s talk about hugo new. This is one of those commands that seems trivial until you realize it’s the entire foundation for not driving yourself insane. It’s Hugo’s way of saying, “Don’t start from an empty file, you maniac. Start from a smart empty file.” Think of it as your personal content factory. You give it a blueprint (an archetype), and it stamps out a new page with all the right front matter fields already filled in, or at least politely suggested. This isn’t just about convenience; it’s about consistency. It ensures your blog/ posts all have a description field and your work/case-studies/ all have a client_name field. Without it, you’re just raw-dogging YAML in a text editor, and I respect you too much to let you do that. How It Actually Works (The Magic Trick Explained) You run hugo new content/path/to/your-page.md. Hugo isn’t just creating a folder and a file. It’s much smarter than that. It looks at that path and tries to match it to a content type. It does this by looking for a directory inside your content/ folder that matches the first part of the path. So, if you run: hugo new blog/2024/my-amazing-post.md Hugo sees blog/ and thinks, “Aha! This is a ‘blog’ type of content.” It then goes looking for a blueprint specifically for the ‘blog’ type, which is a file called archetypes/blog.md. If it finds one, it uses that as the template. If it doesn’t, it falls back to the default archetypes/default.md. Let’s make this concrete. Say you have this archetype at archetypes/blog.md: --- title: "{{ replace .File.ContentBaseName "-" " " | title }}" date: {{ .Date }} draft: true description: "" categories: [] tags: [] --- Summary intro goes here. Your brilliant content here. When you run that hugo new command, it creates content/blog/2024/my-amazing-post.md and populates it with:

9.5 Template Variables in Archetypes: .Date, .Name, .Type

Alright, let’s get our hands dirty with template variables. Think of these as the mad-libs of the Hugo world. You provide the template structure, and Hugo fills in the blanks with actual data from the front matter of your content files. It’s how a generic post.md file becomes a specific, published article about, say, “The Care and Feeding of Your New Robot Dog.” The big three you’ll live and die by are .Date, .Name, and .Type. They seem simple, and mostly they are, but they have their quirks. Let’s break them down.

9.4 Directory Archetypes: Bundled Content with Resources

Alright, let’s talk about Directory Archetypes. This is where Hugo stops being a simple static site generator and starts feeling like a proper, grown-up content management system. The idea is deliciously simple: stop thinking in terms of individual files and start thinking in terms of bundles of content and resources. Think of it like this. You have a “thing” on your site—let’s say a project, or a product, or a person. That “thing” isn’t just a blob of text; it’s a title, a description, some body copy, and it has assets: a hero image, a PDF spec sheet, a gallery of screenshots, maybe even a custom CSS or JavaScript file. In a traditional setup, you’d have your project.md in one folder and your images/project/ in another, and keeping them in sync is a manual, error-prone nightmare.

9.3 Section-Specific Archetypes

Now, let’s get into the real meat of the matter: section-specific archetypes. These aren’t just page templates; they’re the DNA for the individual parts of your site. Think of them as the specialized tools in your workshop. You wouldn’t use a sledgehammer to drive a finishing nail, and you shouldn’t use a generic single.php template for everything. This is where WordPress’s template hierarchy earns its keep, and where you start to look like a genuine theme wizard.

9.2 The default.md Archetype

Alright, let’s talk about the default.md archetype. This isn’t just an archetype; it’s the default archetype. It’s the one Hugo uses when it can’t find a more specific template for your content. Think of it as the trusty, slightly battered toolbox you grab for every job when you don’t need the specialized laser-calibrated screwdriver from the blog-post archetype. Its primary job is to set the baseline, the absolute minimum front matter you should have for a piece of content. And front matter, in case you’re new here, is the metadata block at the top of your content files (YAML, TOML, JSON) that tells Hugo everything it needs to know about your page before it even starts rendering the content itself.

9.1 What Archetypes Do: Bootstrapping Front Matter for New Content

Right, let’s talk about the part of this system that actually saves you from your own forgetfulness: bootstrapping front matter. You know, that YAML block at the top of every Markdown file that looks like it was designed to torture people who forget to close their quotes. Manually typing that out for every new blog post or documentation page is a special kind of hell. It’s repetitive, error-prone, and frankly, beneath you. This is where Archetypes flex their first and most glorious muscle.

— joke —

...