TFK-Blog/new_article.sh
2020-06-01 00:31:13 +02:00

45 lines
993 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, hopefully in the chosen editor
if [ -n "$EDITOR" ]; then
$EDITOR content/articles/"$filename"
fi