<commit_before>var winston = require('winston');
var common = require('../../../core/lib/common');

var filter = common.regexFilter();

function indexPage(req, res) {
    var params = {
        title: "Home",
    };

    winston.info('this is a index page', req.path);

    //500 Error
    //throw Error('make noise!');

    // load recent articles

    res.render(BLITITOR.config.site.theme + '/page/index', params);
}

function plainPage(req, res) {

    var params = {
        title: "Plain",
        path: req.path,
        page: req.path == '/' ? 'index' : req.path.match(filter.page)[1].replace(/-/g, '_'),
    };

    // winston.info(req.path, params, req.path.match(filter.page));
    // console.log(res.locals.menu);

    res.render(BLITITOR.config.site.theme + '/page/' + params.page, params);
}

function exposeAppLocals(locals, menu) {
    return function (req, res, next) {
        res.locals.app = locals;
        res.locals.menu = menu;
        res.locals.adminMenu = menu.AdminMenu || {};
        res.locals.managerMenu = menu.ManagerMenu || {};

        winston.verbose('bind locals in app: {app, menu}');
        next();
    }
}

function bindMenuToRouter(menu, router) {
    menu.map(function (item) {
        router[item['type'] || 'get'](item['url'], plainPage);
    });
}

function redirectPage(url) {
    return function (req, res) {
        // winston.verbose('redirect to', url);
        if (url) {
            res.redirect(url);
        } else {
            res.redirect('back');
        }
    };
}

module.exports = {
    index: indexPage,
    plain: plainPage,
    bindMenu: bindMenuToRouter,
    exposeAppLocals: exposeAppLocals,
    redirect: redirectPage
};<commit_msg>added plain with sub path<commit_after>var winston = require('winston');
var common = require('../../../core/lib/common');

var filter = common.regexFilter();

function plainPage(req, res) {

    var params = {
        title: "Plain",
        path: req.path,
        page: req.path == '/' ? 'index' : req.path.match(filter.page)[1].replace(/-/g, '_'),
    };

    //500 Error
    //throw Error('make noise!');

    // winston.info(req.path, params, req.path.match(filter.page));

    res.render(BLITITOR.config.site.theme + '/page/' + params.page, params);
}

function plainPageWithSubPath(req, res) {

    var params = {
        title: "Plain",
        path: req.path,
        page: req.path.lastIndexOf('/') == req.path.toString().length - 1 ? req.path.replace(/-/g, '_') + 'index' : req.path.replace(/-/g, '_'),
    };

    // winston.info(req.path, params, req.path.match(filter.page));
    // console.log(req.path.lastIndexOf('/'), req.path.toString().length  -1 );

    res.render(BLITITOR.config.site.theme + '/page/' + params.page, params);
}

function bindMenuToRouter(menu, router) {
    menu.map(function (item) {
        router[item['type'] || 'get'](item['url'], plainPage);
    });
}

function bindMenuToRouter2(menu, router) {
    menu.map(function (item) {
        router[item['type'] || 'get'](item['url'], plainPageWithSubPath);
    });
}

function redirectPage(url) {
    return function (req, res) {
        // winston.verbose('redirect to', url);
        if (url) {
            res.redirect(url);
        } else {
            res.redirect('back');
        }
    };
}

function exposeAppLocals(locals, menu) {
    return function (req, res, next) {
        res.locals.app = locals;
        res.locals.menu = menu;
        res.locals.adminMenu = menu.AdminMenu || {};
        res.locals.managerMenu = menu.ManagerMenu || {};

        winston.verbose('bind locals in app: {app, menu}');
        next();
    }
}

module.exports = {
    redirect: redirectPage,
    bindMenu: bindMenuToRouter,
    bindMenuWithSubPath: bindMenuToRouter2,
    exposeAppLocals: exposeAppLocals,
};
{'fraction_non_alphanumeric': 0.17637753756920643, 'fraction_numerical': 0.0031637226469812814, 'mean_word_length': 2.589403973509934, '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': '5595024', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1228, 'n_words': 236}