site: Expose root page to templates

This commit is contained in:
Adnan Maolood 2022-02-09 12:25:39 -05:00
parent f2944f0433
commit fe04b580e8
3 changed files with 10 additions and 7 deletions

View file

@ -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
View file

@ -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

View file

@ -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)
} }