#!/usr/bin/env bash # Blop # By Drew # Amazing logo by HexDSL # uoou@posteo.net # https://gitlab.com/uoou/blop # GPL v.2 blogdir="$PWD" # Default behaviour is to act on the current working directory. You can specify a directory if you prefer. No trailing slash # The following settings can be overridden by placing a 'site.conf' file in the blog directory with a yaml*ish* format, i.e.: # # default_author: Rebecca Black # max_posts: 20 # default_author="Drew" max_posts="10" # number of posts to list on the blog index, posts beyond this will listed in archive.html. Set to "unlimited" (with quotes) to archive nothing group_by_date=false # whether to group the main listing on the blog's index by dates date_format="%B %-d, %Y" short_date_format="%B, %Y" # format for date grouping in the archive and optionally on the index (see group_by_date above) listing_format="/\"> 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 ####################### # load config file if it exists and assign stuff if [[ -f "$blogdir/site.conf" ]]; then echo "Reading $blogdir/site.conf" conf=$(cat "$blogdir/site.conf") if grep -q "default_author" <<< "$conf"; then default_author=$(echo "$conf" | sed -n 's/^default_author:\s\?\(.*\)$/\1/p') fi if grep -q "max_posts" <<< "$conf"; then max_posts=$(echo "$conf" | sed -n 's/^max_posts:\s\?\(.*\)$/\1/p') fi if grep -q "group_by_date" <<< "$conf"; then group_by_date=$(echo "$conf" | sed -n 's/^group_by_date:\s\?\(.*\)$/\1/p') fi if grep -q "date_format" <<< "$conf"; then date_format=$(echo "$conf" | sed -n 's@^date_format:\s\?\(.*\)$@\1@p') fi if grep -q "short_date_format" <<< "$conf"; then short_date_format=$(echo "$conf" | sed -n 's@^short_date_format:\s\?\(.*\)$@\1@p') fi if grep -q "listing_format" <<< "$conf"; then listing_format=$(echo "$conf" | sed -n 's@^listing_format:\s\?\(.*\)$@\1@p') fi fi 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 -1 "$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 -rf $blogdir/posts/* fi rm -f "$blogdir/index.html" "$blogdir/rss.xml" url=$(cat "$blogdir/url.txt") temp=$(mktemp -d) trap 'rm -rf "$temp"' EXIT postcount="0" postlist="