How I Create New Blog Posts
📆 2026-05-12 10:03
Running a gemini capsule is fun, but manually creating a new post folder, writing the boilerplate and remembering to add the "Back to my blog" link is something I dislike. So I wrote a small bash script to automate the process.
Before this script, creating a new post meant:
- making a new directory inside my blog folder
- converting the title into a URL-friendly folder name
- creating an index.gmi file
- adding the title
- adding the timestamp (and always had to search for the calendar emoji)
- adding navigation back to the blog index
Not difficult, just annoying! I know I could have just created YYYY-MM-DD-post-title.gmi but I like the structure "/blog/how-i-create-new-blog-posts/". Makes me feel like I have .htaccess :-D
The script: ./newpost
Now I run:
./newpost "How I Create New Blog Posts"
Or simply:
./newpost.sh
And the script asks me for a title interactively.
Screenshot: How I create a new blog post
It automatically:
- generates a lowercase slug from the title
- replaces spaces with hyphens
- removes unsupported characters - only a-z, A-Z and 0-9 allowed
- prevents duplicate hyphens
- creates the post directory
- creates a ready to edit index.gmi file
The generated structure looks like this:
gemini-content/blog/how-i-create-new-blog-posts/index.gmi
Default template for posts
Each new post starts with:
# Post Title (In this case "How I create new blog posts")
📆 YYYY-MM-DD HH:MM
Start writing here ...
=> /blog/ 🚶 Back to my blog
This gives me a consistent layout for every post. Also, the timestamp is generated automatically with a +1 hour offset, which is enough to write the post and make sure everything looks good. In case I don't finish the post in this 1 hour window I can just modify the date and time :-D.
After generating the file, the script asks:
Would you like to edit the post in vim? (yY/n):
If I answer y or Y, it immediately opens the new file in Vim. This saves another step and lets me jump directly into writing.
Gemini is simple. This is why I have no admin panel, no dashboard, no WYSIWYG editor, and no giant CMS like Wordpress. Just files, folders, and text.
This script keeps it simple also and removes repetitive commands.
The script
#!/usr/bin/env bash
# If not parameters ask for page title...
if [ -z "$1" ]; then
read -p "Post title: " POST_TITLE
else
POST_TITLE="$1"
fi
# Get the script path
SCRIPT_DIR=$(dirname "$(realpath "$0")")
# Create folder name by making everything lowercase, replacing spaces
# with hyphens, remove duplicate hyphens and also remove hyphens if
# they are first or last character
FOLDER_NAME=$(echo "$POST_TITLE" \
| tr '[:upper:]' '[:lower:]' \
| tr ' ' '-' \
| sed 's/[^a-z0-9-]//g' \
| sed 's/--*/-/g' \
| sed 's/^-//' \
| sed 's/-$//')
# Path should be in my blog directory which is relative to the SCRIPT_DIR
FOLDER_PATH="$SCRIPT_DIR/gemini-content/blog/$FOLDER_NAME"
# Create folder
mkdir -p $FOLDER_PATH
# 1 hour into the future
DATE_PLUS_HOUR=$(date -d "+1 hour" "+%Y-%m-%d %H:%M")
# Start creating the post template
# Post title with # at the beginning of the line - H1 and page title
echo "# $POST_TITLE" > "$FOLDER_PATH/index.gmi"
# Empty line
echo "" >> "$FOLDER_PATH/index.gmi"
# Insert date + 1 hour
echo "📆 $DATE_PLUS_HOUR" >> "$FOLDER_PATH/index.gmi"
#Empty line
echo "" >> "$FOLDER_PATH/index.gmi"
# Placeholder text
echo "Start writing here ..." >> "$FOLDER_PATH/index.gmi"
# Empty line
echo "" >> "$FOLDER_PATH/index.gmi"
# Back to my blog link
echo "=> /blog/ 🚶 Back to my blog" >> "$FOLDER_PATH/index.gmi"
# Confirmation
echo "Created post: '$POST_TITLE'."
echo ""
# Ask to open the new post in vim
read -p "Would you like to edit the post in vim? (yY/n): " edit
if [[ "$edit" == "y" || "$edit" == "Y" ]]; then
vim "$FOLDER_PATH/index.gmi"
fi
The script without comments in txt format
Feel free to use this script. Make sure to adapt it to your paths, blog structure and post template.
🚶 Back to my blog