diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-09-09 22:44:09 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-09-09 22:44:09 +0100 |
| commit | f1741a7faa9538e9b12ac60e0fbf6c7721a36059 (patch) | |
| tree | 2b70b14fc20a8520718910a0cd2e0134790c6f53 /pkg/html/service.go | |
Initial commit
Diffstat (limited to 'pkg/html/service.go')
| -rw-r--r-- | pkg/html/service.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/pkg/html/service.go b/pkg/html/service.go new file mode 100644 index 0000000..cba3a6c --- /dev/null +++ b/pkg/html/service.go @@ -0,0 +1,50 @@ +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\">" + if entry.KindName == "starred" { + str += "<b>" + } + str += "<a class=\"entry-title\" href=" + entry.Url + " target=\"_blank\">" + entry.KindEmoji + " " + entry.Title + "</a>" + if entry.KindName == "starred" { + str += "</b>" + } + str += " - <span class=\"entry-description\">" + entry.Description + "</span>" + str += " - <span class=\"entry-date\">" + date.Format(time.DateOnly) + "</span>" + str += "</span><br>" + } + + return str, nil +} |
