|
|
|
@ -1295,14 +1295,32 @@ func viewCollectionPost(app *App, w http.ResponseWriter, r *http.Request) error |
|
|
|
|
coll.Owner = owner |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
postFound := true |
|
|
|
|
p, err := app.db.GetPost(slug, coll.ID) |
|
|
|
|
if err != nil { |
|
|
|
|
if err == ErrCollectionPageNotFound && slug == "feed" { |
|
|
|
|
// User tried to access blog feed without a trailing slash, and
|
|
|
|
|
// there's no post with a slug "feed"
|
|
|
|
|
return impart.HTTPError{http.StatusFound, c.CanonicalURL() + "/feed/"} |
|
|
|
|
if err == ErrCollectionPageNotFound { |
|
|
|
|
postFound = false |
|
|
|
|
|
|
|
|
|
if slug == "feed" { |
|
|
|
|
// User tried to access blog feed without a trailing slash, and
|
|
|
|
|
// there's no post with a slug "feed"
|
|
|
|
|
return impart.HTTPError{http.StatusFound, c.CanonicalURL() + "/feed/"} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
po := &Post{ |
|
|
|
|
Slug: null.NewString(slug, true), |
|
|
|
|
Font: "norm", |
|
|
|
|
Language: zero.NewString("en", true), |
|
|
|
|
RTL: zero.NewBool(false, true), |
|
|
|
|
Content: `<p class="msg">This page is missing.</p> |
|
|
|
|
|
|
|
|
|
Are you sure it was ever here?`, |
|
|
|
|
} |
|
|
|
|
pp := po.processPost() |
|
|
|
|
p = &pp |
|
|
|
|
} else { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
p.IsOwner = owner != nil && p.OwnerID.Valid && owner.ID == p.OwnerID.Int64 |
|
|
|
|
p.Collection = coll |
|
|
|
@ -1324,11 +1342,20 @@ func viewCollectionPost(app *App, w http.ResponseWriter, r *http.Request) error |
|
|
|
|
contentType = "text/markdown" |
|
|
|
|
} |
|
|
|
|
w.Header().Set("Content-Type", fmt.Sprintf("%s; charset=utf-8", contentType)) |
|
|
|
|
if !postFound { |
|
|
|
|
w.WriteHeader(http.StatusNotFound) |
|
|
|
|
fmt.Fprintf(w, "Post not found.") |
|
|
|
|
// TODO: return error instead, so status is correctly reflected in logs
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
if isMarkdown && p.Title.String != "" { |
|
|
|
|
fmt.Fprintf(w, "# %s\n\n", p.Title.String) |
|
|
|
|
} |
|
|
|
|
fmt.Fprint(w, p.Content) |
|
|
|
|
} else if strings.Contains(r.Header.Get("Accept"), "application/activity+json") { |
|
|
|
|
if !postFound { |
|
|
|
|
return ErrCollectionPageNotFound |
|
|
|
|
} |
|
|
|
|
p.extractData() |
|
|
|
|
ap := p.ActivityObject() |
|
|
|
|
ap.Context = []interface{}{activitystreams.Namespace} |
|
|
|
@ -1345,14 +1372,20 @@ func viewCollectionPost(app *App, w http.ResponseWriter, r *http.Request) error |
|
|
|
|
IsPinned bool |
|
|
|
|
IsCustomDomain bool |
|
|
|
|
PinnedPosts *[]PublicPost |
|
|
|
|
IsFound bool |
|
|
|
|
}{ |
|
|
|
|
PublicPost: p, |
|
|
|
|
StaticPage: pageForReq(app, r), |
|
|
|
|
IsOwner: cr.isCollOwner, |
|
|
|
|
IsCustomDomain: cr.isCustomDomain, |
|
|
|
|
IsFound: postFound, |
|
|
|
|
} |
|
|
|
|
tp.PinnedPosts, _ = app.db.GetPinnedPosts(coll) |
|
|
|
|
tp.IsPinned = len(*tp.PinnedPosts) > 0 && PostsContains(tp.PinnedPosts, p) |
|
|
|
|
|
|
|
|
|
if !postFound { |
|
|
|
|
w.WriteHeader(http.StatusNotFound) |
|
|
|
|
} |
|
|
|
|
if err := templates["collection-post"].ExecuteTemplate(w, "post", tp); err != nil { |
|
|
|
|
log.Error("Error in collection-post template: %v", err) |
|
|
|
|
} |
|
|
|
|