35 lines
1.4 KiB
Bash
Executable file
35 lines
1.4 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
check_existing_file() {
|
|
if [ -e "$1/$2.md" ]; then
|
|
echo "Error: A file with the name '$2.md' already exists in the '$1' directory."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
read -p "Enter the title for the new blog post: " title
|
|
kebab_title=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
|
|
|
|
check_existing_file "src/blog" "$kebab_title"
|
|
check_existing_file "src/feed" "$kebab_title"
|
|
|
|
# Create a new blog post file with the appropriate frontmatter and content
|
|
echo "---" > "src/blog/$kebab_title.md"
|
|
echo "title: $title" >> "src/blog/$kebab_title.md"
|
|
echo "layout: article.njk" >> "src/blog/$kebab_title.md"
|
|
echo "date: git Last Modified" >> "src/blog/$kebab_title.md"
|
|
echo "tags: post" >> "src/blog/$kebab_title.md"
|
|
echo "excerpt: Placeholder text for excerpt" >> "src/blog/$kebab_title.md"
|
|
echo "---" >> "src/blog/$kebab_title.md"
|
|
echo -e "\nThis is the content of the new blog post." >> "src/blog/$kebab_title.md"
|
|
|
|
# Create a new feed file with the appropriate frontmatter
|
|
echo "---" > "src/feed/$kebab_title.md"
|
|
echo "title: $title" >> "src/feed/$kebab_title.md"
|
|
echo "relativeUrl: /blog/$kebab_title" >> "src/feed/$kebab_title.md"
|
|
echo "date: git Created" >> "src/feed/$kebab_title.md"
|
|
echo "tags: feed" >> "src/feed/$kebab_title.md"
|
|
echo "---" >> "src/feed/$kebab_title.md"
|
|
echo -e "\nThis is the content of the new blog post." >> "src/feed/$kebab_title.md"
|
|
|
|
$EDITOR "src/blog/$kebab_title.md"
|