Last active
February 9, 2024 22:29
-
-
Save twhite96/b68308a684fcf6a801feaf45509f8cad to your computer and use it in GitHub Desktop.
create a Jekyll post with a shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Put posts in the correct directory | |
directory="_posts" | |
# Prompt the user for the frontmatter | |
read -p "Enter the file title: " file_title | |
read -p "Enter the excerpt: " excerpt | |
read -p "Enter category(s): " category | |
IFS=',' read -p "Enter tags without quotes (comma-separated): " -a tags | |
read -p "Pin?: " featured | |
read -p "Include timestamp in filename? (y/n): " include_timestamp | |
file_name="$(date +"%Y-%m-%d")-${file_title}.md" | |
date_now="$(date +"%Y-%m-%d")" | |
# Check the boolean flag | |
if [[ "$include_timestamp" =~ ^[Yy] ]]; then | |
timestamp="_$(date +"%Y-%m-%d")" | |
else | |
timestamp="" | |
fi | |
if [[ "$featured" = Yy ]]; then | |
pin="true" | |
else | |
pin="false" | |
fi | |
# Create the frontmatter | |
frontmatter= | |
{ | |
echo "---" | |
echo "title: "$file_title"" | |
echo "date: "$date_now"" | |
echo "excerpt: "$excerpt"" | |
echo "tags: "[${tags[@]}]"" | |
echo "category: "[$category]"" | |
echo "pin: $featured" | |
echo "---" | |
} > "$file_name" | |
# Create the directory if it doesn't exist | |
# mkdir -p "$directory" | |
# Navigate to the directory | |
cd "$directory" | |
# Create the file and write content to it | |
echo "$frontmatter" > "$file_name" | |
# Display the created filename | |
echo "Post '$file_name' created with content in '$directory'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment