mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
site: Expose root page to templates
This commit is contained in:
parent
f2944f0433
commit
fe04b580e8
|
@ -419,6 +419,9 @@ Site metadata contains the following data:
|
||||||
*Generated*
|
*Generated*
|
||||||
Site generation time.
|
Site generation time.
|
||||||
|
|
||||||
|
*Root*
|
||||||
|
The root page of the site.
|
||||||
|
|
||||||
Site metadata can be accessed from templates with the *site* function. See
|
Site metadata can be accessed from templates with the *site* function. See
|
||||||
*TEMPLATE FUNCTIONS*.
|
*TEMPLATE FUNCTIONS*.
|
||||||
|
|
||||||
|
|
10
main.go
10
main.go
|
@ -71,17 +71,17 @@ func (site *Site) run() error {
|
||||||
|
|
||||||
func (s *Site) runTask(task *Task) error {
|
func (s *Site) runTask(task *Task) error {
|
||||||
// Read content
|
// Read content
|
||||||
s.root = &Page{Path: "/", FilePath: "", URL: task.URL + "/"}
|
s.Root = &Page{Path: "/", FilePath: "", URL: task.URL + "/"}
|
||||||
if err := s.root.read("content", task, s); err != nil {
|
if err := s.Root.read("content", task, s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.root.sort()
|
s.Root.sort()
|
||||||
// Process content
|
// Process content
|
||||||
if err := s.root.process(s, task); err != nil {
|
if err := s.Root.process(s, task); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Write content
|
// Write content
|
||||||
if err := s.root.write(task.OutputDir, task); err != nil {
|
if err := s.Root.write(task.OutputDir, task); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Copy static files
|
// Copy static files
|
||||||
|
|
4
site.go
4
site.go
|
@ -17,9 +17,9 @@ type Site struct {
|
||||||
Params map[string]string `toml:"params"`
|
Params map[string]string `toml:"params"`
|
||||||
Permalinks map[string]string `toml:"permalinks"`
|
Permalinks map[string]string `toml:"permalinks"`
|
||||||
Generated time.Time `toml:"-"`
|
Generated time.Time `toml:"-"`
|
||||||
|
Root *Page `toml:"-"`
|
||||||
permalinks map[string]*template.Template
|
permalinks map[string]*template.Template
|
||||||
templates Templates
|
templates Templates
|
||||||
root *Page
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task represents a site build task.
|
// Task represents a site build task.
|
||||||
|
@ -125,5 +125,5 @@ func LoadSite(config string) (*Site, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) page(path string) *Page {
|
func (s *Site) page(path string) *Page {
|
||||||
return s.root.getPage(path)
|
return s.Root.getPage(path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue