<commit_before>var sorter = require('./sorter');
var canonical = require('./canonical');

module.exports = routes;

function title(suffix) {
  var t = 'Liftie';
  if(suffix && suffix.length) {
    t += ' | ' + suffix;
  }
  return t;
}

function routes(app) {
  var data = app.data;

  function renderResortsFn(req, res, next, opts) {
    return function(err, items) {
      var titleSuffix = opts.title,
        template = opts.template || 'index';

      if(err) {
        return next(err);
      }
      if(opts.openSingle && items.length === 1) {
        items[0].open = true; // if single resort requested, always mark it as open
        titleSuffix = titleSuffix || items[0].name;
      } else {
        items = sorter(items, req.cookies);
      }

      res.render(template, {
        title: title(titleSuffix),
        all: data.all(),
        resorts: items,
        tags: data.tags()
      });
    };
  }

  /**
   * Handles 2 types of URIs:
   *   / - display all resorts
   *   /resort/<name> - display a specific resort
   *   /?resorts=<name1>,<name2>... - display resorts on the list
   */
  function index(req, res, next) {
    var requested = req.params.resort || req.query.resorts;
    data.get(requested, renderResortsFn(req, res, next, {<commit_msg>Flag to denote a single resort is to be displayed<commit_after>var sorter = require('./sorter');
var canonical = require('./canonical');

module.exports = routes;

function title(suffix) {
  var t = 'Liftie';
  if(suffix && suffix.length) {
    t += ' | ' + suffix;
  }
  return t;
}

function routes(app) {
  var data = app.data;

  function renderResortsFn(req, res, next, opts) {
    return function(err, items) {
      var titleSuffix = opts.title,
        template = opts.template || 'index',
        single;

      if(err) {
        return next(err);
      }
      if(opts.openSingle && items.length === 1) {
        items[0].open = true; // if single resort requested, always mark it as open
        titleSuffix = titleSuffix || items[0].name;
        single = true;
      } else {
        items = sorter(items, req.cookies);
      }

      res.render(template, {
        title: title(titleSuffix),
        all: data.all(),
        resorts: items,
        tags: data.tags(),
        single: single
      });
    };
  }

  /**
   * Handles 2 types of URIs:
   *   / - display all resorts
   *   /resort/<name> - display a specific resort
   *   /?resorts=<name1>,<name2>... - display resorts on the list
   */
  function index(req, res, next) {
    var requested = req.params.resort || req.query.resorts;
    data.get(requested, renderResortsFn(req, res, next, {
{'fraction_non_alphanumeric': 0.14372392870686387, 'fraction_numerical': 0.004550625711035267, 'mean_word_length': 2.339240506329114, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4781195', 'n_tokens_mistral': 867, 'n_tokens_neox': 840, 'n_words': 218}