Add optional title

This commit is contained in:
Nise Void 2018-11-06 19:28:35 +01:00
parent 4858669406
commit 0d86e7ea2a
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3
1 changed files with 15 additions and 1 deletions

16
main.go
View File

@ -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)
}