From 00bcc79b15915a2f4aa4aeed4e4a0019962185fd Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Mon, 6 Jan 2025 10:25:33 -0300 Subject: [PATCH] feat(blog): creation and modified date --- handlers/pages/blog.templ | 40 +++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/handlers/pages/blog.templ b/handlers/pages/blog.templ index a134b97..ced0f63 100644 --- a/handlers/pages/blog.templ +++ b/handlers/pages/blog.templ @@ -11,6 +11,7 @@ import ( "net/url" "path" "log" + "time" "forge.capytal.company/capytal/www/templates/layouts" @@ -40,10 +41,12 @@ type Blog struct { } type entry struct { - title string - path string - summary string - contents templ.Component + title string + path string + summary string + creationDate time.Time + modifiedDate time.Time + contents templ.Component } type BlogOptions struct { @@ -201,6 +204,24 @@ func (p *Blog) init() error { summary = fmt.Sprintf("NO RUMMARY %s", e.Path) } + var created, modified time.Time + + if c, ok := meta["created"]; ok { + s, ok := c.(string) + if ok { + s = strings.Split(s, "T")[0] + created, _ = time.Parse(time.DateOnly, s) + } + } + + if m, ok := meta["modified"]; ok { + s, ok := m.(string) + if ok { + s = strings.Split(s, "T")[0] + modified, _ = time.Parse(time.DateOnly, s) + } + } + err = p.md.Renderer().Render(&buf, body, node) if err != nil { return err @@ -214,10 +235,12 @@ func (p *Blog) init() error { comp := p.entryTemplate(html) entries[e.Path] = entry{ - title: title, - path: e.Path, - summary: summary, - contents: comp, + title: title, + path: e.Path, + summary: summary, + contents: comp, + creationDate: created, + modifiedDate: modified, } } @@ -311,6 +334,7 @@ templ templateList(entries map[string]entry) {

@templ.Raw(e.summary)

+

Created { e.creationDate.Format(time.DateOnly) } • Modified { e.modifiedDate.Format(time.DateOnly) }

}