From c390a0c32720f6afe852bc7a3a3f64c3afe9e401 Mon Sep 17 00:00:00 2001 From: r Date: Fri, 11 Feb 2022 11:18:02 +0000 Subject: Add lists --- renderer/model.go | 13 +++++++++++++ renderer/renderer.go | 2 ++ 2 files changed, 15 insertions(+) (limited to 'renderer') diff --git a/renderer/model.go b/renderer/model.go index 4d09338..e7cfbfb 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -62,6 +62,19 @@ type TimelineData struct { PrevLink string } +type ListsData struct { + *CommonData + Lists []*mastodon.List +} + +type ListData struct { + *CommonData + List *mastodon.List + Accounts []*mastodon.Account + Q string + SearchAccounts []*mastodon.Account +} + type ThreadData struct { *CommonData Statuses []*mastodon.Status diff --git a/renderer/renderer.go b/renderer/renderer.go index 0d6776c..20a3c05 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -19,6 +19,8 @@ const ( NavPage = "nav.tmpl" RootPage = "root.tmpl" TimelinePage = "timeline.tmpl" + ListsPage = "lists.tmpl" + ListPage = "list.tmpl" ThreadPage = "thread.tmpl" QuickReplyPage = "quickreply.tmpl" NotificationPage = "notification.tmpl" -- cgit v1.2.3 From 2d49ff9fb4ea9b0e88df1621e954246bc1851de6 Mon Sep 17 00:00:00 2001 From: r Date: Wed, 30 Mar 2022 15:52:30 +0000 Subject: Switch to html/template --- renderer/renderer.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'renderer') diff --git a/renderer/renderer.go b/renderer/renderer.go index 20a3c05..6e50270 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -1,11 +1,11 @@ package renderer import ( + "html/template" "io" "regexp" "strconv" "strings" - "text/template" "time" "bloat/mastodon" @@ -54,10 +54,7 @@ func emojiFilter(content string, emojis []mastodon.Emoji) string { var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(>.*)( 0 { - content = spoiler + "
" + content - } +func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string { content = quoteRE.ReplaceAllString(content, `$1$2$3`) var replacements []string for _, e := range emojis { @@ -129,6 +126,10 @@ func withContext(data interface{}, ctx *Context) TemplateData { return TemplateData{data, ctx} } +func raw(s string) template.HTML { + return template.HTML(s) +} + type Renderer interface { Render(ctx *Context, writer io.Writer, page string, data interface{}) (err error) } @@ -148,6 +149,8 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) { "FormatTimeRFC3339": formatTimeRFC3339, "FormatTimeRFC822": formatTimeRFC822, "WithContext": withContext, + "HTML": template.HTMLEscapeString, + "Raw": raw, }).ParseGlob(templateGlobPattern) if err != nil { return -- cgit v1.2.3 From 2a014716216d445953b4832958e80c739bb02c2c Mon Sep 17 00:00:00 2001 From: r Date: Wed, 30 Mar 2022 16:58:31 +0000 Subject: Fix duration overflow time.Sub() returns int64 duration in nanoseconds, which can only represent around 290 years. --- renderer/renderer.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'renderer') diff --git a/renderer/renderer.go b/renderer/renderer.go index 6e50270..f1595a5 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -73,16 +73,15 @@ func displayInteractionCount(c int64) string { return "" } -func DurToStr(dur time.Duration) string { - s := dur.Seconds() +func durToStr(s int64) string { if s < 60 { return strconv.Itoa(int(s)) + "s" } - m := dur.Minutes() + m := s / 60 if m < 60*2 { return strconv.Itoa(int(m)) + "m" } - h := dur.Hours() + h := m / 60 if h < 24*2 { return strconv.Itoa(int(h)) + "h" } @@ -94,24 +93,24 @@ func DurToStr(dur time.Duration) string { if mo < 12*2 { return strconv.Itoa(int(mo)) + "mo" } - y := mo / 12 + y := d / 365 return strconv.Itoa(int(y)) + "y" } func timeSince(t time.Time) string { - d := time.Since(t) + d := time.Now().Unix() - t.Unix() if d < 0 { d = 0 } - return DurToStr(d) + return durToStr(d) } func timeUntil(t time.Time) string { - d := time.Until(t) + d := t.Unix() - time.Now().Unix() if d < 0 { d = 0 } - return DurToStr(d) + return durToStr(d) } func formatTimeRFC3339(t time.Time) string { -- cgit v1.2.3 From 4ad71587d821d8586d1fe648ad15f601a318662f Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 May 2022 17:25:58 +0000 Subject: Fix custom CSS --- renderer/renderer.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'renderer') diff --git a/renderer/renderer.go b/renderer/renderer.go index f1595a5..c6b3189 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -129,6 +129,10 @@ func raw(s string) template.HTML { return template.HTML(s) } +func rawCSS(s string) template.CSS { + return template.CSS(s) +} + type Renderer interface { Render(ctx *Context, writer io.Writer, page string, data interface{}) (err error) } @@ -150,6 +154,7 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) { "WithContext": withContext, "HTML": template.HTMLEscapeString, "Raw": raw, + "RawCSS": rawCSS, }).ParseGlob(templateGlobPattern) if err != nil { return -- cgit v1.2.3 From fcbe489138ff60a0bba716bb6c7684327d78558d Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 May 2022 17:27:33 +0000 Subject: Refactor duration formatting --- renderer/renderer.go | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'renderer') diff --git a/renderer/renderer.go b/renderer/renderer.go index c6b3189..7afeb14 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -73,44 +73,41 @@ func displayInteractionCount(c int64) string { return "" } -func durToStr(s int64) string { +func durUnit(s int64) (dur int64, unit string) { if s < 60 { - return strconv.Itoa(int(s)) + "s" + if s < 0 { + s = 0 + } + return s, "s" } m := s / 60 - if m < 60*2 { - return strconv.Itoa(int(m)) + "m" - } h := m / 60 - if h < 24*2 { - return strconv.Itoa(int(h)) + "h" + if h < 2 { + return m, "m" } d := h / 24 - if d < 30*2 { - return strconv.Itoa(int(d)) + "d" + if d < 2 { + return h, "h" } mo := d / 30 - if mo < 12*2 { - return strconv.Itoa(int(mo)) + "mo" + if mo < 2 { + return d, "d" } y := d / 365 - return strconv.Itoa(int(y)) + "y" + if y < 2 { + return mo, "mo" + } + return y, "y" } func timeSince(t time.Time) string { - d := time.Now().Unix() - t.Unix() - if d < 0 { - d = 0 - } - return durToStr(d) + d, u := durUnit(time.Now().Unix() - t.Unix()) + return strconv.FormatInt(d, 10) + u } func timeUntil(t time.Time) string { - d := t.Unix() - time.Now().Unix() - if d < 0 { - d = 0 - } - return durToStr(d) + d, u := durUnit(t.Unix() - time.Now().Unix()) + return strconv.FormatInt(d, 10) + u } func formatTimeRFC3339(t time.Time) string { -- cgit v1.2.3