func showPage(page Page, w http.ResponseWriter, r *http.Request) { out, err := webshell.BuildTemplate(home_template, page) if err != nil { webshell.Error500(err.Error(), "text/plain", w, r) } else { w.Write(out) } }
func Template(tplSource string, w http.ResponseWriter, r *http.Request) *template.Template { t := template.New("page") t, err := t.Parse(tplSource) if err != nil { webshell.Error500(err.Error(), "text/plain", w, r) return nil } return t }
func tpl_error(w http.ResponseWriter, r *http.Request) { var page struct { Nonsense string } out, err := webshell.ServeTemplateFile("templates/test.html", page) if err != nil { fmt.Println("[!] error") webshell.Error500(err.Error(), "text/plain", w, r) } else { w.Write(out) } }
func tpl_test2(w http.ResponseWriter, r *http.Request) { var page struct { Title string Paragraph string } page.Title = "another test page" page.Paragraph = "Sæmundar Edda" out, err := webshell.ServeTemplateFile("templates/test.html", page) if err != nil { webshell.Error500(err.Error(), "text/plain", w, r) } else { w.Write(out) } }
func tpl_test(w http.ResponseWriter, r *http.Request) { var page struct { Title string Paragraph string } page.Title = "test page" page.Paragraph = "rw nw prt m hrw" out, err := webshell.BuildTemplateFile("templates/test.html", page) if err != nil { webshell.Error500(err.Error(), "text/plain", w, r) } else { w.Write(out) } }
func servePage(w http.ResponseWriter, r *http.Request) { md_file := getMdFilename(r.URL.Path[1:]) title := getPageTitle(md_file) out, err := loadMarkdown(md_file) if err != nil { webshell.Error404("Page not found.", "text/plain", w, r) return } page := Page{false, false, title, template.HTML(string(out))} active := extRegex.ReplaceAllString(filepath.Base(md_file), "$1") if active == "index" { page.HomeActive = true } else if active == "about" { page.AboutActive = true } body, err := webshell.BuildTemplate(page_tpl, page) if err != nil { webshell.Error500(err.Error(), "text/plain", w, r) return } w.Write(body) }