Add optional title
This commit is contained in:
parent
4858669406
commit
0d86e7ea2a
16
main.go
16
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -76,5 +77,18 @@ func servePage(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user