From 5977781f17c2bc27e110d88187169a3883b31602 Mon Sep 17 00:00:00 2001 From: f0x Date: Fri, 10 Sep 2021 23:37:38 +0200 Subject: [PATCH] abstract status from thread to avoid copy-pasting --- internal/web/base.go | 2 +- internal/web/{status.go => thread.go} | 8 +- web/template/status.tmpl | 122 ++++++-------------------- web/template/thread.tmpl | 19 ++++ 4 files changed, 49 insertions(+), 102 deletions(-) rename internal/web/{status.go => thread.go} (92%) create mode 100644 web/template/thread.tmpl diff --git a/internal/web/base.go b/internal/web/base.go index 896e3e2a4..2759c3f9e 100644 --- a/internal/web/base.go +++ b/internal/web/base.go @@ -97,7 +97,7 @@ func (m *Module) Route(s router.Router) error { s.AttachHandler(http.MethodGet, "/", m.baseHandler) // serve statuses - s.AttachHandler(http.MethodGet, "/:user/statuses/:id", m.statusTemplateHandler) + s.AttachHandler(http.MethodGet, "/:user/statuses/:id", m.threadTemplateHandler) // 404 handler s.AttachNoRouteHandler(m.NotFoundHandler) diff --git a/internal/web/status.go b/internal/web/thread.go similarity index 92% rename from internal/web/status.go rename to internal/web/thread.go index e108a9a36..c9dd312ec 100644 --- a/internal/web/status.go +++ b/internal/web/thread.go @@ -30,9 +30,9 @@ type StatusLink struct { ID string `uri:"id" binding:"required"` } -func (m *Module) statusTemplateHandler(c *gin.Context) { - l := m.log.WithField("func", "statusTemplateGET") - l.Trace("rendering status template") +func (m *Module) threadTemplateHandler(c *gin.Context) { + l := m.log.WithField("func", "threadTemplateGET") + l.Trace("rendering thread template") var statusLink StatusLink @@ -73,7 +73,7 @@ func (m *Module) statusTemplateHandler(c *gin.Context) { return } - c.HTML(http.StatusOK, "status.tmpl", gin.H{ + c.HTML(http.StatusOK, "thread.tmpl", gin.H{ "instance": instance, "status": status, "context": context, diff --git a/web/template/status.tmpl b/web/template/status.tmpl index 47cd89764..c561edd57 100644 --- a/web/template/status.tmpl +++ b/web/template/status.tmpl @@ -1,100 +1,28 @@ -{{ template "header.tmpl" .}} -
-
- {{range .context.Ancestors}} -
- - {{.Account.DisplayName}} - @{{.Account.Username}} -
- {{.Content |noescape}} -
- {{with .MediaAttachments}} - + +{{.Account.DisplayName}} +@{{.Account.Username}} +
+ {{.Content |noescape}} +
+{{with .MediaAttachments}} + - {{end}} -
- - {{.status.Account.DisplayName}} - @{{.status.Account.Username}} -
- {{.status.Content |noescape}} -
- {{with .status.MediaAttachments}} - - {{end}} -
-
{{.status.CreatedAt | timestamp}}
-
-
{{.status.Visibility | visibilityIcon}}
-
{{.status.RepliesCount}}
-
{{.status.ReblogsCount}}
-
{{.status.FavouritesCount}}
-
-
- View toot -
- {{range .context.Descendants}} -
- - {{.Account.DisplayName}} - @{{.Account.Username}} -
- {{.Content |noescape}} -
- {{with .MediaAttachments}} - - {{end}} -
-
{{.CreatedAt | timestamp}}
-
-
{{.Visibility | visibilityIcon}}
-
{{.RepliesCount}}
-
{{.ReblogsCount}}
-
{{.FavouritesCount}}
-
-
- View toot -
+ {{.Description}} + {{end}}
-
-{{ template "footer.tmpl" .}} \ No newline at end of file +{{end}} +
+
{{.CreatedAt | timestamp}}
+
+
{{.Visibility | visibilityIcon}}
+
{{.RepliesCount}}
+
{{.ReblogsCount}}
+
{{.FavouritesCount}}
+
+
+View toot \ No newline at end of file diff --git a/web/template/thread.tmpl b/web/template/thread.tmpl new file mode 100644 index 000000000..d0f003b91 --- /dev/null +++ b/web/template/thread.tmpl @@ -0,0 +1,19 @@ +{{ template "header.tmpl" .}} +
+
+ {{range .context.Ancestors}} +
+ {{ template "status.tmpl" .}} +
+ {{end}} +
+ {{ template "status.tmpl" .status}} +
+ {{range .context.Descendants}} +
+ {{ template "status.tmpl" .}} +
+ {{end}} +
+
+{{ template "footer.tmpl" .}} \ No newline at end of file