diff options
| author | clsr <clsr@clsr.net> | 2017-08-25 16:18:29 +0200 | 
|---|---|---|
| committer | clsr <clsr@clsr.net> | 2017-08-25 16:18:29 +0200 | 
| commit | cbb456c6d3c995e7856ad08e6fac844fe20796ec (patch) | |
| tree | 297a9fabd4d83cdd8c5f68f992e25fbe1bc07ff6 | |
| parent | c626ecdc562f99fbaf2130f7136d7f9b0ea7b58a (diff) | |
| download | cn-http-cbb456c6d3c995e7856ad08e6fac844fe20796ec.tar.gz cn-http-cbb456c6d3c995e7856ad08e6fac844fe20796ec.zip | |
Handle documents without contentv0.1.6
| -rw-r--r-- | cnhttp.go | 8 | 
1 files changed, 6 insertions, 2 deletions
| @@ -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 == "",  	}) |