<commit_before>/*
 * grunt-haggerston
 * https://github.com/haggerstonjs/grunt-haggerston
 *
 * Copyright (c) 2013 <NAME>, <NAME>
 * Licensed under the MIT license.
 */

var _ = require('underscore');
var path = require('path');
var grunt = require('grunt');
var marked = require('marked');
var swig = require('swig');

module.exports = function() {
  'use strict';

  return function markdown(pages, next, options) {
    var mdRegExp = /\.md$/;
    _(pages).each(function(page) {
      // Recursively loop over every property of the page
      _(page).deepEach(function(value, key, obj) {
        // Search for string values ending in '.json'
        if (_.isString(value) && value.match(mdRegExp)) {
          // Absolute urls are based off the contentPath, not the OS file system
          var filePath;
          if (grunt.file.isPathAbsolute(value)) {
            filePath = path.join(options.contentPath, value);
          } else {
            filePath = path.join(options.contentPath, page.path, value);
          }
          var fileContents = grunt.file.read(filePath);
          if (page.markdownPreprocessWithSwig) {
            fileContents = swig.compile(fileContents, { filename: filePath})({});
          }
          obj[key] = marked(fileContents);
        }
      });
    });

    next(pages);
  };
};<commit_msg>And substr seems to be a little faster still...<commit_after>/*
 * grunt-haggerston
 * https://github.com/haggerstonjs/grunt-haggerston
 *
 * Copyright (c) 2013 <NAME>, <NAME>
 * Licensed under the MIT license.
 */

var _ = require('underscore');
var path = require('path');
var grunt = require('grunt');
var marked = require('marked');
var swig = require('swig');

module.exports = function() {
  'use strict';

  return function markdown(pages, next, options) {
    _(pages).each(function(page) {
      // Recursively loop over every property of the page
      _(page).deepEach(function(value, key, obj) {
        // Search for string values ending in '.md'
        if (_.isString(value) && value.substr(-3) === '.md') {
          // Absolute urls are based off the contentPath, not the OS file system
          var filePath;
          if (grunt.file.isPathAbsolute(value)) {
            filePath = path.join(options.contentPath, value);
          } else {
            filePath = path.join(options.contentPath, page.path, value);
          }
          var fileContents = grunt.file.read(filePath);
          if (page.markdownPreprocessWithSwig) {
            fileContents = swig.compile(fileContents, { filename: filePath})({});
          }
          obj[key] = marked(fileContents);
        }
      });
    });

    next(pages);
  };
};
{'fraction_non_alphanumeric': 0.14050206069689022, 'fraction_numerical': 0.0033720494567253652, 'mean_word_length': 2.56, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '4101464', 'n_tokens_mistral': 806, 'n_tokens_neox': 783, 'n_words': 200}