gorum/views/posts.templ

73 lines
1.4 KiB
Text

package views
import (
"fmt"
"gitrepo.ru/neonxp/gorum/models"
"gitrepo.ru/neonxp/gorum/utils"
)
templ Posts(topic *models.Topic, topics []*models.Topic, nodes []*models.Post) {
@Layout() {
<h1>{ topic.Topic }</h1>
if len(topics) != 0 {
<table>
<thead>
<tr>
<th>Тема</th>
<th>Тем/Ответов</th>
<th>Дата</th>
<th>Автор</th>
</tr>
</thead>
<tbody>
for _, n := range topics {
@Topic(n)
}
</tbody>
</table>
}
if topic.Text != "" {
<article>
<header class="post-header">
<span>
if topic.Author != nil {
{ topic.Author.Username }
}
</span>
<span>
{ topic.CreatedAt.Format("15:04 02.01.2006") }
</span>
</header>
@templ.Raw(utils.MarkdownToHTML(topic.Text))
</article>
}
<hr/>
if len(nodes) == 0 {
<strong>Ответов нет</strong>
}
for _, n := range nodes {
@Post(n)
}
<hr/>
if isAuthorized(ctx) {
@NewPostForm(topic.ID)
} else {
<a href="/login">Войдите</a> чтобы ответить в тему.
}
}
}
templ Post(n *models.Post) {
<article id={ fmt.Sprintf("post%d", n.ID) }>
<header class="post-header">
<span>
{ n.Author.Username }
</span>
<span>
{ n.CreatedAt.Format("15:04 02.01.2006") }
</span>
</header>
@templ.Raw(utils.MarkdownToHTML(n.Text))
</article>
}