diff --git a/database_test.go b/database_test.go index 660ba833b43b48b1f828062798cd333475c2576b..7e5b17742b11feb64e3ccbb05691f420f212e2f0 100644 --- a/database_test.go +++ b/database_test.go @@ -52,9 +52,10 @@ func testEbook() *Book { return &Book{ Id: NewID(), Metadata: &Metadata{ - Title: "20,000 Leagues under the sea", - Creator: []string{"Jules Verne"}, - ISBN: []string{"1234"}, + Title: "20,000 Leagues under the sea", + Creator: []string{"Jules Verne"}, + ISBN: []string{"1234"}, + Description: "A pretty cool book.", }, } } diff --git a/htdocs/templates/book.html b/htdocs/templates/book.html index 505b1041bff64c9fe460bcbe4702234807226181..b6d8d8c8ef3b7dee540d8d11bb2a53cb36620c8d 100644 --- a/htdocs/templates/book.html +++ b/htdocs/templates/book.html @@ -28,8 +28,8 @@ </p> {{end}} - {{if .Book.Metadata.Description}} - <p>{{.Book.Metadata.Description}}</p> + {{if .Description}} + <p>{{.Description}}</p> {{end}} {{range $i, $f := .Files}} diff --git a/web.go b/web.go index 0e6bdd09e2b7b2ca57e62b8a4d4dd951ea1297ed..52a901babf5f99784554bf8c74159ede1c3f3d82 100644 --- a/web.go +++ b/web.go @@ -149,11 +149,18 @@ func (s *uiServer) handleShowBook(book *Book, w http.ResponseWriter, req *http.R return } + // The book's Description, if present, should be rendered + // directly as HTML. So we deal with it separately. ctx := struct { - Query string - Book *Book - Files []*File - }{Book: book, Files: files} + Query string + Book *Book + Files []*File + Description template.HTML + }{ + Book: book, + Files: files, + Description: template.HTML(book.Metadata.Description), + } render("book.html", w, &ctx) }