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*
|
||||
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
10
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
|
||||
|
|
4
site.go
4
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue