This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
2020-11-30 15:29:44 +07:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2020-12-01 14:16:56 +07:00
|
|
|
"fmt"
|
2020-11-30 15:29:44 +07:00
|
|
|
"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)
|
2020-12-01 14:16:56 +07:00
|
|
|
CurrentTheme.ExecuteTemplate(w, "500.tmpl", fmt.Errorf("error reading content folder: %w", err))
|
2020-11-30 15:29:44 +07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Make it actually pass in a post.
|
|
|
|
CurrentTheme.ExecuteTemplate(w, "post.tmpl", nil)
|
|
|
|
}
|