#!/data/data/com.termux/files/usr/bin/sh

SERVER="$1"

curl -s \
    "${SERVER%/}/api/v1/timelines/tag/event?limit=40" |

jq -c '
    .[] |
    {
        url: (.url // .uri // ""),
        author: ("@" + (.account.acct // "")),
        published: (.created_at // ""),
        tags: [.tags[]?.name],
        content: (
            (.content // "")
            | gsub("<br ?/?>"; "\n"; "i")
            | gsub("</p>"; "\n\n"; "i")
            | gsub("<[^>]+>"; "")
            | gsub("&amp;"; "&")
            | gsub("&lt;"; "<")
            | gsub("&gt;"; ">")
            | gsub("&quot;"; "\"")
            | gsub("&#39;"; "\u0027")
        )
    }
'
