From b038d2c5020607ea378d40d2cffe9e4c6e6d01a2 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Thu, 29 Dec 2022 13:16:16 -0500 Subject: [PATCH] refactor: convert comments to a reusable template --- templates/comments.html | 25 ++++++++++++++++++++ templates/question.html | 52 ++--------------------------------------- 2 files changed, 27 insertions(+), 50 deletions(-) create mode 100644 templates/comments.html diff --git a/templates/comments.html b/templates/comments.html new file mode 100644 index 0000000..37e2af7 --- /dev/null +++ b/templates/comments.html @@ -0,0 +1,25 @@ +
+ + Show {{ (len .Comments) }} comments + +
+ {{ range $comment := .Comments }} +
+
+
+ {{ $comment.Text }} +
+
+ Commented {{ $comment.Timestamp }} by + {{ $comment.AuthorName }}. +
+
+
+ {{end}} +
+
diff --git a/templates/question.html b/templates/question.html index ac498f4..8360c23 100644 --- a/templates/question.html +++ b/templates/question.html @@ -47,31 +47,7 @@
{{ .question.Body }}
{{ if .question.Comments }} -
- - Show {{ (len .question.Comments) }} comments - -
- {{ range $comment := .question.Comments }} -
-
-
- {{ $comment.Text }} -
-
- Commented {{ $comment.Timestamp }} by - {{ $comment.AuthorName }}. -
-
-
- {{end}} -
-
+ {{ template "comments.html" .question }} {{end}} @@ -98,31 +74,7 @@ {{ if $answer.Comments }} -
- - Show {{ (len $answer.Comments) }} comments - -
- {{ range $comment := $answer.Comments }} -
-
-
- {{ $comment.Text }} -
-
- Commented {{ $comment.Timestamp }} by - {{ $comment.AuthorName }}. -
-
-
- {{end}} -
-
+ {{ template "comments.html" $answer }} {{end}}