#!/usr/bin/env nix-shell #!nix-shell -i bash -p jq curl set -e prefix() { declare token="${1}" while read line; do echo "${token}${line}" done } urlnormalize() { # Strip scheme and trailing slash sed -e 's|^\w*://||g' | sed -e 's|/$||g' } urlencode() { curl -s -w "%{url_effective}" --get --data-urlencode "@-" "example.com" | cut -d '?' -f2- } render() { declare line=$1 declare url=$(echo $line | jq -j -r .href); declare title=$(echo $line | jq -j -r .description); declare description=$(echo $line | jq -j -r .extended); declare timestamp=$(echo $line | jq -j -r .time); declare tags=$(echo $line | jq -j -r .tags | sed 's|\s| #|g'); echo "# $title" echo "" echo "Link: $url" echo "Timestamp: $timestamp" if [[ "$tags" ]]; then echo "Tags: #$tags" else "Tags: " fi echo "" if [[ "$description" ]]; then echo "## Description" echo "$description" | sed 's|<.\?blockquote>||g' | prefix "> " echo "" fi } jq -c .[] $1 | while read line; do declare path="$(echo $line | jq -j -r .href | urlnormalize | urlencode).md" if [[ -f "$path" ]]; then echo "Skipping: $path" continue fi echo "Converting: $path" render "$line" > $path done