<commit_before>/**
 * Module dependencies.
 */
var kerouac = require('kerouac')
  , fs = require('fs')
  , path = require('path');

var DASHED_REGEX = /^(\d+)-(\d+)-(\d+)-(.*)/;


exports = module.exports = function(
  postHandler,
  atomFeed, rssFeed, rdfFeed, jsonFeed,
  postsDB) {
  
  var dir, options;
  
  if (typeof dir == 'object') {
    options = dir;
    dir = options.dir;
  }
  dir = dir || 'blog';
  options = options || {};
  
  
  var site = kerouac();
  
  site.on('mount', function onmount(parent) {
    // inherit settings
    this.set('layout engine', parent.get('layout engine'));
    
    this.locals.pretty = parent.locals.pretty;
  });
  
  
  site.page('/:year/:month/:day/:slug.html', postHandler);
  // FIXME: pretty URL isn't catching this
  //site.page('/index.html', require('./handlers/index')(options.layout));
  
  // https://github.com/jshttp/mime-db
  // https://help.github.com/articles/mime-types-on-github-pages/
  site.page('/feed.atom', atomFeed);
  site.page('/feed.rss', rssFeed);
  site.page('/feed.rdf', rdfFeed);
  site.page('/feed.json', jsonFeed);
  
  // TODO: implement a news-specific sitemap:
  //       https://support.google.com/webmasters/answer/74288
  // include it as a separate sitemap-news.xml
  
  site.page('/sitemap.xml', require('kerouac-sitemap')());
  
  site.bind(function(done) {
    var self = this;
    
    postsDB.list(function(err, posts) {
      if (err) { return done(err); }
      
      var el, i, len
        , url, year, month, day, slug;
      
      for (i = 0, len = posts.length; i < len; ++i) {
        el = posts[i];
        year = el.publishedAt.getUTCFullYear()
        month = (el.publishedAt.getUTCMonth() + 1)
        day = el.publishedAt.getUTCDate()
        slug = el.slug;
        
        month = (month < 10) ? ('0' + month) : month;
        day = (day < 10) ? ('0' + day) : day;
        
        url = '/' + [ year, month, day, slug + '.html' ].join('/');
        self.add(url);
      }
      
      done();
    });
    
    return;
    
    
    fs.readdir(dir, function(err, files) {
      if (err && err.code == 'ENOENT') {
        return done();
      } else if (err) { return done(err); }
      
      var idx = 0
        , file, base, ext
        , url;
      
      (function iter(err) {
        if (err) { return done(err); }
        
        file = files[idx++];
        if (!file) {
          return done();
        }
        
        file = path.join(dir, file);
        ext = path.extname(file);
        base = path.basename(file, ext);
        
        console.log('GOT FILE!');
        console.log(file);
        
        fs.stat(file, function(err, stats) {
          if (err) { return iter(err); }
          if (!stats.isFile()) { return iter(); }
          
          var year = stats.birthtime.getUTCFullYear()
            , month = (stats.birthtime.getUTCMonth() + 1)
            , day = stats.birthtime.getUTCDate()
            , slug = base;
          month = (month < 10) ? ('0' + month) : month;
          day = (day < 10) ? ('0' + day) : day;
          
          var match;
          if (match = DASHED_REGEX.exec(base)) {
            year = match[1];
            month = match[2];
            day = match[3];
            slug = match[4];
          }
          
          var url = '/' + [ year, month, day, slug + '.html' ].join('/');
          self.add(url);
          iter();
        });
      })();
    });
  });
  <commit_msg>Remove dead code.<commit_after>/**
 * Module dependencies.
 */
var kerouac = require('kerouac')
  , fs = require('fs')
  , path = require('path');

var DASHED_REGEX = /^(\d+)-(\d+)-(\d+)-(.*)/;


exports = module.exports = function(
  postHandler,
  atomFeed, rssFeed, rdfFeed, jsonFeed,
  postsDB) {
  
  var dir, options;
  
  if (typeof dir == 'object') {
    options = dir;
    dir = options.dir;
  }
  dir = dir || 'blog';
  options = options || {};
  
  
  var site = kerouac();
  
  site.on('mount', function onmount(parent) {
    // inherit settings
    this.set('layout engine', parent.get('layout engine'));
    
    this.locals.pretty = parent.locals.pretty;
  });
  
  
  site.page('/:year/:month/:day/:slug.html', postHandler);
  // FIXME: pretty URL isn't catching this
  //site.page('/index.html', require('./handlers/index')(options.layout));
  
  // https://github.com/jshttp/mime-db
  // https://help.github.com/articles/mime-types-on-github-pages/
  site.page('/feed.atom', atomFeed);
  site.page('/feed.rss', rssFeed);
  site.page('/feed.rdf', rdfFeed);
  site.page('/feed.json', jsonFeed);
  
  // TODO: implement a news-specific sitemap:
  //       https://support.google.com/webmasters/answer/74288
  // include it as a separate sitemap-news.xml
  
  site.page('/sitemap.xml', require('kerouac-sitemap')());
  
  site.bind(function(done) {
    var self = this;
    
    postsDB.list(function(err, posts) {
      if (err) { return done(err); }
      
      var el, i, len
        , url, year, month, day, slug;
      
      for (i = 0, len = posts.length; i < len; ++i) {
        el = posts[i];
        year = el.publishedAt.getUTCFullYear()
        month = (el.publishedAt.getUTCMonth() + 1)
        day = el.publishedAt.getUTCDate()
        slug = el.slug;
        
        month = (month < 10) ? ('0' + month) : month;
        day = (day < 10) ? ('0' + day) : day;
        
        url = '/' + [ year, month, day, slug + '.html' ].join('/');
        self.add(url);
      }
      
      done();
    });
  });
  
{'fraction_non_alphanumeric': 0.18100619759387532, 'fraction_numerical': 0.006926722566532993, 'mean_word_length': 1.9452495974235104, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '558041', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1899, 'n_words': 393}