Skip to content

Commit 6f6185f

Browse files
committed
Add more date options to rendering.
1 parent c6dc263 commit 6f6185f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/tacker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"sort"
1212
"strings"
13+
"time"
1314

1415
"github.com/cbroglie/mustache"
1516
"gopkg.in/yaml.v2"
@@ -34,6 +35,7 @@ type Tacker struct {
3435
TagNames map[string]map[string]int
3536
TagIndex *Page
3637
Logger *log.Logger
38+
BuildTime time.Time
3739
}
3840

3941
func NewTacker(dir string) (*Tacker, error) {
@@ -151,6 +153,7 @@ func (t *Tacker) Log(format string, args ...interface{}) {
151153
}
152154

153155
func (t *Tacker) Tack() error {
156+
t.BuildTime = time.Now()
154157
t.Log("Tacking up %s (%d pages)", t.BaseDir, len(t.Pages))
155158

156159
if _, err := os.Stat(filepath.Join(t.BaseDir, TargetDir)); err != nil && !errors.Is(err, os.ErrNotExist) {
@@ -162,7 +165,6 @@ func (t *Tacker) Tack() error {
162165
}
163166

164167
for _, page := range t.Pages {
165-
t.Log("%s => %s (template: %s)", page.Permalink(), page.Slug, page.Template)
166168
if err := page.Generate(); err != nil {
167169
return err
168170
}

core/template.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import (
44
"io"
55
"sort"
66
"strings"
7+
"time"
78

89
"github.com/cbroglie/mustache"
910
)
1011

12+
const RFC822 string = "02 Jan 2006 15:04:05 -0700"
13+
1114
type Template struct {
1215
*mustache.Template
1316
}
@@ -32,6 +35,8 @@ func PageValues(p *Page, ctx *Page) map[string]interface{} {
3235
data["root"] = p.Root()
3336
if p.Post() {
3437
data["date"] = p.Date.Format("2006-01-02")
38+
data["date_rfc822"] = p.Date.Format(RFC822)
39+
data["date_rfc3339"] = p.Date.Format(time.RFC3339)
3540
data["year"] = p.Date.Format("2006")
3641
data["month"] = p.Date.Format("January")
3742
}
@@ -137,6 +142,9 @@ func (t *Template) Render(page *Page, w io.Writer) error {
137142
ctx["posts"] = PageListValues(limitPageList(posts, page, "posts_limit"), page)
138143
}
139144

145+
ctx["TACK_BUILD_DATE"] = page.Tacker.BuildTime.Local().Format(time.RFC3339)
146+
ctx["TACK_BUILD_DATE_RFC822"] = page.Tacker.BuildTime.Local().Format(RFC822)
147+
140148
return t.Template.FRender(w, ctx)
141149
}
142150

0 commit comments

Comments
 (0)