From d624b7cf58d1a594dc8e375ebe106d344ed03ccc Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 11 May 2023 08:41:47 -0700 Subject: [PATCH] bskyweb: iterate on HTML card metadata (#609) Probably still not perfect, but better. - don't user avatar image. use banner for profile and post img, or nothing - most twitter metadata fields were redundant; twitter will parse out opengraph ("og:"), so don't duplicate those - add regular HTML description (for google, etc) - include URI - actually include text --- bskyweb/cmd/bskyweb/server.go | 10 +++++++- bskyweb/templates/home.html | 10 +++----- bskyweb/templates/post.html | 46 +++++++++++++++++++++++----------- bskyweb/templates/profile.html | 44 +++++++++++++++++++++----------- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index 5ba1dbc8..902d1ffc 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -185,7 +185,13 @@ func (srv *Server) WebPost(c echo.Context) error { if err != nil { log.Warnf("failed to fetch post: %s\t%v", uri, err) } else { - data["postView"] = tpv.Thread.FeedDefs_ThreadViewPost.Post + req := c.Request() + postView := tpv.Thread.FeedDefs_ThreadViewPost.Post + data["postView"] = postView + data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) + if postView.Embed != nil && postView.Embed.EmbedImages_View != nil { + data["imgThumbUrl"] = postView.Embed.EmbedImages_View.Images[0].Thumb + } } } @@ -203,7 +209,9 @@ func (srv *Server) WebProfile(c echo.Context) error { if err != nil { log.Warnf("failed to fetch handle: %s\t%v", handle, err) } else { + req := c.Request() data["profileView"] = pv + data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) } } diff --git a/bskyweb/templates/home.html b/bskyweb/templates/home.html index 6625a7d9..0677b915 100644 --- a/bskyweb/templates/home.html +++ b/bskyweb/templates/home.html @@ -3,14 +3,12 @@ {% block head_title %}Bluesky{% endblock %} {% block html_head_extra -%} + + - - - - - - + + {%- endblock %} diff --git a/bskyweb/templates/post.html b/bskyweb/templates/post.html index 866a9739..05d62a1c 100644 --- a/bskyweb/templates/post.html +++ b/bskyweb/templates/post.html @@ -1,23 +1,39 @@ {% extends "base.html" %} -{# TODO: link rel=canonical #} -{# TODO: "same as" #} +{% block head_title %} +{%- if postView -%} + @{{ postView.Author.Handle }} on Bluesky +{%- else -%} + Bluesky +{%- endif -%} +{% endblock %} + {% block html_head_extra -%} -{%- if postView %} - - - - - {%- if postView.Author.Avatar %} - - +{%- if postView -%} + + + {%- if requestURI %} + {% endif -%} - {%- if postView.Record.Text %} - - + {%- if postView.Author.DisplayName %} + + {% else %} + {% endif -%} - - + {%- if postView.Record.Val.Text %} + + + {% endif -%} + {%- if imgThumbUrl %} + + + {%- elif postView.Author.Avatar %} + {# Don't use avatar image in cards; usually looks bad #} + + {% endif %} + + + {% endif -%} {%- endblock %} diff --git a/bskyweb/templates/profile.html b/bskyweb/templates/profile.html index 0710d328..4d4f6794 100644 --- a/bskyweb/templates/profile.html +++ b/bskyweb/templates/profile.html @@ -1,24 +1,40 @@ {% extends "base.html" %} -{# TODO: "same as" indication with DID? #} -{# TODO: could work in profileView.DisplayName here, conditionally? #} +{% block head_title %} +{%- if profileView -%} + @{{ profileView.Handle }} on Bluesky +{%- else -%} + Bluesky +{%- endif -%} +{% endblock %} + {% block html_head_extra -%} {%- if profileView -%} - - - - + + + {%- if requestURI %} + + {% endif -%} + {%- if profileView.DisplayName %} + + {% else %} + + {% endif -%} {%- if profileView.Description %} - - + + {% endif -%} - {%- if profileView.Avatar %} - - - {% endif -%} - + {%- if profileView.Banner %} + + + {%- elif profileView.Avatar -%} + {# Don't use avatar image in cards; usually looks bad #} + + {% endif %} + -{%- endif -%} + +{% endif -%} {%- endblock %} {% block noscript_extra -%}