Hugo now has the ability to do image resizing, cropping, quality-changing, etc (hooray!) - so how do we use it? In this post we take a look at how to resize images automatically using Hugo. There’s a few different ways to achieve this, depending on what you’re trying to do.
In a Theme - “I want to make thumbnails!”
You might run a blog, which on the home page has a list of your blog posts. And lets say you want to show a thumbnail image for each of your posts. This is the scenario we’ll be looking into here.
Important! Make sure your images are not stored in the /static/ folder
In our example, our theme displays the lists of posts in layouts/_default/summary.html
It looks a little like this (I’ve simplified it a bit):
In our example, each of our posts have featured_image in the properties of the markdown file which was can use to know which is the “primary” image of the page. We can then add our images to this summary file by using resources.Get to get the photos.
The line $image.Fill "200x200 q100 Center" can be changed, as we’re making an image with 200px width and 200px height, at 100 quality (crop to the center).
If we sprinkle on some final css style to tidy things up:
Edd is a PHP and Go developer who enjoys blogging about his experiences, mostly about creating and coding new things he's working on and is a big beliver in open-source and Linux.
Markdown for Hugo: Cheatsheet
–
This is designed to be a ‘cheatsheet’ to help you find the syntax you need quickly for creating markdown content on Hugo sites.
Code Block 1 2 3 4 5 ```css body { background: red; } ``` To define a code block, wrap the code in backticks like: `
Three of them, and you can define the code language after the first set, like we’ve said the above code is css.
Hide a Page in Hugo
–
Option 1: Draft The simplest way to hide a page when using Hugo is probably to set the post as a draft. This way, you still have the content ready to go for when you need it.
To hide a page by setting it as draft, so our drafts page:
Set Post as Draft Tutorial Option 2: Hide from Posts List You still want the page to be visible, but you don’t want to show it your blog posts list?
Show Related Posts in Hugo
–
Hugo is a great tool for blogging, creating quick and automated posts. As part of a blog, you will sometimes want to show related articles and posts to the one you’re reading. This is what this post sets out to achieve.
We can make this in Hugo easily if we are using it’s tags structure. With this in mind, you’ll need to be listing tags within your markdown for this to work.