Skip to content

Instantly share code, notes, and snippets.

@jneumann
Created February 12, 2017 03:13
Show Gist options
  • Save jneumann/6b745d5b27bfeb44f0808d8b638b8e92 to your computer and use it in GitHub Desktop.
Save jneumann/6b745d5b27bfeb44f0808d8b638b8e92 to your computer and use it in GitHub Desktop.
var keystone = require('keystone');
var _ = require('underscore');
exports = module.exports = function (req, res) {
var view = new keystone.View(req, res);
var locals = res.locals;
// locals.section is used to set the currently selected
// item in the header navigation.
locals.section = 'home';
locals.content = [];
view.on('init', function (next) {
keystone.list('contents').model.find({'state': 'published', 'isHomepage': true}).exec(function(err, docs) {
var sorted_contents = _.sortBy(docs, 'order').reverse();
sorted_contents.forEach(function(e) {
var content = e.content.toLowerCase().replace(/(<([^>]+)>)/ig,"");
if (content === '[events]') {
e.content = 'events';
view.query('events', keystone.list('events').model.find().exec());
}
locals.content.push(e);
});
next(docs);
});
});
// Render the view
view.render('index');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment