44 lines
1.3 KiB
Bash
Executable file
44 lines
1.3 KiB
Bash
Executable file
#!/bin/sh -eu
|
|
|
|
path_to_rendered_md="${1:-rendered.md}"
|
|
if [ -z "${path_to_rendered_md}" ] || [ ! -f "${path_to_rendered_md}" ]; then
|
|
cat >> /dev/stderr <<-EOM
|
|
Please call as ./new_post.sh rendered.md
|
|
EOM
|
|
exit 1
|
|
fi
|
|
|
|
# Get the number for the new issue
|
|
today="$(date +"%Y-%m-%d")"
|
|
publications="$(find posts/ -maxdepth 1 -mindepth 1 -type d | sort | grep -v "${today}")"
|
|
last_date="$(echo "${publications}" | tail -n 1 | cut -d '/' -f 2)"
|
|
current_number="$(echo "${publications}" | grep -v "${today}" | wc -l)"
|
|
next_number="$(($current_number+1))"
|
|
|
|
printf "\nGenerate eXOfàsia ~${next_number} ..."
|
|
|
|
# Build path of the post
|
|
echo "${today}"
|
|
|
|
year=$(date +"%Y")
|
|
month=$(date +"%m")
|
|
path="./posts/${today}"
|
|
|
|
printf "\n\nCreate directory: $path"
|
|
mkdir -p $path
|
|
|
|
markdown=$path/rendered.md
|
|
printf "\nPlacing and patching rendered.md: $markdown"
|
|
sed -E \
|
|
-e "s/^title:[[:space:]]+\".*\"$/title: \"eXOfàsia ~${next_number}\"/" \
|
|
-e "s/\{\{timestamp\}\}.<!--more-->/${last_date}./" \
|
|
"${path_to_rendered_md}" > "${markdown}"
|
|
|
|
printf "\n\nEnter issue directory..."
|
|
cd $path
|
|
|
|
printf "\n\nPaste the Hebbot curl command here to download all media files, and close the shell again with 'exit'.\n\n"
|
|
|
|
# Enter new shell inside the issue directory
|
|
exec env PS1="HEBBOT ${today} (eXOfàsia ~${next_number})$ " "${SHELL}"
|