aboutsummaryrefslogtreecommitdiff
path: root/page/renderMarkdown.go
diff options
context:
space:
mode:
Diffstat (limited to 'page/renderMarkdown.go')
-rw-r--r--page/renderMarkdown.go61
1 files changed, 0 insertions, 61 deletions
diff --git a/page/renderMarkdown.go b/page/renderMarkdown.go
deleted file mode 100644
index 8356e55..0000000
--- a/page/renderMarkdown.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package page
-
-import (
- "bytes"
- "errors"
- "io/fs"
- "net/http"
-)
-
-// RenderMarkdown is analogous to Render, except it spits out rendered markdown
-// as text/plain. It also sets .Vars.RenderingMarkdownOnly so templates can
-// vary on whether or not they're plain markdown. For instance, not including
-// some HTML tags.
-func RenderMarkdown(w http.ResponseWriter, r *http.Request,
- path string, vars map[string]interface{}, statusCode int) {
- // Sepcifically use the specified path for the page
- p := NewPage(path)
-
- if vars != nil {
- p.Vars = vars
- }
-
- if p.Vars != nil {
- p.Vars["RenderingMarkdownOnly"] = true
- } else {
- p.Vars = map[string]interface{}{
- "RenderingMarkdownOnly": true,
- }
- }
-
- buf := &bytes.Buffer{}
-
- err := p.Render(buf)
- if err != nil {
- if errors.Is(err, fs.ErrNotExist) {
- plainResp(w, http.StatusNotFound, "Not found")
-
- return
- }
-
- logErr(r, "while rendering", err)
- plainResp(w, http.StatusInternalServerError, "Internal server error")
-
- return
- }
-
- // Error was handled above
- md, _ := p.GetMarkdown()
-
- w.Header().Set("Content-type", "text/plain")
- w.WriteHeader(statusCode)
-
- _, err = w.Write([]byte(md))
- if err != nil {
- logErr(r, "while writing buf", err)
-
- return
- }
-
- logReq(r, statusCode)
-}