summaryrefslogtreecommitdiffstats
path: root/cnhttp.go
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-25 16:18:29 +0200
committerclsr <clsr@clsr.net>2017-08-25 16:18:29 +0200
commitcbb456c6d3c995e7856ad08e6fac844fe20796ec (patch)
tree297a9fabd4d83cdd8c5f68f992e25fbe1bc07ff6 /cnhttp.go
parentc626ecdc562f99fbaf2130f7136d7f9b0ea7b58a (diff)
downloadcn-http-cbb456c6d3c995e7856ad08e6fac844fe20796ec.tar.gz
cn-http-cbb456c6d3c995e7856ad08e6fac844fe20796ec.zip
Handle documents without contentv0.1.6
Diffstat (limited to 'cnhttp.go')
-rw-r--r--cnhttp.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/cnhttp.go b/cnhttp.go
index c9732d5..bc949ca 100644
--- a/cnhttp.go
+++ b/cnhttp.go
@@ -318,7 +318,7 @@ func genToc(b cnm.Block) []tocSection {
res = append(res, genToc(bl)...)
}
}
- } else if v, ok := b.(cnm.ContainerBlock); ok && v != nil {
+ } else if v, ok := b.(cnm.ContainerBlock); ok {
for _, bl := range v.Children() {
res = append(res, genToc(bl)...)
}
@@ -418,6 +418,10 @@ func (srv *server) cnpCNMToHTML(w http.ResponseWriter, r *http.Request, req *cnp
return
}
+ var toc []tocSection
+ if doc.Content != nil {
+ toc = genToc(doc.Content)
+ }
err = srv.addTemplateFuncs(tmpl, req, resp).ExecuteTemplate(&buf, "page.html", cnmPage{
URL: u.String(),
Req: breq.String(),
@@ -425,7 +429,7 @@ func (srv *server) cnpCNMToHTML(w http.ResponseWriter, r *http.Request, req *cnp
Doc: doc,
Netcat: shellquote.Join("echo", hdrs) + " | " + shellquote.Join("nc", host, port),
Site: st,
- Toc: tocSection{Children: genToc(doc.Content)},
+ Toc: tocSection{Children: toc},
Highlight: srv.highlighting,
Browser: srv.host == "",
})