Fetch website toots from API

This commit is contained in:
Brandon Rozek 2025-06-08 19:39:56 -04:00
parent d3434eff06
commit 53b9acc9f0
No known key found for this signature in database
GPG key ID: DFB0E78F805F4567
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,40 @@
{{/* Get remote data. */}}
{{ $items := dict }}
{{ $url := "https://api.brandonrozek.com/toots" }}
{{ with try (resources.GetRemote $url ) }}
{{ with .Err }}
{{ errorf "Unable to get remote resource %s: %s" $url . }}
{{ else with .Value }}
{{ $items = . | transform.Unmarshal }}
{{ else }}
{{ errorf "Unable to get remote resource %s" $url }}
{{ end }}
{{ end }}
{{ range $items.toots }}
{{ $content := dict "mediaType" "text/html" "value" .content }}
{{ $dates := dict "date" (time.AsTime .created_at) }}
{{ $params := dict
"favourites_count" .favourites_count
"syndication" .url
"author" "@brozek@fosstodon.org"
"account" (dict
"display_name" "@brozek"
"avatar" "https://cdn.fosstodon.org/accounts/avatars/108/219/415/927/856/966/original/bae9f46f23936e79.jpg"
)
"media_attachments" .media_attachments
"reblogs_count" .reblogs_count
"replies_count" .replies_count
}}
{{ $page := dict
"content" $content
"dates" $dates
"kind" "page"
"params" $params
"path" .id
"title" ""
"build" (dict "render" "never")
}}
{{ $.AddPage $page }}
{{ end }}

8
content/toots/_index.md Normal file
View file

@ -0,0 +1,8 @@
---
title: Toots
description: Brandon's Toots from Mastodon
---
This is an experimental page showing my toots from Mastodon.
Currently, this does not support boosts and it refreshes daily through a GitHub action.
Feel free to check out [my profile at Fosstodon](https://fosstodon.org/@brozek)