From 0d86e7ea2af6587d2378ebccc2be9b4348e06bb4 Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Tue, 6 Nov 2018 19:28:35 +0100 Subject: [PATCH] Add optional title --- main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 62b8ad7..5ed93ba 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "flag" "html/template" "io/ioutil" @@ -76,5 +77,18 @@ func servePage(w http.ResponseWriter, r *http.Request) { return } - t.Execute(w, template.HTML(blackfriday.MarkdownCommon(c))) + var title string + if idx := bytes.IndexByte(c, '\n'); idx != -1 { + fl := string(c[:idx]) + if strings.HasPrefix(fl, `[title]:`) { + title = strings.TrimPrefix(fl, `[title]:`) + } + } + + data := struct { + Title string + Content template.HTML + }{title, template.HTML(blackfriday.MarkdownCommon(c))} + + t.Execute(w, data) }