<commit_before>var parsePath = require('parse-filepath')
var isobject = require('lodash.isobject')
var map = require('lodash.map')
var slug = require('slug')

module.exports = function parseContents (contents) {
  var depth = 0
  var menu = []

  function iterate (contents, depth) {
    return map(contents, function (value, key, obj) {
      return level(contents, key, value, depth + 1)
    })[0]
  }

  function level (contents, key, value, depth) {
    var obj = { depth: depth, name: key }

    if (isobject(value) && value.link) {
      obj.source = value.link
    }

    if (isobject(value) && !value.file) {
      menu.push(obj)
      iterate(value, depth)
    } else {
      var parsed = parsePath(value)
      obj.key = parsed.name
      obj.link = '/' + obj.key
      menu.push(obj)
    }
    return menu
  }

  return iterate(contents, depth)
}<commit_msg>fix parse-contents.js to allow for external link<commit_after>var parsePath = require('parse-filepath')
var isobject = require('lodash.isobject')
var map = require('lodash.map')
var slug = require('slug')

module.exports = function parseContents (contents) {
  var depth = 0
  var menu = []

  function iterate (contents, depth) {
    return map(contents, function (value, key, obj) {
      return level(contents, key, value, depth + 1)
    })[0]
  }

  function level (contents, key, value, depth) {
    var obj = { depth: depth, name: key }

    if (isobject(value) && value.link) {
      obj.source = value.link
    }

    if (isobject(value) && !value.file) {
      menu.push(obj)
      iterate(value, depth)
    } else {
      if (isobject(value)) {
        obj.source = value.link
        value = value.file
      }
      var parsed = parsePath(value)
      obj.key = parsed.name
      obj.link = '/' + obj.key
      menu.push(obj)
    }
    return menu
  }

  return iterate(contents, depth)
}
{'fraction_non_alphanumeric': 0.135366506153023, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 2.7250996015936253, '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': '2091772', 'n_tokens_mistral': 622, 'n_tokens_neox': 596, 'n_words': 162}