37 lines
808 B
Go
37 lines
808 B
Go
package pages
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"slices"
|
|
"sort"
|
|
|
|
"git.urbach.dev/go/web"
|
|
"git.urbach.dev/web/urbach.dev/server/app"
|
|
)
|
|
|
|
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>`)
|
|
return app.Render(ctx, "<title>urbach.dev</title>", html.String())
|
|
}
|