handlePostIDRedirect handles a route where a post ID is given and redirects the user to the canonical post URL.
(app *App, w http.ResponseWriter, r *http.Request)
| 265 | // handlePostIDRedirect handles a route where a post ID is given and redirects |
| 266 | // the user to the canonical post URL. |
| 267 | func handlePostIDRedirect(app *App, w http.ResponseWriter, r *http.Request) error { |
| 268 | vars := mux.Vars(r) |
| 269 | postID := vars["post"] |
| 270 | p, err := app.db.GetPost(postID, 0) |
| 271 | if err != nil { |
| 272 | return err |
| 273 | } |
| 274 | |
| 275 | if !p.CollectionID.Valid { |
| 276 | // No collection; send to normal URL |
| 277 | // NOTE: not handling single user blogs here since this handler is only used for the Reader |
| 278 | return impart.HTTPError{http.StatusFound, app.cfg.App.Host + "/" + postID + ".md"} |
| 279 | } |
| 280 | |
| 281 | c, err := app.db.GetCollectionBy("id = ?", fmt.Sprintf("%d", p.CollectionID.Int64)) |
| 282 | if err != nil { |
| 283 | return err |
| 284 | } |
| 285 | c.hostName = app.cfg.App.Host |
| 286 | |
| 287 | // Retrieve collection information and send user to canonical URL |
| 288 | return impart.HTTPError{http.StatusFound, c.CanonicalURL() + p.Slug.String} |
| 289 | } |
| 290 | |
| 291 | func viewLocalTimelineFeed(app *App, w http.ResponseWriter, req *http.Request) error { |
| 292 | if !app.cfg.App.LocalTimeline { |
nothing calls this directly
no test coverage detected