diff --git a/docs/kiln.1.scd b/docs/kiln.1.scd index 494db9b..3af2efd 100644 --- a/docs/kiln.1.scd +++ b/docs/kiln.1.scd @@ -132,6 +132,20 @@ The following keys are supported: --- ``` +*template* + Optionally specifies the name of the template to use when building this + page. If unspecified, defaults to "page" for regular pages and "index" for + index pages. + + Example: + + ``` + --- + title: About me + template: about + --- + ``` + *params* Specifies extra parameters to be provided to templates. diff --git a/page.go b/page.go index 37ffb1d..93bfd16 100644 --- a/page.go +++ b/page.go @@ -22,6 +22,7 @@ type Page struct { Date time.Time `yaml:"date"` Weight int `yaml:"weight"` Outputs []string `yaml:"outputs"` + Template string `yaml:"template"` Params map[string]interface{} `yaml:"params"` Path string `yaml:"-"` FilePath string `yaml:"-"` @@ -193,7 +194,11 @@ func (p *Page) process(cfg *Site, task *Task) error { if task.TemplateExt != "" { // Create index if p.index { - tmpl, ok := cfg.templates.FindTemplate(p.FilePath, "index"+task.TemplateExt) + tmplName := p.Template + if tmplName == "" { + tmplName = "index" + } + tmpl, ok := cfg.templates.FindTemplate(p.FilePath, tmplName+task.TemplateExt) if ok { var b strings.Builder if err := tmpl.Execute(&b, p); err != nil { @@ -205,8 +210,12 @@ func (p *Page) process(cfg *Site, task *Task) error { // Process pages for i := range p.Pages { + tmplName := p.Pages[i].Template + if tmplName == "" { + tmplName = "page" + } var b strings.Builder - tmpl, ok := cfg.templates.FindTemplate(p.FilePath, "page"+task.TemplateExt) + tmpl, ok := cfg.templates.FindTemplate(p.FilePath, tmplName+task.TemplateExt) if ok { if err := tmpl.Execute(&b, p.Pages[i]); err != nil { return err