This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
blgo/handler/post.go

29 lines
710 B
Go

package handler
import (
"fmt"
"net/http"
"os"
)
// Post is the handler that renders a post.
func Post(w http.ResponseWriter, r *http.Request) {
fileName := "content" + r.URL.Path + ".md"
// Check if the post exists and is not a directory.
info, err := os.Stat(fileName)
if os.IsNotExist(err) || (info != nil && info.IsDir()) {
w.WriteHeader(http.StatusNotFound)
CurrentTheme.ExecuteTemplate(w, "404.tmpl", nil)
return
}
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
CurrentTheme.ExecuteTemplate(w, "500.tmpl", fmt.Errorf("error reading content folder: %w", err))
return
}
// TODO Make it actually pass in a post.
CurrentTheme.ExecuteTemplate(w, "post.tmpl", nil)
}