From 561568343abd5dad5b5c44746a91c7f9bfd9e0e2 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sun, 11 Nov 2018 15:28:11 -0500 Subject: [PATCH] Use avatar as blog link social media image --- collections.go | 13 ++++++++++--- templates/collection-post.tmpl | 4 ++-- templates/collection-tags.tmpl | 2 ++ templates/collection.tmpl | 2 ++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/collections.go b/collections.go index a6ade4d..0841f7a 100644 --- a/collections.go +++ b/collections.go @@ -264,12 +264,11 @@ func (c *Collection) PersonObject(ids ...int64) *activitystreams.Person { p.Name = c.DisplayTitle() p.Summary = c.Description if p.Name != "" { - fl := string(unicode.ToLower([]rune(p.Name)[0])) - if isLowerLetter(fl) { + if av := c.AvatarURL(); av != "" { p.Icon = activitystreams.Image{ Type: "Image", MediaType: "image/png", - URL: hostName + "/img/avatars/" + fl + ".png", + URL: av, } } } @@ -287,6 +286,14 @@ func (c *Collection) PersonObject(ids ...int64) *activitystreams.Person { return p } +func (c *Collection) AvatarURL() string { + fl := string(unicode.ToLower([]rune(c.DisplayTitle())[0])) + if !isLowerLetter(fl) { + return "" + } + return hostName + "/img/avatars/" + fl + ".png" +} + func (c *Collection) FederatedAPIBase() string { return hostName + "/" } diff --git a/templates/collection-post.tmpl b/templates/collection-post.tmpl index 6d2dfa0..6f34863 100644 --- a/templates/collection-post.tmpl +++ b/templates/collection-post.tmpl @@ -20,14 +20,14 @@ - {{if gt (len .Images) 0}}{{else}}{{end}} + {{if gt (len .Images) 0}}{{else}}{{end}} - {{range .Images}}{{else}}{{end}} + {{range .Images}}{{else}}{{end}} {{if .Collection.StyleSheet}}{{end}} {{if .Collection.RenderMathJax}} diff --git a/templates/collection-tags.tmpl b/templates/collection-tags.tmpl index 48cb475..021febc 100644 --- a/templates/collection-tags.tmpl +++ b/templates/collection-tags.tmpl @@ -23,10 +23,12 @@ + + {{if .Collection.StyleSheet}}{{end}} {{if .Collection.RenderMathJax}}