diff options
author | r <r@freesoftwareextremist.com> | 2019-12-21 05:48:06 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2019-12-21 05:48:06 +0000 |
commit | 889f8da49637e908f203d6d9d195f7d585f8cd03 (patch) | |
tree | 705431057471930b1f38f70169be07d643aa5662 /renderer | |
parent | 3280af21ed1a82aa2b964ae098596b2f13a5fc22 (diff) | |
download | bloat-889f8da49637e908f203d6d9d195f7d585f8cd03.tar.gz bloat-889f8da49637e908f203d6d9d195f7d585f8cd03.zip |
Use local url for for mentioned users
Diffstat (limited to 'renderer')
-rw-r--r-- | renderer/renderer.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/renderer/renderer.go b/renderer/renderer.go index 3eb0457..9bbe06e 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -28,7 +28,8 @@ type renderer struct { func NewRenderer(templateGlobPattern string) (r *renderer, err error) { t := template.New("default") t, err = t.Funcs(template.FuncMap{ - "WithEmojis": WithEmojis, + "EmojiFilter": EmojiFilter, + "StatusContentFilter": StatusContentFilter, "DisplayInteractionCount": DisplayInteractionCount, "TimeSince": TimeSince, "FormatTimeRFC3339": FormatTimeRFC3339, @@ -70,12 +71,24 @@ func (r *renderer) RenderUserPage(ctx context.Context, writer io.Writer, data *U return r.template.ExecuteTemplate(writer, "user.tmpl", data) } -func WithEmojis(content string, emojis []mastodon.Emoji) string { - var emojiNameContentPair []string + +func EmojiFilter(content string, emojis []mastodon.Emoji) string { + var replacements []string + for _, e := range emojis { + replacements = append(replacements, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" />") + } + return strings.NewReplacer(replacements...).Replace(content) +} + +func StatusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string { + var replacements []string for _, e := range emojis { - emojiNameContentPair = append(emojiNameContentPair, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" />") + replacements = append(replacements, ":"+e.ShortCode+":", "<img class=\"status-emoji\" src=\""+e.URL+"\" alt=\""+e.ShortCode+"\" />") + } + for _, m := range mentions { + replacements = append(replacements, "\""+m.URL+"\"", "\"/user/"+m.ID+"\"") } - return strings.NewReplacer(emojiNameContentPair...).Replace(content) + return strings.NewReplacer(replacements...).Replace(content) } func DisplayInteractionCount(c int64) string { |