32 lines
645 B
Go
32 lines
645 B
Go
package fs
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"html/template"
|
|
"io/fs"
|
|
|
|
"source.toby3d.me/toby3d/home/internal/theme"
|
|
)
|
|
|
|
type fileSystemThemeRepository struct {
|
|
dir fs.FS
|
|
funcMap template.FuncMap
|
|
}
|
|
|
|
func NewFileSystemThemeRepository(dir fs.FS, funcMap template.FuncMap) theme.Repository {
|
|
return &fileSystemThemeRepository{
|
|
dir: dir,
|
|
funcMap: funcMap,
|
|
}
|
|
}
|
|
|
|
func (repo *fileSystemThemeRepository) Get(ctx context.Context) (*template.Template, error) {
|
|
tpl, err := template.New("").Funcs(repo.funcMap).ParseFS(repo.dir, "*.html")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot find baseof template: %w", err)
|
|
}
|
|
|
|
return tpl, nil
|
|
}
|