mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
site: Add Generated variable
This also removes the need for the feed Updated variable.
This commit is contained in:
parent
5a674c0ea5
commit
686f6a78d6
2
dir.go
2
dir.go
|
@ -204,7 +204,6 @@ func (d Dir) buildFeed(cfg *Site, feed Feed) ([]byte, error) {
|
||||||
type Feed struct {
|
type Feed struct {
|
||||||
Title string
|
Title string
|
||||||
Permalink string
|
Permalink string
|
||||||
Updated time.Time
|
|
||||||
Pages []*Page
|
Pages []*Page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +216,6 @@ func (d Dir) buildFeed(cfg *Site, feed Feed) ([]byte, error) {
|
||||||
data := Feed{
|
data := Feed{
|
||||||
Title: feed.Title,
|
Title: feed.Title,
|
||||||
Permalink: d.Permalink,
|
Permalink: d.Permalink,
|
||||||
Updated: time.Now(),
|
|
||||||
Pages: d.Pages,
|
Pages: d.Pages,
|
||||||
}
|
}
|
||||||
if err := tmpl.Execute(&b, data); err != nil {
|
if err := tmpl.Execute(&b, data); err != nil {
|
||||||
|
|
|
@ -637,6 +637,8 @@ Site metadata contains the following data:
|
||||||
: The URLs of the site.
|
: The URLs of the site.
|
||||||
| Params
|
| Params
|
||||||
: Extra parameters specified in configuration.
|
: Extra parameters specified in configuration.
|
||||||
|
| Generated
|
||||||
|
: Site generation time.
|
||||||
|
|
||||||
To configure these variables, see *CONFIGURATION*.
|
To configure these variables, see *CONFIGURATION*.
|
||||||
|
|
||||||
|
|
6
site.go
6
site.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
@ -15,6 +16,7 @@ type Site struct {
|
||||||
Tasks []*Task `toml:"tasks"`
|
Tasks []*Task `toml:"tasks"`
|
||||||
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:"-"`
|
||||||
permalinks map[string]*template.Template
|
permalinks map[string]*template.Template
|
||||||
templates Templates
|
templates Templates
|
||||||
root *Dir
|
root *Dir
|
||||||
|
@ -58,7 +60,9 @@ func LoadSite(config string) (*Site, error) {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
site := &Site{}
|
site := &Site{
|
||||||
|
Generated: time.Now(),
|
||||||
|
}
|
||||||
if err := toml.NewDecoder(f).Decode(site); err != nil {
|
if err := toml.NewDecoder(f).Decode(site); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
<id>{{ index site.URLs 0 }}{{ .Permalink }}</id>
|
<id>{{ index site.URLs 0 }}{{ .Permalink }}</id>
|
||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
<updated>{{ .Updated.Format "2006-01-02T15:04:05Z07:00" }}</updated>
|
<updated>{{ site.Generated.Format "2006-01-02T15:04:05Z07:00" }}</updated>
|
||||||
<link href="{{ index site.URLs 0 | safeURL }}{{ .Permalink }}" rel="alternate"/>
|
<link href="{{ index site.URLs 0 | safeURL }}{{ .Permalink }}" rel="alternate"/>
|
||||||
{{ range .Pages }}<entry>
|
{{ range .Pages }}<entry>
|
||||||
<id>{{ index site.URLs 0 }}{{ .Permalink }}</id>
|
<id>{{ index site.URLs 0 }}{{ .Permalink }}</id>
|
||||||
|
|
Loading…
Reference in a new issue