OrbitalMartian


Testing New Script

📕 304 words ⏳ 2 min.

A little while ago, Matt (famous from The Linux Cast) wrote a blost on his personal blog about his new blog script, which I have wanted to do for a while. SO what do I do, I copy his script and start editing it to work with my setup.

Here’s what I’ve got so far.

#!/bin/bash

# This script is to create a new blost file from a template.
# By OrbitalMartian
# Stolen from Matthew Webber (The Linux Cast)

# Check if a filename argument is provided
if [ -z "$1" ]; then
  echo "Usage: $0 <filename>"
  exit 1
fi


CURRENT_DATE=$(date +%Y-%m-%d)

BASE_DIR="$HOME/git/my-website/_posts/"

# Get the desired filename from the first argument
# Convert filename to a human-readable title (e.g., "my-new-post" becomes "My New Post")
# This took me forever. I hate awk. I love awk. I'm terribe at awk. And sed.
RAW_FILENAME="$CURRENT_DATE-$1"
TITLE=$(echo "$RAW_FILENAME" | sed 's/[_-]/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1')

FILENAME="$RAW_FILENAME.md"

FULL_PATH="$FILENAME"

# Create the front matter content
FRONT_MATTER="---\ntitle: $TITLE\ndate: $CURRENT_DATE\ndescription: \"\"\n---\n\n"

# Write the front matter to the new markdown file
echo -e "$FRONT_MATTER" > "_posts/$FULL_PATH"

echo "Markdown file created successfully with front matter at: $FULL_PATH"

I’m looking forward to working on this more.

Have a good one, BYEEE!!!


Comments

If you have something to say, leave a comment, or contact me ✉️ instead