Add enrichment function for post bodies
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EnrichPost(body string) string {
|
||||||
|
lines := strings.Split(body, "\n")
|
||||||
|
for i, line := range lines {
|
||||||
|
if strings.HasPrefix(line, ">") {
|
||||||
|
escaped := template.HTMLEscapeString(line)
|
||||||
|
lines[i] = `<span class="greentext">` + escaped + `</span>`
|
||||||
|
} else {
|
||||||
|
lines[i] = template.HTMLEscapeString(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Join(lines, "<br />")
|
||||||
|
}
|
||||||
@@ -55,6 +55,7 @@ body {
|
|||||||
#catalog {
|
#catalog {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 2rem;
|
margin: 2rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.catalog-preview {
|
.catalog-preview {
|
||||||
@@ -62,8 +63,7 @@ body {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border: 2px solid rgba(111, 111, 111, 0.34);
|
border: 2px solid rgba(111, 111, 111, 0.34);
|
||||||
min-width: 140px;
|
width: 200px;
|
||||||
max-width: 200px;
|
|
||||||
max-height: 192px;
|
max-height: 192px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +187,10 @@ body {
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.greentext {
|
||||||
|
color: #789922
|
||||||
|
}
|
||||||
|
|
||||||
/* GENERAL LAYOUT */
|
/* GENERAL LAYOUT */
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package views
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dominicf2001/comfychan/internal/database"
|
"github.com/dominicf2001/comfychan/internal/database"
|
||||||
|
"github.com/dominicf2001/comfychan/internal/util"
|
||||||
"github.com/dominicf2001/comfychan/web/views/shared"
|
"github.com/dominicf2001/comfychan/web/views/shared"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@@ -21,7 +22,9 @@ templ ThreadPosts(posts []database.Post) {
|
|||||||
<span class="post-time">{ post.CreatedAt.Format("15:04") }</span>
|
<span class="post-time">{ post.CreatedAt.Format("15:04") }</span>
|
||||||
<span class="post-num">No. { strconv.Itoa(post.Id) }</span>
|
<span class="post-num">No. { strconv.Itoa(post.Id) }</span>
|
||||||
</header>
|
</header>
|
||||||
<p>{ post.Body }</p>
|
<p>
|
||||||
|
@templ.Raw(util.EnrichPost(post.Body))
|
||||||
|
</p>
|
||||||
</article>
|
</article>
|
||||||
<br/>
|
<br/>
|
||||||
}
|
}
|
||||||
@@ -71,7 +74,9 @@ templ Thread(board database.Board, thread database.Thread, posts []database.Post
|
|||||||
<span class="post-time">{ posts[0].CreatedAt.Format("15:04") }</span>
|
<span class="post-time">{ posts[0].CreatedAt.Format("15:04") }</span>
|
||||||
<span class="post-num">No. { strconv.Itoa(posts[0].Id) }</span>
|
<span class="post-num">No. { strconv.Itoa(posts[0].Id) }</span>
|
||||||
</header>
|
</header>
|
||||||
<p class="post-body">{ posts[0].Body }</p>
|
<p class="post-body">
|
||||||
|
@templ.Raw(util.EnrichPost(posts[0].Body))
|
||||||
|
</p>
|
||||||
</article>
|
</article>
|
||||||
<div hx-get={ fmt.Sprintf("/hx/%s/threads/%d/posts", board.Slug, thread.Id) } hx-trigger="refreshPosts from:body">
|
<div hx-get={ fmt.Sprintf("/hx/%s/threads/%d/posts", board.Slug, thread.Id) } hx-trigger="refreshPosts from:body">
|
||||||
@ThreadPosts(posts[1:])
|
@ThreadPosts(posts[1:])
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "github.com/dominicf2001/comfychan/internal/util"
|
||||||
|
|
||||||
type CatalogThreadPreview struct {
|
type CatalogThreadPreview struct {
|
||||||
Subject string
|
Subject string
|
||||||
@@ -17,7 +18,9 @@ templ ThreadsCatalog(previews []CatalogThreadPreview) {
|
|||||||
<img class="catalog-preview-img" src={ fmt.Sprintf("/static/img/posts/%s", preview.MediaPath) }/>
|
<img class="catalog-preview-img" src={ fmt.Sprintf("/static/img/posts/%s", preview.MediaPath) }/>
|
||||||
</a>
|
</a>
|
||||||
<h1><a href={ templ.SafeURL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a></h1>
|
<h1><a href={ templ.SafeURL(preview.ThreadURL) } class="catalog-preview-link">{ preview.Subject }</a></h1>
|
||||||
<p>{ preview.Body }</p>
|
<p>
|
||||||
|
@templ.Raw(util.EnrichPost(preview.Body))
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user