<commit_before>var path = require('path');
var markdown = require('markdown').markdown;
var qfs = require('promised-io/fs');
var handlebars = require('handlebars');

var config = require('./config.json');

qfs.readFile(config.TEMPLATES.index, 'utf8')
    .then(function(templateSource){
        return handlebars.compile(templateSource);
    })
    .then(function(template){
        qfs.readdir(config.POSTS_DIRECTORY)
            .then(function(posts){
                var input = '';
                posts.forEach(function(post){
                    var link = path.basename(post, '.md') + '.html';
                    input += '* ';
                    input += '[' + post + '](' + link + ')\n';
                });
                var content = markdown.toHTML(input);
                var output = template({ 'content': content });
                var outputName = path.join(config.BLOG_DIRECTORY, 'index.html');
                return qfs.writeFile(outputName, output, 'utf8');
            })
            .then(function(){
                console.log('finished writing index.html');
            });
   });
<commit_msg>Extract title from file name<commit_after>var path = require('path');
var markdown = require('markdown').markdown;
var qfs = require('promised-io/fs');
var handlebars = require('handlebars');

var config = require('./config.json');
var postRegExp = /[.]([^.]*)[.]md/;

qfs.readFile(config.TEMPLATES.index, 'utf8')
    .then(function(templateSource){
        return handlebars.compile(templateSource);
    })
    .then(function(template){
        qfs.readdir(config.POSTS_DIRECTORY)
            .then(function(posts){
                var input = '';
                posts.forEach(function(post){
                    var matches = post.match(postRegExp);
                    var name = matches ? matches[1] : post;
                    var link = path.basename(post, '.md') + '.html';
                    input += '* ';
                    input += '[' + name + '](' + link + ')\n';
                });
                var content = markdown.toHTML(input);
                var output = template({ 'content': content });
                var outputName = path.join(config.BLOG_DIRECTORY, 'index.html');
                return qfs.writeFile(outputName, output, 'utf8');
            })
            .then(function(){
                console.log('finished writing index.html');
            });
   });

{'fraction_non_alphanumeric': 0.15486542443064183, 'fraction_numerical': 0.002070393374741201, 'mean_word_length': 1.9143546441495778, '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': '1099080', 'n_tokens_mistral': 679, 'n_tokens_neox': 645, 'n_words': 127}