Display fediverse:creator header tag on posts

This uses the fediverse actor a blog author has added in
the Verification field on their blog, looking up the handle
locally to display it in the `fediverse:creator` tag. If
it doesn't exist locally, the tag is simply left out.
This commit is contained in:
Matt Baer 2025-02-15 17:15:56 -05:00
parent a7fa19f2e4
commit 69f468f7a7
4 changed files with 56 additions and 23 deletions

View file

@ -971,6 +971,24 @@ func getRemoteUserFromHandle(app *App, handle string) (*RemoteUser, error) {
return &u, nil
}
// getRemoteUserFromURL retrieves the profile page of a remote user
// from the @user@server.tld handle
func getRemoteUserFromURL(app *App, urlStr string) (*RemoteUser, error) {
u := RemoteUser{URL: urlStr}
var urlVal, handle sql.NullString
err := app.db.QueryRow("SELECT id, actor_id, inbox, shared_inbox, url, handle FROM remoteusers WHERE url = ?", urlStr).Scan(&u.ID, &u.ActorID, &u.Inbox, &u.SharedInbox, &urlVal, &handle)
switch {
case err == sql.ErrNoRows:
return nil, ErrRemoteUserNotFound
case err != nil:
log.Error("Couldn't get remote user from URL %s: %v", urlStr, err)
return nil, err
}
u.URL = urlVal.String
u.Handle = handle.String
return &u, nil
}
func getActor(app *App, actorIRI string) (*activitystreams.Person, *RemoteUser, error) {
log.Info("Fetching actor %s locally", actorIRI)
actor := &activitystreams.Person{}

View file

@ -639,6 +639,7 @@ type CollectionPage struct {
CanPin bool
Username string
Monetization string
FediverseAuthor string
Flash template.HTML
Collections *[]Collection
PinnedPosts *[]PublicPost

View file

@ -149,6 +149,7 @@ type (
IsCustomDomain bool
Monetization string
Verification string
FediverseAuthor string
PinnedPosts *[]PublicPost
IsFound bool
IsAdmin bool
@ -1614,6 +1615,18 @@ Are you sure it was ever here?`,
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p)
tp.Monetization = coll.Monetization
tp.Verification = coll.Verification
if tp.Verification != "" {
// Fetch info for fediverse:creator tag
ru, err := getRemoteUserFromURL(app, coll.Verification)
if err != nil {
if debugging {
log.Info("showing rel=me tag, but no local handle for %s", coll.Verification)
}
} else {
// Though we don't store handles with leading @, strip it here just in case
tp.FediverseAuthor = "@" + strings.TrimLeft(ru.Handle, "@")
}
}
if !postFound {
w.WriteHeader(http.StatusNotFound)

View file

@ -4,6 +4,7 @@
<meta name="monetization" content="{{.DisplayMonetization}}" />
{{- end}}
{{if .Verification -}}
{{if .FediverseAuthor}}<meta name="fediverse:creator" content="{{.FediverseAuthor}}">{{end}}
<link rel="me" href="{{.Verification}}" />
{{- end}}
{{end}}