mirror of
https://github.com/trwnh/hugo-content-adapter-mastodon.git
synced 2024-11-24 09:31:21 +00:00
72 lines
1.8 KiB
Go Template
72 lines
1.8 KiB
Go Template
{{ $actor_data := dict }}
|
|
{{ $actor_url := "https://mastodon.social/users/trwnh.json" }}
|
|
{{ with resources.GetRemote $actor_url }}
|
|
{{ with .Err }}
|
|
{{ errorf "Unable to get remote resource %s: %s" $actor_url . }}
|
|
{{ else }}
|
|
{{ $actor_data = . | unmarshal }}
|
|
{{ end }}
|
|
{{ else }}
|
|
{{ errorf "Unable to get remote resource %s" $actor_url }}
|
|
{{ end }}
|
|
|
|
{{ with $actor_data }}
|
|
|
|
{{ $username := .preferredUsername }}
|
|
|
|
{{/* Fetch and save avatar */}}
|
|
{{ $avatar_url := .icon.url }}
|
|
{{ with resources.GetRemote $avatar_url }}
|
|
{{ with .Err }}
|
|
{{ warnf "Unable to get avatar from %s with error: %s" $avatar_url . }}
|
|
{{ else }}
|
|
{{ $avatar_content := dict "mediaType" .MediaType.Type "value" .Content }}
|
|
{{ $avatar_resource := dict
|
|
"path" (printf "avatar.%s" (index .MediaType.Suffixes 0))
|
|
"content" $avatar_content
|
|
}}
|
|
{{ $.AddResource $avatar_resource }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{/* Fetch and save header */}}
|
|
{{ $header_url := .image.url }}
|
|
{{ with resources.GetRemote $header_url }}
|
|
{{ with .Err }}
|
|
{{ warnf "Unable to get header from %s with error: %s" $avatar_url . }}
|
|
{{ else }}
|
|
{{ $header_content := dict "mediaType" .MediaType.Type "value" .Content }}
|
|
{{ $header_resource := dict
|
|
"path" (printf "header.%s" (index .MediaType.Suffixes 0))
|
|
"content" $header_content
|
|
}}
|
|
{{ $.AddResource $header_resource }}
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{/* Add account page */}}
|
|
{{ $account_page := dict
|
|
"path" "."
|
|
"kind" "section"
|
|
"title" .name
|
|
"summary" (.summary | plainify)
|
|
"content" (dict
|
|
"mediaType" "text/html"
|
|
"value" ""
|
|
)
|
|
"type" "mastodon"
|
|
"layout" "user"
|
|
"params" (dict
|
|
"mastodon" (dict
|
|
"_model" "Account"
|
|
"username" .preferredUsername
|
|
"created_at" (.published | time)
|
|
"note" .summary
|
|
"display_name" .name
|
|
|
|
)
|
|
)
|
|
}}
|
|
{{ $.AddPage $account_page }}
|
|
|
|
{{ end }} |