Jekyll Date Strings
For my first serious post, why not one I’ll probably constantly refer to myself every time I need to make a post?
Jekyll post filenames use the same format as the result of the command date -I
. Date strings (at least as used with Chirpy) have the same format as date --rfc-3339='seconds'
.
So I made this post with the simple one-liner, date --rfc-3339='seconds' > _posts/$(date -I)-JEKYLL-DATES.md
. Then I just have to fill in the Front Matter around the date string and away we go. As I write this, I feel I can probably write a better script which templates that too. So, here’s that bash script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# Get the title from the first argument
title="$1"
# Generate a slug from the title, replacing spaces with hyphens
slug="${title// /-}"
# Create the filename with the date and slug
filename="_posts/$(date -I)-${slug}.md"
# Write the front matter, including the title and date
cat << EOF > "$filename"
---
title: $title
date: $(date --rfc-3339='seconds')
categories: []
tags: []
---
EOF
echo "Jekyll post created at: $filename"
This post is licensed under CC BY 4.0 by the author.