Last active
January 28, 2023 01:28
-
-
Save shazow/0a9f4e0afc9f5e7b85401ab0bf8b322e to your computer and use it in GitHub Desktop.
Revisions
-
shazow revised this gist
Jan 28, 2023 . 1 changed file with 10 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,6 @@ #!/usr/bin/env nix-shell #!nix-shell -i bash -p jq curl set -e prefix() { @@ -24,13 +22,12 @@ urlencode() { 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" @@ -49,7 +46,11 @@ render() { } 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 -
shazow renamed this gist
Jan 28, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
shazow created this gist
Jan 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ #!/usr/bin/env nix-shell #!nix-shell -i bash -p jq curl # Takes a pinboard export .json, outputs a markdown file per bookmark. 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 -r .href); declare title=$(echo $line | jq -r .description); declare description=$(echo $line | jq -r .extended); declare timestamp=$(echo $line | jq -r .time); declare tags=$(echo $line | jq -r .tags | sed 's|\s| #|g'); echo "$path" 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 -r .href | urlnormalize | urlencode).md" echo "Converting: $path" render "$line" > $path done