refactor: convert comments to a reusable template

This commit is contained in:
httpjamesm 2022-12-29 13:16:16 -05:00
parent e6915ae849
commit b038d2c502
2 changed files with 27 additions and 50 deletions

25
templates/comments.html Normal file
View File

@ -0,0 +1,25 @@
<details class="comments">
<summary>
Show <b>{{ (len .Comments) }} comments</b>
</summary>
<div class="comments-parent">
{{ range $comment := .Comments }}
<div class="comment-parent">
<div class="comment">
<div class="comment-body">
{{ $comment.Text }}
</div>
<div class="comment-author">
Commented {{ $comment.Timestamp }} by
<a
href="https://stackoverflow.com{{ $comment.AuthorURL }}"
target="_blank"
rel="noopener noreferrer"
>{{ $comment.AuthorName }}</a
>.
</div>
</div>
</div>
{{end}}
</div>
</details>

View File

@ -47,31 +47,7 @@
</div>
<div class="card-body">{{ .question.Body }}</div>
{{ if .question.Comments }}
<details class="comments">
<summary>
Show <b>{{ (len .question.Comments) }} comments</b>
</summary>
<div class="comments-parent">
{{ range $comment := .question.Comments }}
<div class="comment-parent">
<div class="comment">
<div class="comment-body">
{{ $comment.Text }}
</div>
<div class="comment-author">
Commented {{ $comment.Timestamp }} by
<a
href="https://stackoverflow.com{{ $comment.AuthorURL }}"
target="_blank"
rel="noopener noreferrer"
>{{ $comment.AuthorName }}</a
>.
</div>
</div>
</div>
{{end}}
</div>
</details>
{{ template "comments.html" .question }}
{{end}}
</div>
@ -98,31 +74,7 @@
</div>
</div>
{{ if $answer.Comments }}
<details class="comments">
<summary>
Show <b>{{ (len $answer.Comments) }} comments</b>
</summary>
<div class="comments-parent">
{{ range $comment := $answer.Comments }}
<div class="comment-parent">
<div class="comment">
<div class="comment-body">
{{ $comment.Text }}
</div>
<div class="comment-author">
Commented {{ $comment.Timestamp }} by
<a
href="https://stackoverflow.com{{ $comment.AuthorURL }}"
target="_blank"
rel="noopener noreferrer"
>{{ $comment.AuthorName }}</a
>.
</div>
</div>
</div>
{{end}}
</div>
</details>
{{ template "comments.html" $answer }}
{{end}}
</div>
<hr class="answer-divider" />