reprogl
1package handlers
2
3import (
4"errors"
5"io/fs"
6"net/http"
7
8"github.com/go-chi/chi/v5"
9"xelbot.com/reprogl/container"
10"xelbot.com/reprogl/views"
11)
12
13func MarkdownAction(app *container.Application) http.HandlerFunc {
14return func(w http.ResponseWriter, r *http.Request) {
15content, err := views.MarkdownToHTML(chi.URLParam(r, "filename"))
16if err != nil {
17if errors.Is(err, fs.ErrNotExist) {
18app.NotFound(w)
19} else {
20app.ServerError(w, err)
21}
22
23return
24}
25
26cacheControl(w, container.StaticFileTTL)
27w.Header().Set("Content-Type", "text/html; charset=utf-8")
28_, err = w.Write(content)
29if err != nil {
30app.ServerError(w, err)
31
32return
33}
34}
35}
36