feat: better PDF

This commit is contained in:
2025-08-24 00:24:40 +02:00
parent 0267e6e578
commit 5b664234e9
18 changed files with 540 additions and 228 deletions

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"html/template"
"math"
"strings"
"time"
)
@@ -16,11 +15,9 @@ var htmlTemplate string
//go:embed assets/style.css
var style template.CSS
//go:embed assets/ch-cross.svg
var chCross template.HTML
func (r Report) ChCross() template.HTML {
return chCross
type tmpler struct {
Report
Style template.CSS
}
func (r Report) ToHTML() string {
@@ -32,15 +29,13 @@ func (r Report) ToHTML() string {
"time": fmtDateTime,
"date": fmtDate,
"duration": fmtDuration,
"brakes": func(text string) template.HTML {
return template.HTML(strings.ReplaceAll(template.HTMLEscapeString(text), "\n", "<br>"))
},
}).Parse(htmlTemplate))
r.Style = style
buf := new(bytes.Buffer)
_ = tmpl.Execute(buf, r)
err := tmpl.Execute(buf, tmpler{r, style})
if err != nil {
panic(err)
}
return buf.String()
}
@@ -62,12 +57,12 @@ func fmtDuration(d time.Duration) string {
return fmt.Sprintf("%.2f h", d.Hours())
}
func (r Report) Total() string {
func (r Report) Total() time.Duration {
dur := time.Duration(0)
for _, i := range r.Issues {
dur += i.Duration
}
return r.applyRate(dur)
return dur
}