diff --git a/core/page.go b/core/page.go index 669790c..90983c3 100644 --- a/core/page.go +++ b/core/page.go @@ -259,17 +259,19 @@ func (p *Page) Generate() error { destDir := filepath.Join(append([]string{p.Tacker.BaseDir, TargetDir}, p.TargetDir()...)...) - p.Tacker.Log("Generating %s", p.Slug) - par := "-" - if p.Parent != nil { - par = p.Parent.DiskPath + if p.DiskPath != "" { + p.Tacker.Log("Generating %s", p.Slug) + par := "-" + if p.Parent != nil { + par = p.Parent.DiskPath + } + p.Tacker.Log(" - disk path: %s", p.DiskPath) + p.Tacker.Log(" - parent: %s", par) + p.Tacker.Log(" - permalink: %s", p.Permalink()) + p.Tacker.Log(" - destdir: %s", destDir) + p.Tacker.Log(" - ancestors: %s", strings.Join(a, " << ")) + p.Tacker.Log(" - siblings: %s", strings.Join(s, ", ")) } - p.Tacker.Log(" - disk path: %s", p.DiskPath) - p.Tacker.Log(" - parent: %s", par) - p.Tacker.Log(" - permalink: %s", p.Permalink()) - p.Tacker.Log(" - destdir: %s", destDir) - p.Tacker.Log(" - ancestors: %s", strings.Join(a, " << ")) - p.Tacker.Log(" - siblings: %s", strings.Join(s, ", ")) if err := os.MkdirAll(destDir, 0755); err != nil { return err @@ -291,7 +293,7 @@ func (p *Page) Generate() error { } for i := range p.Assets { - p.Tacker.Log("Copying ...%s", i) + p.Tacker.Log(" - copying %s", i) if err := os.MkdirAll(filepath.Dir(filepath.Join(destDir, i)), 0755); err != nil { return err } @@ -300,5 +302,31 @@ func (p *Page) Generate() error { } } + if dict, ok := p.Variables["extra_files"].(map[interface{}]interface{}); ok { + for k, v := range dict { + fn := k.(string) + templateName := v.(string) + if fn == "" || templateName == "" { + continue + } + + p.Tacker.Log(" - rendering %s", fn) + tpl, err := p.Tacker.FindTemplate(templateName) + if err != nil { + return fmt.Errorf("unable to load template '%s' for extra file '%s' when rendering '%s': %s", s, fn, p.Permalink(), err) + } + + f, err := os.OpenFile(filepath.Join(destDir, fn), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + return err + } + defer f.Close() + + if err := tpl.Render(p, f); err != nil { + return fmt.Errorf("unable to render template '%s' for extra file '%s' when rendering '%s': %s", s, fn, p.Permalink(), err) + } + } + } + return nil }