(app *App, w http.ResponseWriter, r *http.Request, t *template.Template)
| 307 | } |
| 308 | |
| 309 | func handleTemplatedPage(app *App, w http.ResponseWriter, r *http.Request, t *template.Template) error { |
| 310 | p := struct { |
| 311 | page.StaticPage |
| 312 | ContentTitle string |
| 313 | Content template.HTML |
| 314 | PlainContent string |
| 315 | Updated string |
| 316 | |
| 317 | AboutStats *InstanceStats |
| 318 | }{ |
| 319 | StaticPage: pageForReq(app, r), |
| 320 | } |
| 321 | if r.URL.Path == "/about" || r.URL.Path == "/contact" || r.URL.Path == "/privacy" { |
| 322 | var c *instanceContent |
| 323 | var err error |
| 324 | |
| 325 | if r.URL.Path == "/about" { |
| 326 | c, err = getAboutPage(app) |
| 327 | |
| 328 | // Fetch stats |
| 329 | p.AboutStats = &InstanceStats{} |
| 330 | p.AboutStats.NumPosts, _ = app.db.GetTotalPosts() |
| 331 | p.AboutStats.NumBlogs, _ = app.db.GetTotalCollections() |
| 332 | } else if r.URL.Path == "/contact" { |
| 333 | c, err = getContactPage(app) |
| 334 | if c.Updated.IsZero() { |
| 335 | // Page was never set up, so return 404 |
| 336 | return ErrPostNotFound |
| 337 | } |
| 338 | } else { |
| 339 | c, err = getPrivacyPage(app) |
| 340 | } |
| 341 | |
| 342 | if err != nil { |
| 343 | return err |
| 344 | } |
| 345 | p.ContentTitle = c.Title.String |
| 346 | p.Content = template.HTML(applyMarkdown([]byte(c.Content), "", app.cfg)) |
| 347 | p.PlainContent = shortPostDescription(stripmd.Strip(c.Content)) |
| 348 | if !c.Updated.IsZero() { |
| 349 | p.Updated = c.Updated.Format("January 2, 2006") |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // Serve templated page |
| 354 | err := t.ExecuteTemplate(w, "base", p) |
| 355 | if err != nil { |
| 356 | log.Error("Unable to render page: %v", err) |
| 357 | } |
| 358 | return nil |
| 359 | } |
| 360 | |
| 361 | func pageForReq(app *App, r *http.Request) page.StaticPage { |
| 362 | p := page.StaticPage{ |
no test coverage detected