<commit_before>var Q = require('q');
var _ = require('lodash');

var path = require('path');
var latenize = require('latenize');

var fs = require('./lib/fs');


function repeat(str, n) {
    return _.chain(n)
    .range()
    .map(_.constant(str))
    .value().join('');
}

function convertChapter(content) {
    var parts = content.split('\n## ');
    var README = parts[0];

    var articles = _.map(parts.slice(1), function(src) {
        return '## ' + src;
    });

    return {
        readme: README,
        articles: articles
    };
}

function titleToPath(title) {
    return latenize(title.toLowerCase())
    .replace(/[ -]/g, '_')
    .replace(/[^a-zA-Z_]/g, "");
}

function parseChapter(_path, fullpath) {
    var matches = _path.match(/^\d+-(.*)\/0\d-chapter(\d+).markdown$/);
    if(!matches) {
        throw new Error('Failed to handle, '+_path);
    }

    // Extract title and chapter number
    var title = matches[1].replace(/-/g, ' ');
    var num = parseInt(matches[2], 10);

    return fs.readFile(fullpath, 'utf8')
    .then(convertChapter)
    .then(function(parts) {
        return {
            num: num,
            title: chapterTitle(parts.readme),
            readme: fixMarkdown(parts.readme),
            articles: _.map(parts.articles, function(content) {
                return {
                    title: articleTitle(content),<commit_msg>Hash titles to generate paths<commit_after>var Q = require('q');
var _ = require('lodash');

var path = require('path');
var latenize = require('latenize');

var crypto = require('crypto');

var fs = require('./lib/fs');


function repeat(str, n) {
    return _.chain(n)
    .range()
    .map(_.constant(str))
    .value().join('');
}

function convertChapter(content) {
    var parts = content.split('\n## ');
    var README = parts[0];

    var articles = _.map(parts.slice(1), function(src) {
        return '## ' + src;
    });

    return {
        readme: README,
        articles: articles
    };
}

/*
function titleToPath(title) {
    return latenize(title.toLowerCase())
    .replace(/[ -]/g, '_')
    .replace(/[^a-zA-Z_]/g, "");
}
*/

// Brute force ish method by hashing
function titleToPath(title) {
    return crypto.createHash('md5').update(title).digest('hex');
}

function parseChapter(_path, fullpath) {
    var matches = _path.match(/^\d+-(.*)\/0\d-chapter(\d+).markdown$/);
    if(!matches) {
        throw new Error('Failed to handle, '+_path);
    }

    // Extract title and chapter number
    var title = matches[1].replace(/-/g, ' ');
    var num = parseInt(matches[2], 10);

    return fs.readFile(fullpath, 'utf8')
    .then(convertChapter)
    .then(function(parts) {
        return {
            num: num,
            title: chapterTitle(parts.readme),
            readme: fixMarkdown(parts.readme),
            articles: _.map(parts.articles, function(content) {
                return {
                    title: articleTitle(content),
{'fraction_non_alphanumeric': 0.17447386286490157, 'fraction_numerical': 0.005770536320434488, 'mean_word_length': 2.5293413173652697, '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': '6728386', 'n_tokens_mistral': 977, 'n_tokens_neox': 941, 'n_words': 198}