blob: 8a7a163fce8644ee1265c2db7dee628258b6a257 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package html
import (
"time"
"git.leonardobishop.net/history/pkg/database/sqlc"
)
type Service interface {
GenerateHtml([]sqlc.GetEntriesRow) (string, error)
}
type service struct{}
func NewService() Service {
return &service{}
}
func (s *service) GenerateHtml(entries []sqlc.GetEntriesRow) (string, error) {
var str string
var currentDate time.Time
for _, entry := range entries {
date, err := time.Parse(time.DateTime, entry.Timestamp)
if err != nil {
return "", err
}
if currentDate.Year() != date.Year() || currentDate.Month() != date.Month() {
str = str + "<h2>" + date.Format("January 2006") + "</h2>"
}
currentDate = date
str += "<span class=\"entry\">"
str += "<a class=\"entry-title\" href=" + entry.Url + " target=\"_blank\">"
if entry.KindName == "starred" {
str += "<b>"
}
str += entry.KindEmoji + " " + entry.Title
if entry.KindName == "starred" {
str += "</b>"
}
str += "</a>"
str += "<span class=\"entry-description\">" + entry.Description + "</span>"
str += "<i class=\"entry-date\">on " + date.Format("02 Jan 2006") + "</i>"
str += "</span>"
}
return str, nil
}
|