replace method with field

This commit is contained in:
facundoolano 2024-02-12 15:38:26 -03:00
parent 0f2c2f37aa
commit 03da3b3770
2 changed files with 7 additions and 12 deletions

View file

@ -35,7 +35,8 @@ func Build() error {
}
site := Site{
layouts: make(map[string]templates.Template),
layouts: make(map[string]templates.Template),
templateIndex: make(map[string]*templates.Template),
}
// FIXME these sound like they should be site methods too
@ -100,6 +101,9 @@ func loadTemplates(site *Site) error {
} else {
site.pages = append(site.pages, *templ)
}
site.templateIndex[path] = templ
// TODO load tags
}
return nil
})
@ -111,7 +115,6 @@ func writeTarget(site *Site) error {
os.Mkdir(TARGET_DIR, FILE_RW_MODE)
// walk the source directory, creating directories and files at the target dir
templIndex := site.templateIndex()
return filepath.WalkDir(SRC_DIR, func(path string, entry fs.DirEntry, err error) error {
subpath, _ := filepath.Rel(SRC_DIR, path)
targetPath := filepath.Join(TARGET_DIR, subpath)
@ -120,7 +123,7 @@ func writeTarget(site *Site) error {
os.MkdirAll(targetPath, FILE_RW_MODE)
} else {
if templ, ok := templIndex[path]; ok {
if templ, ok := site.templateIndex[path]; ok {
// if a template was found at source, render it
content, err := site.render(templ)
if err != nil {

View file

@ -15,7 +15,7 @@ type Site struct {
pages []templates.Template
tags map[string]*templates.Template
renderCache map[string]string
templateIndex map[string]*templates.Template
}
func (site Site) render(templ *templates.Template) (string, error) {
@ -42,14 +42,6 @@ func (site Site) render(templ *templates.Template) (string, error) {
return content, err
}
func (site Site) templateIndex() map[string]*templates.Template {
templIndex := make(map[string]*templates.Template)
for _, templ := range append(site.posts, site.pages...) {
templIndex[templ.SrcPath] = &templ
}
return templIndex
}
func (site Site) baseContext() map[string]interface{} {
return map[string]interface{}{
"config": site.config,