35 lines
725 B
Go

package app
import (
"fmt"
"slices"
"strings"
"git.akyoto.dev/go/markdown"
"git.akyoto.dev/go/web"
)
func RenderPost(ctx web.Context, id string) error {
post := Posts[id]
head := fmt.Sprintf(`<title>%s</title><meta name="keywords" content="%s">`, post.Title, strings.Join(post.Tags, ","))
content := ""
if slices.Contains(post.Tags, "article") {
content = fmt.Sprintf(
`<article><header><h1>%s</h1><time datetime="%s">%s</time></header>%s</article>`,
post.Title,
post.Created,
post.Created[:len("YYYY-MM-DD")],
markdown.Render(post.Content),
)
} else {
content = fmt.Sprintf(
`<h2>%s</h2>%s`,
post.Title,
markdown.Render(post.Content),
)
}
return Render(ctx, head, content)
}