mirror of
https://github.com/facundoolano/jorge.git
synced 2025-01-13 20:03:26 +01:00
replace method with field
This commit is contained in:
parent
0f2c2f37aa
commit
03da3b3770
2 changed files with 7 additions and 12 deletions
|
@ -35,7 +35,8 @@ func Build() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
site := Site{
|
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
|
// FIXME these sound like they should be site methods too
|
||||||
|
@ -100,6 +101,9 @@ func loadTemplates(site *Site) error {
|
||||||
} else {
|
} else {
|
||||||
site.pages = append(site.pages, *templ)
|
site.pages = append(site.pages, *templ)
|
||||||
}
|
}
|
||||||
|
site.templateIndex[path] = templ
|
||||||
|
|
||||||
|
// TODO load tags
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -111,7 +115,6 @@ func writeTarget(site *Site) error {
|
||||||
os.Mkdir(TARGET_DIR, FILE_RW_MODE)
|
os.Mkdir(TARGET_DIR, FILE_RW_MODE)
|
||||||
|
|
||||||
// walk the source directory, creating directories and files at the target dir
|
// 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 {
|
return filepath.WalkDir(SRC_DIR, func(path string, entry fs.DirEntry, err error) error {
|
||||||
subpath, _ := filepath.Rel(SRC_DIR, path)
|
subpath, _ := filepath.Rel(SRC_DIR, path)
|
||||||
targetPath := filepath.Join(TARGET_DIR, subpath)
|
targetPath := filepath.Join(TARGET_DIR, subpath)
|
||||||
|
@ -120,7 +123,7 @@ func writeTarget(site *Site) error {
|
||||||
os.MkdirAll(targetPath, FILE_RW_MODE)
|
os.MkdirAll(targetPath, FILE_RW_MODE)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if templ, ok := templIndex[path]; ok {
|
if templ, ok := site.templateIndex[path]; ok {
|
||||||
// if a template was found at source, render it
|
// if a template was found at source, render it
|
||||||
content, err := site.render(templ)
|
content, err := site.render(templ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -15,7 +15,7 @@ type Site struct {
|
||||||
pages []templates.Template
|
pages []templates.Template
|
||||||
tags map[string]*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) {
|
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
|
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{} {
|
func (site Site) baseContext() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"config": site.config,
|
"config": site.config,
|
||||||
|
|
Loading…
Reference in a new issue