www-gem words

Using a blog template

Published on

hugo The repetitive part of creating a blog post is completing the frontmatter, but this can be simplified using automation.
All you need to pre-populate your post frontmatters is a simple blog.md template in your achetypes theme folder.

Here is a very basic one to get you started:

+++
title = ""
url = "/{{ replace .Name "-" " " | title }}/"
date = "{{ .Date }}"
tags = [{{ range $name, $taxonomy := .Site.Taxonomies.tags }}"{{ printf "%s" $name}}"{{ end }}]
series = [{{ range $name, $taxonomy := .Site.Taxonomies.series }}"{{ printf "%s" $name }}"{{ end }}]
+++

Executing the command hugo new blog/post_name.md will create a blog post in your blog directory with the above url field changed to /post_name/

Let’s see what the rest of the code is doing:



More food for thoughts? Check other posts about: #Hugo


Thanks for your read. Hope it's been useful to you.


Interact with this post using Mastodon or

Comment on wwwgem's post

Copy and paste this URL into the search field of your favourite Fediverse app or the web interface of your Mastodon server.

✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈