2020-05-31 23:01:02 +01:00
|
|
|
#!/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
|
2020-10-03 00:45:33 +02:00
|
|
|
option="$(echo "$2" | tr '[:upper:]' '[:lower:]')"
|
2020-05-31 23:01:02 +01:00
|
|
|
if [ -n "$answer" ]; then
|
2020-10-03 00:45:33 +02:00
|
|
|
echo "$option = ""$answer" >> "content/articles/$1"
|
2020-05-31 23:01:02 +01:00
|
|
|
else
|
|
|
|
echo "Empty answer, nothing was appended"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
echo -n "Filename : "
|
|
|
|
read filename
|
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
echo "+++" > content/articles/"$filename"
|
|
|
|
|
|
|
|
echo "The title must be between quotes"
|
|
|
|
|
2020-05-31 23:01:02 +01:00
|
|
|
append_to_metadata "$filename" "Title"
|
|
|
|
|
|
|
|
append_to_metadata "$filename" "Date"
|
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
append_to_metadata "$filename" "Draft"
|
2020-05-31 23:01:02 +01:00
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
append_to_metadata "$filename" "Slug"
|
2020-05-31 23:01:02 +01:00
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
echo "[taxonomies]" >> content/articles/"$filename"
|
2020-05-31 23:01:02 +01:00
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
echo "Categories and tag must be formatted as follows : [\"element1\",\"element2\"]"
|
|
|
|
|
|
|
|
append_to_metadata "$filename" "Categories"
|
2020-05-31 23:01:02 +01:00
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
append_to_metadata "$filename" "Tags"
|
2020-05-31 23:01:02 +01:00
|
|
|
|
2020-10-03 00:45:33 +02:00
|
|
|
echo -e "+++\n\n" >> content/articles/"$filename"
|
2020-05-31 23:01:02 +01:00
|
|
|
|
|
|
|
# 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}
|
|
|
|
|
2020-06-01 00:31:13 +02:00
|
|
|
# Open the newly created file, hopefully in the chosen editor
|
|
|
|
if [ -n "$EDITOR" ]; then
|
|
|
|
$EDITOR content/articles/"$filename"
|
|
|
|
fi
|