aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorFChannel <>2021-07-03 18:39:34 -0700
committerFChannel <>2021-07-03 18:39:34 -0700
commitcf86acee94652ac7cd8e8f313e6abf6c9901c398 (patch)
treee8e9d1157e2d64eb8d8f3baa1f8694bd3e7e108d /database.go
parentab6edbbe8044d5a3c7d9456bd15e3a74af35111a (diff)
add some styling to news pull request
Diffstat (limited to 'database.go')
-rw-r--r--database.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/database.go b/database.go
index baae16a..edab4f6 100644
--- a/database.go
+++ b/database.go
@@ -7,6 +7,7 @@ import (
"sort"
"strings"
"time"
+ "html/template"
_ "github.com/lib/pq"
)
@@ -1546,10 +1547,15 @@ func getNewsFromDB(db *sql.DB, limit int) []NewsItem {
defer rows.Close()
for rows.Next() {
n := NewsItem{}
- err = rows.Scan(&n.Title, &n.Content, &n.Time)
+ var content string
+ err = rows.Scan(&n.Title, &content, &n.Time)
if CheckError(err, "error scanning news from db") != nil {
return news
}
+
+ content = strings.ReplaceAll(content, "\n", "<br>")
+ n.Content = template.HTML(content)
+
news = append(news, n)
}
@@ -1558,6 +1564,7 @@ func getNewsFromDB(db *sql.DB, limit int) []NewsItem {
func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) {
var news NewsItem
+ var content string
query := `select title, content, time from newsItem where time=$1 limit 1`
rows, err := db.Query(query, timestamp)
@@ -1568,11 +1575,14 @@ func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) {
defer rows.Close()
rows.Next()
- err = rows.Scan(&news.Title, &news.Content, &news.Time)
+ err = rows.Scan(&news.Title, &content, &news.Time)
if err != nil {
return news, err
}
+
+ content = strings.ReplaceAll(content, "\n", "<br>")
+ news.Content = template.HTML(content)
return news, nil
}