<commit_before>var keystone = require('keystone');

exports = module.exports = function(req, res) {

    var view = new keystone.View(req, res);
    var locals = res.locals;

    locals.section = 'blog';
    locals.filters = {
        post: req.params.post
    };
    locals.data = {
        posts: []
    };

    // Load the current post
    view.on('init', function(next) {

        var q = keystone.list('Post').model.findOne({
            state: 'published',
            slug: locals.filters.post
        }).populate('author categories');

        q.exec(function(err, result) {
            locals.data.post = result;
            next(err);
        });

    });

    // Load other posts
    view.on('init', function(next) {

        var q = keystone.list('Post').model.find().where('state', 'published').sort('-publishedDate').populate('author').limit('4');

        q.exec(function(err, results) {
            locals.data.posts = results;
            next(err);
        });

    });

    // Render the view
    view.render('post');
};<commit_msg>[master] Load category in post.js<commit_after>var keystone = require('keystone');

exports = module.exports = function(req, res) {

    var view = new keystone.View(req, res);
    var locals = res.locals;

    locals.section = 'blog';
    locals.filters = {
        post: req.params.post
    };
    locals.data = {
        posts: [],
        categories: []
    };

    // Load all categories
    view.on('init', function(next) {

        keystone.list('Category').model.find().sort('name').exec(function(err, results) {

            if (err || !results.length) {
                return next(err);
            }

            locals.data.categories = results;
            next();
        });
    });

    // Load the current post
    view.on('init', function(next) {

        var q = keystone.list('Post').model.findOne({
            state: 'published',
            slug: locals.filters.post
        }).populate('author categories');

        q.exec(function(err, result) {
            locals.data.post = result;
            next(err);
        });
    });

    // Load other posts
    view.on('init', function(next) {

        var q = keystone.list('Post').model.find().where('state', 'published').sort('-publishedDate').populate('author').limit('4');

        q.exec(function(err, results) {
            locals.data.posts = results;
            next(err);
        });
    });

    view.render('post');
};
{'fraction_non_alphanumeric': 0.16578411405295315, 'fraction_numerical': 0.000814663951120163, 'mean_word_length': 1.9987789987789988, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5732185', 'n_tokens_mistral': 743, 'n_tokens_neox': 717, 'n_words': 137}