diff --git a/public/views/index.hbs b/public/views/index.hbs index 7aee06e..8d3e916 100644 --- a/public/views/index.hbs +++ b/public/views/index.hbs @@ -36,49 +36,21 @@

- Popular Resources + Newest Resources

- - - - - - - + {{#each recentResources}} +
+ + +

{{this.name}}

+
+ {{#each this.owners}} + {{this}} + {{/each}} +
+ {{/each}}
diff --git a/server/db.js b/server/db.js index 1b6af4c..cda82b1 100644 --- a/server/db.js +++ b/server/db.js @@ -23,7 +23,7 @@ const Resource = mongoose.model('Resource', mongoose.Schema({ ] }, data: Buffer, owners: { type: Array, default: [] }, - when: String, + when: Number, })) const Collection = mongoose.model('Collection', mongoose.Schema({ @@ -60,5 +60,12 @@ module.exports = { done() }) }) + }, + + getRecentResources: async function(count) { + const resources = (await db.collections.resources.find()) + .sort({when: -1}) + .limit(4) + return resources } } \ No newline at end of file diff --git a/server/main.js b/server/main.js index 99a9356..8dccd46 100644 --- a/server/main.js +++ b/server/main.js @@ -501,9 +501,10 @@ app.get('/resources/:id/raw', async function(req, res) { } }) -app.get('/', function(req, res) { +app.get('/', async function(req, res) { res.render('index', { - user: req.session.user + user: req.session.user, + recentResources: await (db.getRecentResources()).then(e => e.toArray()) }) })