Skip to content

Instantly share code, notes, and snippets.

@shazow
Last active January 28, 2023 01:28
Show Gist options
  • Save shazow/0a9f4e0afc9f5e7b85401ab0bf8b322e to your computer and use it in GitHub Desktop.
Save shazow/0a9f4e0afc9f5e7b85401ab0bf8b322e to your computer and use it in GitHub Desktop.

Revisions

  1. shazow revised this gist Jan 28, 2023. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions pinboard2markdown.sh
    Original 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

    # Takes a pinboard export .json, outputs a markdown file per bookmark.

    set -e

    prefix() {
    @@ -24,13 +22,12 @@ urlencode() {
    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');
    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 "$path"
    echo "# $title"
    echo ""
    echo "Link: $url"
    @@ -49,7 +46,11 @@ render() {
    }

    jq -c .[] $1 | while read line; do
    declare path="$(echo $line | jq -r .href | urlnormalize | urlencode).md"
    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
  2. shazow renamed this gist Jan 28, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. shazow created this gist Jan 28, 2023.
    56 changes: 56 additions & 0 deletions pinboard2markdown
    Original 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