blob: a39c90dc7338a18d651f8895f3d6b4a5b0d9aa89 (
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
54
55
56
57
58
59
60
61
62
63
64
|
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
var group bool
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() {
if group {
str += "</div>"
}
str += "<h2>" + date.Format("January 2006") + "</h2>"
str += "<div class=\"entry-group\">"
group = true
}
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>"
}
if group {
str += "</div>"
}
return str, nil
}
|