site: Expose root page to templates

This commit is contained in:
adnano 2022-02-09 12:25:39 -05:00
parent 13ff1a687c
commit e3a39e45ee
3 changed files with 10 additions and 7 deletions

View file

@ -419,6 +419,9 @@ Site metadata contains the following data:
*Generated*
Site generation time.
*Root*
The root page of the site.
Site metadata can be accessed from templates with the *site* function. See
*TEMPLATE FUNCTIONS*.

10
main.go
View file

@ -71,17 +71,17 @@ func (site *Site) run() error {
func (s *Site) runTask(task *Task) error {
// Read content
s.root = &Page{Path: "/", FilePath: "", URL: task.URL + "/"}
if err := s.root.read("content", task, s); err != nil {
s.Root = &Page{Path: "/", FilePath: "", URL: task.URL + "/"}
if err := s.Root.read("content", task, s); err != nil {
return err
}
s.root.sort()
s.Root.sort()
// Process content
if err := s.root.process(s, task); err != nil {
if err := s.Root.process(s, task); err != nil {
return err
}
// Write content
if err := s.root.write(task.OutputDir, task); err != nil {
if err := s.Root.write(task.OutputDir, task); err != nil {
return err
}
// Copy static files

View file

@ -17,9 +17,9 @@ type Site struct {
Params map[string]string `toml:"params"`
Permalinks map[string]string `toml:"permalinks"`
Generated time.Time `toml:"-"`
Root *Page `toml:"-"`
permalinks map[string]*template.Template
templates Templates
root *Page
}
// Task represents a site build task.
@ -125,5 +125,5 @@ func LoadSite(config string) (*Site, error) {
}
func (s *Site) page(path string) *Page {
return s.root.getPage(path)
return s.Root.getPage(path)
}