aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--renderer/renderer.go23
-rw-r--r--templates/notification.tmpl6
-rw-r--r--templates/status.tmpl6
-rw-r--r--templates/user.tmpl2
4 files changed, 25 insertions, 12 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 {
diff --git a/templates/notification.tmpl b/templates/notification.tmpl
index da6164b..271597b 100644
--- a/templates/notification.tmpl
+++ b/templates/notification.tmpl
@@ -11,7 +11,7 @@
</a>
<div>
<div>
- <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>
+ <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<span class="icon dripicons-user-group"></span>
followed you
</div>
@@ -31,7 +31,7 @@
</a>
<div>
<div>
- <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>
+ <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<span class="icon dripicons-retweet retweeted"></span>
retweeted your post
</div>
@@ -46,7 +46,7 @@
</a>
<div>
<div>
- <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>
+ <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<span class="icon dripicons-star liked"></span>
liked your post
</div>
diff --git a/templates/status.tmpl b/templates/status.tmpl
index 618398f..b1babf6 100644
--- a/templates/status.tmpl
+++ b/templates/status.tmpl
@@ -4,7 +4,7 @@
<a href="/user/{{.Account.ID}}" >
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
</a>
- <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>
+ <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<span class="icon dripicons-retweet retweeted"></span>
retweeted
</div>
@@ -22,7 +22,7 @@
<div class="status">
{{if not .HideAccountInfo}}
<div class="status-name">
- <span class="status-dname"> {{WithEmojis .Account.DisplayName .Account.Emojis}} </span>
+ <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<a href="/user/{{.Account.ID}}" >
<span class="status-uname"> {{.Account.Acct}} </span>
</a>
@@ -41,7 +41,7 @@
{{end}}
{{end}}
</div>
- <div class="status-content"> {{WithEmojis .Content .Emojis}} </div>
+ <div class="status-content"> {{StatusContentFilter .Content .Emojis .Mentions}} </div>
<div class="status-media-container">
{{range .MediaAttachments}}
{{if eq .Type "image"}}
diff --git a/templates/user.tmpl b/templates/user.tmpl
index 3347f92..e1a782a 100644
--- a/templates/user.tmpl
+++ b/templates/user.tmpl
@@ -9,7 +9,7 @@
</div>
<div class="user-profile-details-container">
<div>
- <span class="status-dname"> {{WithEmojis .User.DisplayName .User.Emojis}} </span>
+ <span class="status-dname"> {{EmojiFilter .User.DisplayName .User.Emojis}} </span>
<span class="status-uname"> {{.User.Acct}} </span>
</div>
<div>