From 686f6a78d6f6c891ae9cfe5269054bd9eb1a7fc3 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Sat, 2 Oct 2021 16:25:01 -0400 Subject: [PATCH] site: Add Generated variable This also removes the need for the feed Updated variable. --- dir.go | 2 -- docs/kiln.1.scd | 2 ++ site.go | 6 +++++- templates/_default/atom.xml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dir.go b/dir.go index 917c626..8738697 100644 --- a/dir.go +++ b/dir.go @@ -204,7 +204,6 @@ func (d Dir) buildFeed(cfg *Site, feed Feed) ([]byte, error) { type Feed struct { Title string Permalink string - Updated time.Time Pages []*Page } @@ -217,7 +216,6 @@ func (d Dir) buildFeed(cfg *Site, feed Feed) ([]byte, error) { data := Feed{ Title: feed.Title, Permalink: d.Permalink, - Updated: time.Now(), Pages: d.Pages, } if err := tmpl.Execute(&b, data); err != nil { diff --git a/docs/kiln.1.scd b/docs/kiln.1.scd index b654aae..fd94f9c 100644 --- a/docs/kiln.1.scd +++ b/docs/kiln.1.scd @@ -637,6 +637,8 @@ Site metadata contains the following data: : The URLs of the site. | Params : Extra parameters specified in configuration. +| Generated +: Site generation time. To configure these variables, see *CONFIGURATION*. diff --git a/site.go b/site.go index 42972b6..653c3d8 100644 --- a/site.go +++ b/site.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "text/template" + "time" "github.com/pelletier/go-toml" ) @@ -15,6 +16,7 @@ type Site struct { Tasks []*Task `toml:"tasks"` Params map[string]string `toml:"params"` Permalinks map[string]string `toml:"permalinks"` + Generated time.Time `toml:"-"` permalinks map[string]*template.Template templates Templates root *Dir @@ -58,7 +60,9 @@ func LoadSite(config string) (*Site, error) { } defer f.Close() - site := &Site{} + site := &Site{ + Generated: time.Now(), + } if err := toml.NewDecoder(f).Decode(site); err != nil { return nil, err } diff --git a/templates/_default/atom.xml b/templates/_default/atom.xml index 553da4b..b4f005b 100644 --- a/templates/_default/atom.xml +++ b/templates/_default/atom.xml @@ -2,7 +2,7 @@ {{ index site.URLs 0 }}{{ .Permalink }} {{ .Title }} -{{ .Updated.Format "2006-01-02T15:04:05Z07:00" }} +{{ site.Generated.Format "2006-01-02T15:04:05Z07:00" }} {{ range .Pages }} {{ index site.URLs 0 }}{{ .Permalink }}