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 += "" } str += "

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

" str += "
" group = true } currentDate = date str += "" str += "" if entry.KindName == "starred" { str += "" } str += entry.KindEmoji + " " + entry.Title if entry.KindName == "starred" { str += "" } str += "" str += "" + entry.Description + "" str += "on " + date.Format("02 Jan 2006") + "" str += "" } if group { str += "
" } return str, nil }