From ac71ea235f27234a34e5005af03935f80a9d1092 Mon Sep 17 00:00:00 2001 From: Caidan Date: Wed, 17 Sep 2025 14:30:10 -0700 Subject: improve: enhance post OpenGraph metadata with engagement data and auth handling (#9046) --- bskyweb/cmd/bskyweb/server.go | 14 ++++++++++---- bskyweb/templates/base.html | 2 +- bskyweb/templates/post.html | 45 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index 8d75bb6ef..672e8d25e 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -488,20 +488,26 @@ func (srv *Server) WebPost(c echo.Context) error { } } + req := c.Request() if !unauthedViewingOkay { + // Provide minimal OpenGraph data for auth-required posts + data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) + data["requiresAuth"] = true + data["profileHandle"] = pv.Handle + if pv.DisplayName != nil { + data["profileDisplayName"] = *pv.DisplayName + } return c.Render(http.StatusOK, "post.html", data) } - did := pv.Did - data["did"] = did // then fetch the post thread (with extra context) - uri := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", did, rkey) + uri := fmt.Sprintf("at://%s/app.bsky.feed.post/%s", pv.Did, rkey) tpv, err := appbsky.FeedGetPostThread(ctx, srv.xrpcc, 1, 0, uri) if err != nil { log.Warnf("failed to fetch post: %s\t%v", uri, err) return c.Render(http.StatusOK, "post.html", data) } - req := c.Request() + postView := tpv.Thread.FeedDefs_ThreadViewPost.Post data["postView"] = postView data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) diff --git a/bskyweb/templates/base.html b/bskyweb/templates/base.html index 715b39fd2..c8dec0e22 100644 --- a/bskyweb/templates/base.html +++ b/bskyweb/templates/base.html @@ -94,7 +94,7 @@ - + diff --git a/bskyweb/templates/post.html b/bskyweb/templates/post.html index 6473bc284..983f84535 100644 --- a/bskyweb/templates/post.html +++ b/bskyweb/templates/post.html @@ -3,6 +3,8 @@ {% block head_title %} {%- if postView -%} @{{ postView.Author.Handle }} on Bluesky +{%- elif requiresAuth and profileHandle -%} + @{{ profileHandle }} on Bluesky {%- else -%} Bluesky {%- endif -%} @@ -11,7 +13,7 @@ {% block html_head_extra -%} {%- if postView -%} - + {%- if requestURI %} @@ -32,17 +34,44 @@ {% endfor %} - {%- elif postView.Author.Avatar %} - + {% else %} + {% endif %} - - + {%- if postView.LikeCount %} + + + {% endif -%} + {%- if postView.ReplyCount %} + + + {% endif -%} + {%- if postView.RepostCount %} + + + {% endif -%} + +{%- elif requiresAuth and profileHandle -%} + + + {%- if requestURI %} + + + {% endif -%} + {%- if profileDisplayName %} + + {% else %} + + {% endif -%} + + + + {% endif -%} {%- endblock %} @@ -56,5 +85,11 @@

{{ postText }}

{{ postView.IndexedAt }}

+{%- elif requiresAuth and profileHandle -%} +
+

Post

+

{{ profileHandle }}

+

This post requires authentication to view.

+
{% endif -%} {%- endblock %} -- cgit 1.4.1