Ejemplo n.º 1
0
Archivo: kvb.go Proyecto: pgray/kvb
func editHandler(w http.ResponseWriter, r *http.Request, section string, title string) {
	fmt.Println("editHandler: ", section, title)
	if title == "" {
		title = "root"
	}

	p := db.LoadPage(DB, section, title)
	t, err := template.ParseFiles("templates/edit.html")
	ce(err)
	tempStruct := struct {
		Section string
		Title   string
		Body    []byte
	}{
		section,
		p.Title,
		p.Body,
	}
	t.Execute(w, tempStruct)
}
Ejemplo n.º 2
0
Archivo: kvb.go Proyecto: pgray/kvb
func browseHandler(w http.ResponseWriter, r *http.Request, section string, title string) {
	fmt.Println("browseHandler: ", section, title)
	if title == "" {
		t, err := template.ParseFiles("templates/section.html")
		ce(err)
		posts := db.Posts(DB, section)
		fmt.Println("posts: ", posts)
		tempStruct := struct {
			Section string
			Posts   []string
		}{
			section,
			posts,
		}
		t.Execute(w, tempStruct)
		return
	}

	p := db.LoadPage(DB, section, title)

	if p.Body == nil {
		p.Body = append(p.Body, []byte("Sorry, that page does not exist")...)
	}

	t, err := template.ParseFiles("templates/browse.html")
	ce(err)
	fmt.Println("browse: ", section, title)
	tempStruct := struct {
		Section string
		Title   string
		Body    template.HTML
	}{
		section,
		p.Title,
		template.HTML(blackfriday.MarkdownCommon(p.Body)),
	}
	t.Execute(w, tempStruct)
}