simplified some loops, added day2.md to test new footer date functionality
This commit is contained in:
15
posts.go
15
posts.go
@@ -5,6 +5,7 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -109,8 +110,8 @@ func parseFrontmatter(content string) (PostMeta, string, error) {
|
||||
meta.Excerpt = v
|
||||
case "tags":
|
||||
if v != "" {
|
||||
tags := strings.Split(v, ",")
|
||||
for _, t := range tags {
|
||||
tags := strings.SplitSeq(v, ",")
|
||||
for t := range tags {
|
||||
meta.Tags = append(meta.Tags, strings.TrimSpace(t))
|
||||
}
|
||||
}
|
||||
@@ -307,11 +308,8 @@ func GetPostsByTag(tag string, page, per int) []models.Post {
|
||||
|
||||
var filtered []models.Post
|
||||
for _, post := range posts {
|
||||
for _, t := range post.Tags {
|
||||
if t == tag {
|
||||
if slices.Contains(post.Tags, tag) {
|
||||
filtered = append(filtered, post)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,11 +334,8 @@ func GetTotalPagesByTag(tag string, per int) int {
|
||||
|
||||
count := 0
|
||||
for _, post := range posts {
|
||||
for _, t := range post.Tags {
|
||||
if t == tag {
|
||||
if slices.Contains(post.Tags, tag) {
|
||||
count++
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
posts/day2.md
Normal file
12
posts/day2.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: "Day 2...ish?"
|
||||
date: "2026-03-10"
|
||||
excerpt: "It's been a while"
|
||||
draft: false
|
||||
---
|
||||
|
||||
It's been a while since I visited the Forge.
|
||||
|
||||
I guess I've just been busy. I think it's time I commit, 1 post a week minimum.
|
||||
|
||||
I'll...see you soon.
|
||||
@@ -1,11 +1,21 @@
|
||||
package templates
|
||||
|
||||
templ Footer() {
|
||||
import "time"
|
||||
|
||||
func FormatLastUpdated(t time.Time) string {
|
||||
updatedAt := "Now-ish"
|
||||
if !t.IsZero() {
|
||||
updatedAt = t.Format("January 2, 2006")
|
||||
}
|
||||
return updatedAt
|
||||
}
|
||||
|
||||
templ Footer(lastUpdated time.Time) {
|
||||
<footer class="footer">
|
||||
<p>
|
||||
© 2025 Valentine Bott | Built with Go + Templ + HTMX |
|
||||
© 2026 Valentine Bott | Built with Go + Templ + HTMX |
|
||||
<a href="https://git.valxntine.dev/valxntine/blog">Source Code</a> |
|
||||
Last updated: <span class="blink">●</span> Now-ish
|
||||
Last updated: <span class="blink">●</span> { FormatLastUpdated(lastUpdated) }
|
||||
</p>
|
||||
</footer>
|
||||
}
|
||||
|
||||
@@ -8,7 +8,17 @@ package templates
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func Footer() templ.Component {
|
||||
import "time"
|
||||
|
||||
func FormatLastUpdated(t time.Time) string {
|
||||
updatedAt := "Now-ish"
|
||||
if !t.IsZero() {
|
||||
updatedAt = t.Format("January 2, 2006")
|
||||
}
|
||||
return updatedAt
|
||||
}
|
||||
|
||||
func Footer(lastUpdated time.Time) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
@@ -29,7 +39,20 @@ func Footer() templ.Component {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<footer class=\"footer\"><p>© 2025 Valentine Bott | Built with Go + Templ + HTMX | <a href=\"https://git.valxntine.dev/valxntine/blog\">Source Code</a> | Last updated: <span class=\"blink\">●</span> Now-ish</p></footer>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<footer class=\"footer\"><p>© 2026 Valentine Bott | Built with Go + Templ + HTMX | <a href=\"https://git.valxntine.dev/valxntine/blog\">Source Code</a> | Last updated: <span class=\"blink\">●</span> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(FormatLastUpdated(lastUpdated))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/footer.templ`, Line: 18, Col: 80}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</p></footer>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
package templates
|
||||
|
||||
import "git.valxntine.dev/valxntine/blog/models"
|
||||
import (
|
||||
"git.valxntine.dev/valxntine/blog/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetLastUpdated(p []models.Post) time.Time {
|
||||
if len(p) == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return p[0].PublishedAt
|
||||
}
|
||||
|
||||
templ HomePage(data models.Data) {
|
||||
@Layout(data.Title) {
|
||||
@@ -9,6 +19,6 @@ templ HomePage(data models.Data) {
|
||||
<main>
|
||||
@PostList(data.Posts, data.CurrentPage, data.TotalPages)
|
||||
</main>
|
||||
@Footer()
|
||||
@Footer(GetLastUpdated(data.Posts))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,17 @@ package templates
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import "git.valxntine.dev/valxntine/blog/models"
|
||||
import (
|
||||
"git.valxntine.dev/valxntine/blog/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetLastUpdated(p []models.Post) time.Time {
|
||||
if len(p) == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
return p[0].PublishedAt
|
||||
}
|
||||
|
||||
func HomePage(data models.Data) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
@@ -67,7 +77,7 @@ func HomePage(data models.Data) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = Footer().Render(ctx, templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = Footer(GetLastUpdated(data.Posts)).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ templ PostPageFull(post models.Post) {
|
||||
<main>
|
||||
@PostDetail(post)
|
||||
</main>
|
||||
@Footer()
|
||||
@Footer(post.PublishedAt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func PostPageFull(post models.Post) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = Footer().Render(ctx, templ_7745c5c3_Buffer)
|
||||
templ_7745c5c3_Err = Footer(post.PublishedAt).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user