As I’ve been migrating this website from Wordpress, I’ve been manually creating folder structure in VS Code and manually filling in front matter. It’s been painful!
After a good holiday, I decided there must be a better way so this is just my reminder on how I do it for my site:
Create a Post with Current Date in YYYY/MM/DD Format
hugo new posts/$(date +"%Y/%m/%d")/my-post-slug/index.md
Complete Example:
For a post titled “How I Quickly Make a New Hugo Post”, the command would be:
hugo new posts/$(date +"%Y/%m/%d")/how-i-quickly-make-a-new-hugo-post/index.md
This command will:
- Use
$(date +"%Y/%m/%d")to get the four-digit year (YYYY), month (MM), and day (DD). - Replace
my-post-slugwith the desired slug for the post (how-i-quickly-make-a-new-hugo-post). - Create an
index.mdfile inside a directory that follows the structureYYYY/MM/DD/slug.
Example output if today is October 12, 2024:
The command will create the following directory structure:
content/
└── posts/
└── 2024/
└── 10/
└── 12/
└── how-i-quickly-make-a-new-hugo-post/
└── index.md
Front Matter
The index.md file will include automatic front matter like this:
---
title: "How I Quickly Make a New Hugo Post"
date: 2024-10-12T15:30:00+00:00
draft: true
---