#!/usr/bin/env bash # Blop # By Drew # uoou@posteo.net # https://gitlab.com/uoou/blop # GPL v.2 ####################### # Stuff you should edit ####################### blogdir="$PWD" # no trailing slash default_author="Drew" date_format="%B %-d, %Y" listing_format=".html\"> by on " # rejig this and/or remove elements to taste. You may need to change delimeter when sed is used on this later if any of the fields contain slashes ####################### do_error () { if [[ ! -z "$1" ]];then echo "$1" fi exit } # Check for missing stuff and that if ! hash pandoc 2>/dev/null; then do_error "You need pandoc. Install it!" fi if [[ ! -d "$blogdir/markdown/" ]]; then do_error "Directory: $blogdir/markdown/ does not exist. It needs to exist." fi count_mds=$(ls -t1 "$blogdir/markdown/"*.md 2> /dev/null | wc -l) if [[ "$count_mds" -eq "0" ]];then do_error "There are no markdown files in $blogdir/markdown/. There's nowt to do, pal." fi if [[ ! -f "$blogdir/url.txt" ]]; then do_error "Create the file $blogdir/url.txt containing the blog's base url (without trailing slash e.g. http://example.com )" elif [[ ! -s "$blogdir/url.txt" ]]; then do_error "The file $blogdir/url.txt must contain the blog's base url (without trailing slash e.g. http://example.com )" fi #Do the things if [[ ! -d "$blogdir/posts/" ]]; then echo "$blogdir/posts/ doesn't exist, creating it..." mkdir "$blogdir/posts/" else echo "Deleting old HTML files in $blogdir/posts/" find "$blogdir/posts/" -name "*.html" -type f -exec rm -f {} + rm -f "$blogdir/index.html" "$blogdir/rss.xml" fi url=$(cat "$blogdir/url.txt") postlist="" echo -e "$postlist" > "$temp"/list sed "//r $temp/list" "$blogdir/index_template.html" | sed '//d' > "$blogdir/index.html" echo "Creating RSS" sed "//r $temp/rss" "$blogdir/rss_template.xml" | sed "s@@$url@g" | sed '//d' > "$blogdir/rss.xml" # we use @ as delimeter here because replacement text contains slashes. If your sites url contains an @ for some reason, use a delimeter that doesn't appear in the url echo "Done"