Re: My create article script

Published on at meta , techie , 2 mins.

In my case, using “hugo” to generate my web and capsule, I can leverage its nice templating system for new content called archetypes. This system allows you to have templates that will be used by the “hugo new” subcommand. Just to save some keystrokes I have a couple extra wrapping functions on my shell that include the logic for the date and location of the file:

$ grep hugo-new .zshrc 
function hugo-new-post { hugo new posts/$(date +%Y)/$(date --iso)-$ }
function hugo-new-update { hugo new posts/$(date +%Y)/$(date +%Y-%m).md --kind update }

So I have one function to generate posts with a default template and another to produce entries for my update category. The former calls the “hugo new” subcommand storing the file in the year folder, using the passed parameter as file name with the date prepended in ISO format. The latter does not need any parameter, it just uses the date.

For example, today I run:

$ hugo-new-post new-article
Content "/home/j/src/personal/" created

And that generated the file has the following content:

$ cat content/posts/2023/

title: "2023 04 16 New Article"
date: 2023-04-16T20:16:00+02:00
languages: [ 'english' ]
categories: [ 'update' ]
outputs: ['html', 'md']
description: >

The markdown file with the frontmatter is ready to start writing. After editing the title, since I am posting this just for the capsule, the “description” and “images” properties are not necessary and I removed “html” from the “outputs” property as well.

And that’s it. I will leave for another occasion to describe how my website and capsule are generated with Hugo.