Since I migrated this blog from Jekyll to Hugo, I want to try all the features provided by Hugo. One of the features is image processing. It could help me to develop a mobile-friendly blog. An image processing might help you, who read these contents from a smartphone which might have a slow internet connection to load images faster.
Though I developed this blog as minimal as possible, processing an image might be a problem. That’s where Hugo’s feature helps me to create a solution for this problem. In this article, you will learn to implement image processing using Hugo.
Shortcodes
Shortcodes is one of Hugo’s feature that could help to reuse the implementation of image processing easily. You may want to read more about shortcodes here. Now let’s create one.
You may create your shortcodes in your Hugo project at either one of these paths:
/layouts/shortcodes/<name>.html
/themes/<theme>/layouts/shortcodes/<name>.html
You can create the shortcodes at /layouts/shortcodes/img.html.
Let’s say you have put your images in Hugo’s assets directory. For example, you put your image file in /assets/img/testing/ehe.png, and then you can use it at your content like this:
1
{{< img src="/img/testing/ehe.png" alt="alt" >}}
At the moment, Hugo will not render it yet. Let’s adjust the shortcode so it will render the image.
Any kind of supports is greatly appreciated! Kindly support me via Bitcoin, Ko-fi, Trakteer, or just continue to read another content. You can write a response via Webmention and let me know the URL via Telegraph.