37 lines
808 B
Go
Raw Permalink Normal View History

2025-01-21 14:00:40 +01:00
package pages
import (
"bytes"
"fmt"
"slices"
"sort"
2025-02-25 17:01:59 +01:00
"git.urbach.dev/go/web"
"git.urbach.dev/web/urbach.dev/server/app"
2025-01-21 14:00:40 +01:00
)
func Blog(ctx web.Context) error {
html := bytes.Buffer{}
html.WriteString(`<h2>Blog</h2><ul class="blog">`)
articles := []*app.Post{}
for _, post := range app.Posts {
if !post.Published || !slices.Contains(post.Tags, "article") {
continue
}
articles = append(articles, post)
}
sort.Slice(articles, func(i, j int) bool {
return articles[i].Created > articles[j].Created
})
for _, post := range articles {
fmt.Fprintf(&html, `<li><a href="/%s">%s</a><time datetime="%s">%s</time></li>`, post.Slug, post.Title, post.Created, post.Created[:len("YYYY")])
}
html.WriteString(`</ul>`)
2025-02-25 17:01:59 +01:00
return app.Render(ctx, "<title>urbach.dev</title>", html.String())
2025-01-21 14:00:40 +01:00
}