all repos — honk @ d892ed3e5ad511046b00bd8efea823acfa3c1827

my fork of honk

an attempt at opengraph
Ted Unangst tedu@tedunangst.com
Tue, 13 Jun 2023 14:58:35 -0400
commit

d892ed3e5ad511046b00bd8efea823acfa3c1827

parent

61991f1a0233c5577b67b1eba29596870221ee06

4 files changed, 45 insertions(+), 10 deletions(-)

jump to
M activity.goactivity.go

@@ -25,7 +25,6 @@ "html"

"io" notrand "math/rand" "net/http" - "net/url" "os" "regexp" "strings"

@@ -1602,12 +1601,7 @@ j["following"] = user.URL + "/following"

a := junk.New() a["type"] = "Image" a["mediaType"] = "image/png" - if ava := user.Options.Avatar; ava != "" { - a["url"] = ava - } else { - u := fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL)) - a["url"] = u - } + a["url"] = avatarURL(user) j["icon"] = a if ban := user.Options.Banner; ban != "" { a := junk.New()
M avatar.goavatar.go

@@ -23,6 +23,7 @@ "fmt"

"image" "image/png" "net/http" + "net/url" "regexp" "strconv" "strings"

@@ -101,6 +102,13 @@ }

var buf bytes.Buffer png.Encode(&buf, img) return buf.Bytes() +} + +func avatarURL(user *WhatAbout) string { + if ava := user.Options.Avatar; ava != "" { + return ava + } + return fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL)) } func showflag(writer http.ResponseWriter, req *http.Request) {
M views/header.htmlviews/header.html

@@ -7,6 +7,7 @@ {{ if .LocalStyleParam }}

<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet"> {{ end }} {{ .APAltLink }} +{{ .Honkology }} <link href="/icon.png" rel="icon"> <meta name="theme-color" content="#305"> <meta name="viewport" content="width=device-width">
M web.goweb.go

@@ -1017,6 +1017,34 @@ trackchan <- Track{xid: xid, who: who}

} } +func honkology(honk *Honk) template.HTML { + var user *WhatAbout + ok := somenumberedusers.Get(honk.UserID, &user) + if !ok { + return "" + } + title := fmt.Sprintf("%s: %s", user.Display, honk.Precis) + imgurl := avatarURL(user) + for _, d := range honk.Donks { + if d.Local && strings.HasPrefix(d.Media, "image") { + imgurl = d.URL + break + } + } + short := honk.Noise + if len(short) > 160 { + short = short[0:160] + "..." + } + return templates.Sprintf( + `<meta property="og:title" content="%s" /> +<meta property="og:type" content="article" /> +<meta property="article:author" content="%s" /> +<meta property="og:url" content="%s" /> +<meta property="og:image" content="%s" /> +<meta property="og:description" content = "%s" />`, + title, user.URL, honk.XID, imgurl, short) +} + func showonehonk(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] user, err := butwhatabout(name)

@@ -1064,19 +1092,23 @@ templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)

honkpage(w, u, honks, templinfo) return } + + templinfo := getInfo(r) rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0) reversehonks(rawhonks) var honks []*Honk for _, h := range rawhonks { - if h.XID == xid && len(honks) != 0 { - h.Style += " glow" + if h.XID == xid { + templinfo["Honkology"] = honkology(h) + if len(honks) != 0 { + h.Style += " glow" + } } if h.Public && (h.Whofore == 2 || h.IsAcked()) { honks = append(honks, h) } } - templinfo := getInfo(r) templinfo["ServerMessage"] = "one honk maybe more" templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) templinfo["APAltLink"] = templates.Sprintf("<link href='%s' rel='alternate' type='application/activity+json'>", xid)