mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
config: Make templates private
This commit is contained in:
parent
12ddad63e4
commit
13b8bb7ff3
19
config.go
19
config.go
|
@ -11,11 +11,12 @@ import (
|
||||||
|
|
||||||
// Config contains site configuration.
|
// Config contains site configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Title string `toml:"title"` // site title
|
Title string
|
||||||
URLs []string `toml:"urls"` // site URLs
|
URLs []string
|
||||||
Feeds map[string]string `toml:"feeds"` // site feeds
|
Feeds map[string]string
|
||||||
Tasks map[string]*Task `toml:"tasks"` // site tasks
|
Tasks map[string]*Task
|
||||||
Templates *Templates `toml:"-"` // site templates
|
Permalinks map[string]string
|
||||||
|
templates *Templates
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task represents a site build task.
|
// Task represents a site build task.
|
||||||
|
@ -58,8 +59,8 @@ func (c *Config) LoadTemplates(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load templates
|
// Load templates
|
||||||
c.Templates = NewTemplates()
|
c.templates = NewTemplates()
|
||||||
c.Templates.Funcs(map[string]interface{}{
|
c.templates.Funcs(map[string]interface{}{
|
||||||
"site": func() Site {
|
"site": func() Site {
|
||||||
return Site{
|
return Site{
|
||||||
Title: c.Title,
|
Title: c.Title,
|
||||||
|
@ -67,7 +68,7 @@ func (c *Config) LoadTemplates(path string) error {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"partial": func(name string, data interface{}) (interface{}, error) {
|
"partial": func(name string, data interface{}) (interface{}, error) {
|
||||||
t, ok := c.Templates.FindPartial(name)
|
t, ok := c.templates.FindPartial(name)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("Error: partial %q not found", name)
|
return "", fmt.Errorf("Error: partial %q not found", name)
|
||||||
}
|
}
|
||||||
|
@ -78,5 +79,5 @@ func (c *Config) LoadTemplates(path string) error {
|
||||||
return b.String(), nil
|
return b.String(), nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return c.Templates.Load(path)
|
return c.templates.Load(path)
|
||||||
}
|
}
|
||||||
|
|
6
dir.go
6
dir.go
|
@ -92,7 +92,7 @@ func (d *Dir) Process(cfg *Config, task *Task) error {
|
||||||
if task.TemplateExt != "" {
|
if task.TemplateExt != "" {
|
||||||
// Create index
|
// Create index
|
||||||
if d.index != nil {
|
if d.index != nil {
|
||||||
tmpl, ok := cfg.Templates.FindTemplate(d.Path, "index"+task.TemplateExt)
|
tmpl, ok := cfg.templates.FindTemplate(d.Path, "index"+task.TemplateExt)
|
||||||
if ok {
|
if ok {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
if err := tmpl.Execute(&b, d); err != nil {
|
if err := tmpl.Execute(&b, d); err != nil {
|
||||||
|
@ -105,7 +105,7 @@ func (d *Dir) Process(cfg *Config, task *Task) error {
|
||||||
// Process pages
|
// Process pages
|
||||||
for i := range d.Pages {
|
for i := range d.Pages {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
tmpl, ok := cfg.Templates.FindTemplate(d.Path, "page"+task.TemplateExt)
|
tmpl, ok := cfg.templates.FindTemplate(d.Path, "page"+task.TemplateExt)
|
||||||
if ok {
|
if ok {
|
||||||
if err := tmpl.Execute(&b, d.Pages[i]); err != nil {
|
if err := tmpl.Execute(&b, d.Pages[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -132,7 +132,7 @@ func (d *Dir) Process(cfg *Config, task *Task) error {
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
Entries: d.Pages,
|
Entries: d.Pages,
|
||||||
}
|
}
|
||||||
tmpl, ok := cfg.Templates.FindTemplate(d.Path, "atom.xml")
|
tmpl, ok := cfg.templates.FindTemplate(d.Path, "atom.xml")
|
||||||
if ok {
|
if ok {
|
||||||
if err := tmpl.Execute(&b, feed); err != nil {
|
if err := tmpl.Execute(&b, feed); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue