Code as it stands in December 2023
This is the BASH code so far.
#!/bin/bash
AUTHOR="`whoami`@analoguelife"
WEBSITE="https://analoguelife.xyz/"
;
CSS="../style.css"
;
INDEXFILE="index.html"
;
EDITOR="nvim + +startinsert"
;
DEFAULTFOLDER="$PWD"
;
EXT="md"
;
# Ask for Post Title then open Markdown template in editor
newpost () {
read -ep "Title of new Post? " title ; echo "$title"
TITLE="$title"
DATE=`date +"%Y-%m-%d %H:%M"`
SLUG=$(echo -n "${title}" | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)
if [[ "${title:0:1}" == "2" ]]; then TITLE=${title:11}; fi
if [[ ! -f ${DEFAULTFOLDER}/drafts/${SLUG}.${EXT} ]]; then
echo -e "---\nwebsite: ${WEBSITE}\ntitle: ${title}\nauthor: ${AUTHOR}\ndate:
${DATE}\nslug: ${SLUG}\ntags:\n---\n\n" > "${DEFAULTFOLDER}/drafts/${SLUG}.${EXT}"
fi
${EDITOR} "${DEFAULTFOLDER}/drafts/${SLUG}.${EXT}" ;}
# Find & list out files
filefind() {
files=( */*.md )
PS3="$MSG";
if [[ ! -e ${files[0]} ]]; then
echo "No Files found."; exit
fi
select file in "${files[@]}"; do
if [[ $REPLY == "0" ]]; then echo "Bye!"; exit
elif [[ -z $file ]]; then echo "Invalid choice, try again"
else break
fi
done
}
# Ask for file to delete, then delete
delete () {
MSG="Choose file to Delete, or 0 to exit: "
filefind;
rm -f "$file" ; echo "$file deleted."
}
# Ask for file to convert, then publish post from Markdown to HTML using Pandoc. Also create snippet to inject to index.html
publish () {
MSG="Choose file to Publish, or 0 to exit: "
filefind;
pandoc -s $file -o "${file%.md}.html" --template="$DEFAULTFOLDER/tmpl/main.html"
pandoc -s $file -o "entry.html" --template="$DEFAULTFOLDER/tmpl/entry.html"
sed -i "/<!-- Entry -->/r entry.html" "$INDEXFILE"
mv drafts/*.html "${DEFAULTFOLDER}/posts/"
rm -f "$file"; rm -f "entry.html"
echo "File converted and saved to ${DEFAULTFOLDER}/"
}
# Menu of options
case "$1" in
np*) newpost ;;
dp*) delete ;;
pp*) publish ;;
*) printf "\\nBlog by Analoguelife <matt@analoguelife.xyz>.\\n\\n
Usage:\\n./blog np:\\tNew Post\\n./blog dp:\\tDelete Post\\n./blog pp:\\tPublish via
Pandoc to HTML\\n./blog\\n\\n" ;;
esac
© matthew@analoguelife | 2023-12-30
14:37