#!/usr/bin/env sh # Dependency: pup set -e [ "$2" ] || { echo "usage: $0 "; exit 1; } echo "Converting $2" mkdir -p "$1/images" || true img="$1/images/$(basename "$2").jpg" imgurl="$(pup -f "$2" 'div.featured-image img attr{src}')" [ -f "$img" ] || curl -s -o "$img" "$imgurl" title="$(pup -f "$2" '#page-title text{}')" author="$(pup -f "$2" '.username text{}')" imgcredit="$(pup -f "$2" 'div.featured-image a text{}')" if [ "$imgcredit" ]; then imgcrediturl="$(pup -f "$2" 'div.featured-image a attr{href}' | tail -n1)" else imgcrediturl="" imgcredit="$author" fi description="$(pup -f "$2" 'div.field-type-text-with-summary text{}' \ | sed -z 's/\n\n\+/\n\n/g')" ingredients="$(pup -f "$2" "div[itemprop="ingredients"]" \ | tr -d "\n" \ | sed 's||\n|g; s|<[^>]\+>||g;' \ | sed 's/^ \+//g; s/^/- /g' | tr -s ' ')" directions="$(pup -f "$2" "div[itemprop="recipeInstructions"].step-body" \ | tr -d "\n" \ | sed 's||\n|g; s|<[^>]\+>||g;' \ | sed 's/^ \+//g; s/^[0-9]\+\. \+//g; s/^/- /g' | tr -s ' ')" tags="$(pup -f "$2" 'div.field-type-taxonomy-term-reference a text{}' \ | tr "\n" "," | sed 's/,$//g; s/,/, /g;')" cat > "$1/$(basename "$2").yml" <