From cbb456c6d3c995e7856ad08e6fac844fe20796ec Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 25 Aug 2017 16:18:29 +0200 Subject: Handle documents without content --- cnhttp.go | 8 ++++++-- 1 file 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 == "", }) -- cgit