<commit_before>/**
 * HTTP Server Settings
 * (sails.config.http)
 *
 * Configuration for the underlying HTTP server in Sails.
 * Only applies to HTTP requests (not WebSockets)
 *
 * For more information on configuration, check out:
 * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.http.html
 */
var dateFormat = require('dateformat');
var autoLink = require('autolink-js');
var marked = require('marked');
var cheerio = require ('cheerio');


module.exports.http = {

  /****************************************************************************
  *                                                                           *
  * Express middleware to use for every Sails request. To add custom          *
  * middleware to the mix, add a function to the middleware config object and *
  * add its key to the "order" array. The $custom key is reserved for         *
  * backwards-compatibility with Sails v0.9.x apps that use the               *
  * `customMiddleware` config option.                                         *
  *                                                                           *
  ****************************************************************************/

  middleware: {

  /***************************************************************************
  *                                                                          *
  * The order in which middleware should be run for HTTP request. (the Sails *
  * router is invoked by the "router" middleware below.)                     *
  *                                                                          *
  ***************************************************************************/

    order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'passportInit',
      'passportSession',
      'userInjector',
      'paramsInjector',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      '$custom',
      'router',
      'flash', // Connect-flash for passport.js
      'www',
      'favicon',
      '404',
      '500'
    ],

  /****************************************************************************
  *                                                                           *
  * Example custom middleware; logs each request to the console.              *
  *                                                                           *
  ****************************************************************************/

  userInjector: function (req, res, next) {
    res.locals.user = req.user;
    return next();
  },

  paramsInjector: function (req, res, next) {
    res.locals.inViewerPane = (req.param('viewer_pane') === '1') ? true : false;
    res.locals.path = req.path;
    res.locals.dateformat = dateFormat;
    res.locals.autoLink = autoLink;
    res.locals.lodash = require('lodash');
    res.locals.md = function (md,baseLink) {
      if(baseLink!=""){
        var base = cheerio.load(baseLink);
        base = base('a').attr('href');
      }
      else{
        base = "";
      }      
      var html = marked (md);
      $ = cheerio.load(html);
      var links = $('a');
      links.attr('href',function(i,link){
        if(!(link.startsWith("http:") || link.startsWith("www"))){
          if(link.startsWith("/..")){
            return link.replace("/..",base);
          }
          else if(base.startsWith("http://github.com")){
            return base.replace("http://github.com","https://raw.githubusercontent.com")+"/master/"+ link;
          } 
          else{
            return link;
          }
        }
      })
      links = $('img');
      links.attr('src',function(i,link){
        if(!(link.startsWith("http:") || link.startsWith("www"))){
          if(link.startsWith("/..")){
            return link.replace("/..",base+"/blob");
          }
          else if(base.startsWith("http://github.com")){
            return base.replace("http://github.com","https://raw.githubusercontent.com")+"/master/"+ link;
          } 
          else{
            return link;
          }
        }
        else{
          return link;
        }
      })
      return $.html();
    };<commit_msg>fixed it to also work with https links<commit_after>/**
 * HTTP Server Settings
 * (sails.config.http)
 *
 * Configuration for the underlying HTTP server in Sails.
 * Only applies to HTTP requests (not WebSockets)
 *
 * For more information on configuration, check out:
 * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.http.html
 */
var dateFormat = require('dateformat');
var autoLink = require('autolink-js');
var marked = require('marked');
var cheerio = require ('cheerio');


module.exports.http = {

  /****************************************************************************
  *                                                                           *
  * Express middleware to use for every Sails request. To add custom          *
  * middleware to the mix, add a function to the middleware config object and *
  * add its key to the "order" array. The $custom key is reserved for         *
  * backwards-compatibility with Sails v0.9.x apps that use the               *
  * `customMiddleware` config option.                                         *
  *                                                                           *
  ****************************************************************************/

  middleware: {

  /***************************************************************************
  *                                                                          *
  * The order in which middleware should be run for HTTP request. (the Sails *
  * router is invoked by the "router" middleware below.)                     *
  *                                                                          *
  ***************************************************************************/

    order: [
      'startRequestTimer',
      'cookieParser',
      'session',
      'passportInit',
      'passportSession',
      'userInjector',
      'paramsInjector',
      'bodyParser',
      'handleBodyParserError',
      'compress',
      'methodOverride',
      '$custom',
      'router',
      'flash', // Connect-flash for passport.js
      'www',
      'favicon',
      '404',
      '500'
    ],

  /****************************************************************************
  *                                                                           *
  * Example custom middleware; logs each request to the console.              *
  *                                                                           *
  ****************************************************************************/

  userInjector: function (req, res, next) {
    res.locals.user = req.user;
    return next();
  },

  paramsInjector: function (req, res, next) {
    res.locals.inViewerPane = (req.param('viewer_pane') === '1') ? true : false;
    res.locals.path = req.path;
    res.locals.dateformat = dateFormat;
    res.locals.autoLink = autoLink;
    res.locals.lodash = require('lodash');
    res.locals.md = function (md,baseLink) {
      if(baseLink!=""){
        var base = cheerio.load(baseLink);
        base = base('a').attr('href');
      }
      else{
        base = "";
      }      
      var html = marked (md);
      $ = cheerio.load(html);
      var links = $('a');
      links.attr('href',function(i,link){
        if(!(link.startsWith("http") || link.startsWith("www"))){
          if(link.startsWith("/..")){
            return link.replace("/..",base);
          }
          else if(base.startsWith("http://github.com")){
            return base.replace("http://github.com","https://raw.githubusercontent.com")+"/master/"+ link;
          } 
          else{
            return link;
          }
        }
      })
      links = $('img');
      links.attr('src',function(i,link){
        if(!(link.startsWith("http") || link.startsWith("www"))){
          if(link.startsWith("/..")){
            return link.replace("/..",base+"/blob");
          }
          else if(base.startsWith("http://github.com")){
            return base.replace("http://github.com","https://raw.githubusercontent.com")+"/master/"+ link;
          } 
          else{
            return link;
          }
        }
        else{
          return link;
        }
      })
      return $.html();
    };
{'fraction_non_alphanumeric': 0.22777317390789628, 'fraction_numerical': 0.0021309340594293834, 'mean_word_length': 1.718146718146718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2794605', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2023, 'n_words': 455}