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 + "

" + date.Format("January 2006") + "

" } currentDate = date str += "" if entry.KindName == "starred" { str += "" } str += "" + entry.KindEmoji + " " + entry.Title + "" if entry.KindName == "starred" { str += "" } str += " - " + entry.Description + "" str += " - " + date.Format(time.DateOnly) + "" str += "
" } return str, nil }