TFK-Blog/new_article.sh
trotFunky 32a4c73685 First setup of the blog
First article and about page
Flex theme setup with some corrections and using a PR for ToC
2020-05-31 23:01:22 +01:00

44 lines
964 B
Bash
Executable file

#!/bin/bash
# Add the metadata if the answer is not empty
# Usage:
# append_to_metadata file_name metadata_name
append_to_metadata() {
if [ $# -eq 2 ]; then
echo -n "$2 : "
read answer
if [ -n "$answer" ]; then
echo "$2: ""$answer" >> "content/articles/$1"
else
echo "Empty answer, nothing was appended"
fi
fi
}
echo -n "Filename : "
read filename
append_to_metadata "$filename" "Title"
append_to_metadata "$filename" "Date"
append_to_metadata "$filename" "Category"
append_to_metadata "$filename" "Tags"
append_to_metadata "$filename" "Lang"
append_to_metadata "$filename" "Slug"
append_to_metadata "$filename" "Summary"
echo -e "\n" >> content/articles/"$filename"
# Try to get the default editor from alternatives
EDITOR=${EDITOR:-$(update-alternatives --list editor | head -n1)}
# If not present set it to vi
EDITOR=${EDITOR:-vi}
# Open the newly created file, openfully in the chosen editor
$EDITOR content/articles/"$filename"