an attempt at opengraph
This commit is contained in:
parent
712873418b
commit
e20c344f11
|
@ -25,7 +25,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
notrand "math/rand"
|
notrand "math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1602,12 +1601,7 @@ func junkuser(user *WhatAbout) junk.Junk {
|
||||||
a := junk.New()
|
a := junk.New()
|
||||||
a["type"] = "Image"
|
a["type"] = "Image"
|
||||||
a["mediaType"] = "image/png"
|
a["mediaType"] = "image/png"
|
||||||
if ava := user.Options.Avatar; ava != "" {
|
a["url"] = avatarURL(user)
|
||||||
a["url"] = ava
|
|
||||||
} else {
|
|
||||||
u := fmt.Sprintf("https://%s/a?a=%s", serverName, url.QueryEscape(user.URL))
|
|
||||||
a["url"] = u
|
|
||||||
}
|
|
||||||
j["icon"] = a
|
j["icon"] = a
|
||||||
if ban := user.Options.Banner; ban != "" {
|
if ban := user.Options.Banner; ban != "" {
|
||||||
a := junk.New()
|
a := junk.New()
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"image"
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -103,6 +104,13 @@ func genAvatar(name string) []byte {
|
||||||
return buf.Bytes()
|
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) {
|
func showflag(writer http.ResponseWriter, req *http.Request) {
|
||||||
code := mux.Vars(req)["code"]
|
code := mux.Vars(req)["code"]
|
||||||
colors := strings.Split(code, ",")
|
colors := strings.Split(code, ",")
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet">
|
<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ .APAltLink }}
|
{{ .APAltLink }}
|
||||||
|
{{ .Honkology }}
|
||||||
<link href="/icon.png" rel="icon">
|
<link href="/icon.png" rel="icon">
|
||||||
<meta name="theme-color" content="#305">
|
<meta name="theme-color" content="#305">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
|
|
36
web.go
36
web.go
|
@ -1017,6 +1017,34 @@ func trackback(xid string, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
func showonehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
name := mux.Vars(r)["name"]
|
name := mux.Vars(r)["name"]
|
||||||
user, err := butwhatabout(name)
|
user, err := butwhatabout(name)
|
||||||
|
@ -1064,19 +1092,23 @@ func showonehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
honkpage(w, u, honks, templinfo)
|
honkpage(w, u, honks, templinfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templinfo := getInfo(r)
|
||||||
rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0)
|
rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0)
|
||||||
reversehonks(rawhonks)
|
reversehonks(rawhonks)
|
||||||
var honks []*Honk
|
var honks []*Honk
|
||||||
for _, h := range rawhonks {
|
for _, h := range rawhonks {
|
||||||
if h.XID == xid && len(honks) != 0 {
|
if h.XID == xid {
|
||||||
|
templinfo["Honkology"] = honkology(h)
|
||||||
|
if len(honks) != 0 {
|
||||||
h.Style += " glow"
|
h.Style += " glow"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if h.Public && (h.Whofore == 2 || h.IsAcked()) {
|
if h.Public && (h.Whofore == 2 || h.IsAcked()) {
|
||||||
honks = append(honks, h)
|
honks = append(honks, h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templinfo := getInfo(r)
|
|
||||||
templinfo["ServerMessage"] = "one honk maybe more"
|
templinfo["ServerMessage"] = "one honk maybe more"
|
||||||
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
||||||
templinfo["APAltLink"] = templates.Sprintf("<link href='%s' rel='alternate' type='application/activity+json'>", xid)
|
templinfo["APAltLink"] = templates.Sprintf("<link href='%s' rel='alternate' type='application/activity+json'>", xid)
|
||||||
|
|
Loading…
Reference in New Issue