♻️ Include template utils in theme repository
This commit is contained in:
parent
a475dacd60
commit
0ad5c9694f
|
@ -11,23 +11,24 @@ import (
|
|||
)
|
||||
|
||||
type fileSystemThemeRepository struct {
|
||||
dir fs.FS
|
||||
dir fs.FS
|
||||
funcMap template.FuncMap
|
||||
}
|
||||
|
||||
var helpers = template.FuncMap{
|
||||
"safeHTML": templateutil.SafeHTML,
|
||||
}
|
||||
|
||||
func NewFileSystemThemeRepository(dir fs.FS) theme.Repository {
|
||||
return &fileSystemThemeRepository{
|
||||
dir: dir,
|
||||
func NewFileSystemThemeRepository(dir fs.FS) (theme.Repository, error) {
|
||||
funcMap, err := templateutil.New(dir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot setup template.FuncMap for theme templates: %w", err)
|
||||
}
|
||||
|
||||
return &fileSystemThemeRepository{
|
||||
dir: dir,
|
||||
funcMap: funcMap,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (repo *fileSystemThemeRepository) Get(ctx context.Context) (*template.Template, error) {
|
||||
tpl, err := template.New("").
|
||||
Funcs(helpers).
|
||||
ParseFS(repo.dir, "baseof.html", "single.html")
|
||||
tpl, err := template.New("").Funcs(repo.funcMap).ParseFS(repo.dir, "*.html")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot find baseof template: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue