2026-02-18 11:07:18 +00:00
|
|
|
package sitebuilder
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"html/template"
|
|
|
|
|
"net/url"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-02-19 10:21:27 +00:00
|
|
|
"lmika.dev/lmika/weiro/models/pubmodel"
|
2026-02-18 11:07:18 +00:00
|
|
|
)
|
|
|
|
|
|
2026-02-19 10:21:27 +00:00
|
|
|
func templateFns(site pubmodel.Site, opts Options) template.FuncMap {
|
2026-02-18 11:07:18 +00:00
|
|
|
return template.FuncMap{
|
|
|
|
|
"url_abs": func(basePath string) (string, error) {
|
2026-02-19 10:21:27 +00:00
|
|
|
if site.BaseURL == "" {
|
2026-02-18 11:07:18 +00:00
|
|
|
return basePath, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 10:21:27 +00:00
|
|
|
pu, err := url.Parse(site.BaseURL)
|
2026-02-18 11:07:18 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
pu.Path = filepath.Join(pu.Path, basePath)
|
|
|
|
|
return pu.String(), nil
|
|
|
|
|
},
|
|
|
|
|
"format_date": func(date time.Time) string {
|
|
|
|
|
loc := opts.RenderTZ
|
|
|
|
|
if loc == nil {
|
|
|
|
|
loc = time.Local
|
|
|
|
|
}
|
|
|
|
|
return date.In(loc).Format("02 Jan 2006")
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|