From adb903dc60d1136ba04347c5840eddc5c58702bc Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Thu, 2 Jun 2022 20:20:32 -0400 Subject: [PATCH] Refactored toot code --- assets/css/style.css | 4 ++ layouts/partials/toot.html | 51 ++++++++++++++++++ layouts/shortcodes/displayOnlineToot.html | 50 +---------------- layouts/shortcodes/displayToot.html | 50 +---------------- layouts/shortcodes/displayToots.html | 48 +---------------- layouts/toots/list.html | 66 ++++++----------------- layouts/toots/single.html | 61 ++++++--------------- 7 files changed, 94 insertions(+), 236 deletions(-) create mode 100644 layouts/partials/toot.html diff --git a/assets/css/style.css b/assets/css/style.css index 5e8410f..9ec5bde 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -267,6 +267,10 @@ main { min-height: calc(100vh - 250px); } +article { + padding-bottom: 20px; +} + main .e-content { text-align: left; } diff --git a/layouts/partials/toot.html b/layouts/partials/toot.html new file mode 100644 index 0000000..d553574 --- /dev/null +++ b/layouts/partials/toot.html @@ -0,0 +1,51 @@ +{{ $tootData := .Scratch.Get "toot" }} + +{{ with $tootData }} +{{ if ne .content "" }} +
+ +

Tooted on

+
+ {{ .content | safeHTML }} + {{ if gt (len .media_attachments) 0 }} +
+ {{ range .media_attachments}} + {{ if eq .type "image" }} + {{ .description }} + {{ end }} + {{ end }} +
+ {{ end }} +
+ + {{ range .tags }} + + {{ end }} +
+ {{ $post_url := urls.Parse .url }} + {{ $status_id := index (last 1 (split $post_url.Path "/")) 0 }} + {{ $social_url := printf "%s://%s/interact/%s" $post_url.Scheme $post_url.Host $status_id }} + {{ $reply_url := printf "%s?type=reply" $social_url }} + {{ $favorite_url := printf "%s?type=favourite" $social_url }} + {{ $boost_url := printf "%s?type=reblog" $social_url }} + + + {{ .replies_count }} + + + + {{ .reblogs_count }} + + + + {{ .favourites_count }} + + | Source: {{ .url }} +
+
+ {{ end }} + {{ end }} + \ No newline at end of file diff --git a/layouts/shortcodes/displayOnlineToot.html b/layouts/shortcodes/displayOnlineToot.html index 5a9520c..7e1a426 100644 --- a/layouts/shortcodes/displayOnlineToot.html +++ b/layouts/shortcodes/displayOnlineToot.html @@ -3,51 +3,5 @@ {{ $api_url := printf "%s://%s/api/v1/statuses/%s" $url.Scheme $url.Host $status_id }} {{ $dataJ := getJSON $api_url }} -{{ with $dataJ }} -{{ if ne .content "" }} -
- -

Tooted on

-
- {{ .content | safeHTML }} - {{ if gt (len .media_attachments) 0 }} -
- {{ range .media_attachments}} - {{ if eq .type "image" }} - {{ .description }} - {{ end }} - {{ end }} -
- {{ end }} -
- - {{ range .tags }} - - {{ end }} -
- {{ $post_url := urls.Parse .url }} - {{ $status_id := index (last 1 (split $post_url.Path "/")) 0 }} - {{ $social_url := printf "%s://%s/interact/%s" $post_url.Scheme $post_url.Host $status_id }} - {{ $reply_url := printf "%s?type=reply" $social_url }} - {{ $favorite_url := printf "%s?type=favourite" $social_url }} - {{ $boost_url := printf "%s?type=reblog" $social_url }} - - - {{ .replies_count }} - - - - {{ .reblogs_count }} - - - - {{ .favourites_count }} - - | Source: {{ .url }} -
-
-{{ end }} -{{ end }} +{{ .Scratch.Set "toot" $dataJ }} +{{ partial "toot.html" . }} diff --git a/layouts/shortcodes/displayToot.html b/layouts/shortcodes/displayToot.html index 29e4e30..2acd29b 100644 --- a/layouts/shortcodes/displayToot.html +++ b/layouts/shortcodes/displayToot.html @@ -2,51 +2,5 @@ {{ $url := printf "static/data/toots/%s.json" $toot_reference }} {{ $dataJ := getJSON $url }} -{{ with $dataJ }} -{{ if ne .content "" }} -
- -

Tooted on

-
- {{ .content | safeHTML }} - {{ if gt (len .media_attachments) 0 }} -
- {{ range .media_attachments}} - {{ if eq .type "image" }} - {{ .description }} - {{ end }} - {{ end }} -
- {{ end }} -
- - {{ range .tags }} - - {{ end }} -
- {{ $post_url := urls.Parse .url }} - {{ $status_id := index (last 1 (split $post_url.Path "/")) 0 }} - {{ $social_url := printf "%s://%s/interact/%s" $post_url.Scheme $post_url.Host $status_id }} - {{ $reply_url := printf "%s?type=reply" $social_url }} - {{ $favorite_url := printf "%s?type=favourite" $social_url }} - {{ $boost_url := printf "%s?type=reblog" $social_url }} - - - {{ .Params.replies_count }} - - - - {{ .Params.reblogs_count }} - - - - {{ .Params.favourites_count }} - - | Source: {{ .url }} -
-
-{{ end }} -{{ end }} +{{ .Scratch.Set "toot" $dataJ }} +{{ partial "toot.html" . }} diff --git a/layouts/shortcodes/displayToots.html b/layouts/shortcodes/displayToots.html index 7fd6378..2853d7d 100644 --- a/layouts/shortcodes/displayToots.html +++ b/layouts/shortcodes/displayToots.html @@ -3,50 +3,6 @@ {{ range sort $dataJ "created_at" "desc" }} -{{ if ne .content "" }} -
- -

Tooted on

-
- {{ .content | safeHTML }} - {{ if gt (len .media_attachments) 0 }} -
- {{ range .media_attachments}} - {{ if eq .type "image" }} - {{ .description }} - {{ end }} - {{ end }} -
- {{ end }} -
- - {{ range .tags }} - - {{ end }} -
- {{ $post_url := urls.Parse .url }} - {{ $status_id := index (last 1 (split $post_url.Path "/")) 0 }} - {{ $social_url := printf "%s://%s/interact/%s" $post_url.Scheme $post_url.Host $status_id }} - {{ $reply_url := printf "%s?type=reply" $social_url }} - {{ $favorite_url := printf "%s?type=favourite" $social_url }} - {{ $boost_url := printf "%s?type=reblog" $social_url }} - - - {{ .Params.replies_count }} - - - - {{ .Params.reblogs_count }} - - - - {{ .Params.favourites_count }} - - | Source: {{ .url }} -
-
-{{ end }} + {{ .Scratch.Set "toot" $dataJ }} + {{ partial "toot.html" . }} {{ end }} diff --git a/layouts/toots/list.html b/layouts/toots/list.html index 71104f5..07d6424 100644 --- a/layouts/toots/list.html +++ b/layouts/toots/list.html @@ -3,59 +3,25 @@
{{ partial "search.html" . }} -

- This is an experimental page showing my toots from Mastodon. - Currently, this does not support boosts and it does not automatically refresh. - Feel free to check out - my profile at Fosstodon -

+ {{ .Content }} {{ $listPageDateFormat := .Site.Params.listPageDateFormat | default "January, 2006"}} {{ range $index, $value := .Pages.GroupByDate $listPageDateFormat }} {{ range .Pages }} -
- -

Tooted on

-
- {{ .Content | safeHTML }} - {{ if gt (len .Params.media_attachments) 0 }} -
- {{ range .Params.media_attachments}} - {{ if eq .type "image" }} - {{ .description }} - {{ end }} - {{ end }} -
- {{ end }} -
- - {{ range .Params.tags }} - - {{ end }} -
- {{ $post_url := urls.Parse .Params.syndication }} - {{ $status_id := index (last 1 (split $post_url.Path "/")) 0 }} - {{ $social_url := printf "%s://%s/interact/%s" $post_url.Scheme $post_url.Host $status_id }} - {{ $reply_url := printf "%s?type=reply" $social_url }} - {{ $favorite_url := printf "%s?type=favourite" $social_url }} - {{ $boost_url := printf "%s?type=reblog" $social_url }} - - - {{ .Params.replies_count }} - - - - {{ .Params.reblogs_count }} - - - - {{ .Params.favourites_count }} - - | Source: {{ .Params.syndication }} -
-
+ {{ $dataJ := dict "account" .Params.account + "account.display_name" .Params.account.display_name + "created_at" .Date + "content" .Content + "media_attachments" .Params.media_attachments + "Permalink" .Permalink + "tags" .Params.tags + "url" .Params.syndication + "replies_count" .Params.replies_count + "reblogs_count" .Params.reblogs_count + "favourites_count" .Params.favourites_count + }} + + {{ .Scratch.Set "toot" $dataJ }} + {{ partial "toot.html" . }} {{ end }} {{ end }}
diff --git a/layouts/toots/single.html b/layouts/toots/single.html index 7fc0ab0..b8d635f 100644 --- a/layouts/toots/single.html +++ b/layouts/toots/single.html @@ -4,50 +4,23 @@ {{ .Scratch.Set "customTitleHeaderLink" "/toots" }} {{ partial "header.html" . }}
-
- -

Tooted on

-
- {{ .Content | safeHTML }} - {{ if gt (len .Params.media_attachments) 0 }} -
- {{ range .Params.media_attachments}} - {{ if eq .type "image" }} - {{ .description }} - {{ end }} - {{ end }} -
- {{ end }} -
- - {{ range .Params.tags }} - - {{ end }} -
- {{ $post_url := urls.Parse .Params.syndication }} - {{ $status_id := index (last 1 (split $post_url.Path "/")) 0 }} - {{ $social_url := printf "%s://%s/interact/%s" $post_url.Scheme $post_url.Host $status_id }} - {{ $reply_url := printf "%s?type=reply" $social_url }} - {{ $favorite_url := printf "%s?type=favourite" $social_url }} - {{ $boost_url := printf "%s?type=reblog" $social_url }} - - - {{ .Params.replies_count }} - - - - {{ .Params.reblogs_count }} - - - - {{ .Params.favourites_count }} - - | Source: {{ .Params.syndication }} -
-
+ {{ $dataJ := dict "account" .Params.account + "account.display_name" .Params.account.display_name + "created_at" .Date + "content" .Content + "media_attachments" .Params.media_attachments + "Permalink" .Permalink + "tags" .Params.tags + "url" .Params.syndication + "replies_count" .Params.replies_count + "reblogs_count" .Params.reblogs_count + "favourites_count" .Params.favourites_count + }} + + {{ .Scratch.Set "toot" $dataJ }} + {{ partial "toot.html" . }}
+ + {{ partial "footer.html" . }} {{ end }}