From fe04b580e8db4031c90a6413bdb1f69dac119471 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Wed, 9 Feb 2022 12:25:39 -0500 Subject: [PATCH] site: Expose root page to templates --- docs/kiln.1.scd | 3 +++ main.go | 10 +++++----- site.go | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/kiln.1.scd b/docs/kiln.1.scd index 244c20f..e135268 100644 --- a/docs/kiln.1.scd +++ b/docs/kiln.1.scd @@ -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*. diff --git a/main.go b/main.go index a2a57c5..c8bc27f 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/site.go b/site.go index c4aae12..140ae0d 100644 --- a/site.go +++ b/site.go @@ -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) }