news pinned feature;
This commit is contained in:
1 parent
e7c77e18c6
commit
38fac9c033
1 file changed
+39
-1
+39
-1
@@ -22,11 +22,49 @@ module.exports = function (app) {
|
||||
var query = {};
|
||||
if (this.query.type) query.type = this.query.type;
|
||||
|
||||
this.body = yield db.c("posts").find(query).skip(skip).limit(count).toArray()
|
||||
var pinned = [];
|
||||
if(portion == 0) {
|
||||
var now = new Date();
|
||||
pinned = yield db.c("posts").find({until: {$gte: now}}).toArray()
|
||||
.then(function (items) {
|
||||
return items.sort(sortNewsByDate);
|
||||
});
|
||||
}
|
||||
var pinned_ids = pinned.map(function (p) {
|
||||
return p["_id"]+"";
|
||||
});
|
||||
|
||||
var posts = yield db.c("posts").find(query).skip(skip).limit(count).toArray()
|
||||
.then(function (items) {
|
||||
return items.sort(sortNewsByDate);
|
||||
})
|
||||
.then(function (items) {
|
||||
return items.filter(function (i) {
|
||||
var id = i["_id"]+"";
|
||||
return pinned_ids.indexOf(id) < 0;
|
||||
});
|
||||
});
|
||||
|
||||
this.body = pinned.concat(posts);
|
||||
//this.body = pinned_ids
|
||||
}
|
||||
})));
|
||||
|
||||
app.use(route.get("/news/pinned", router.accepts({
|
||||
"text/html": function *() {
|
||||
this.redirect("/");
|
||||
},
|
||||
"text/plain": function *() {
|
||||
this.redirect("/");
|
||||
},
|
||||
"application/json": function *() {
|
||||
var now = new Date();
|
||||
var pinned = yield db.c("posts").find({until: {$gte: now}}).toArray()
|
||||
.then(function (items) {
|
||||
return items.sort(sortNewsByDate);
|
||||
});
|
||||
this.body = pinned;
|
||||
}
|
||||
})));
|
||||
|
||||
app.use(route.get("/news/:uri", router.accepts({
|
||||
|
||||
Reference in new issue
Block a user