package app import ( "fmt" "slices" "strings" "git.urbach.dev/go/markdown" "git.urbach.dev/go/web" ) func RenderPost(ctx web.Context, id string) error { var ( post = Posts[id] title string content string created string tags []string ) if post != nil { title = post.Title content = post.Content created = post.Created tags = post.Tags } else { title = "Not found" content = fmt.Sprintf("Post `%s` does not exist.", id) ctx.Status(404) } head := fmt.Sprintf(`%s`, title, strings.Join(tags, ",")) if slices.Contains(tags, "article") { content = fmt.Sprintf( `

%s

%s
`, title, created, created[:len("YYYY-MM-DD")], markdown.Render(content), ) } else { content = fmt.Sprintf( `

%s

%s`, title, markdown.Render(content), ) } return Render(ctx, head, content) }