<commit_before>var Fs = require('fs');
var Path = require('path');
var File = require('./file');

var PATH_LAYOUT = 'layout.html';
var PATH_PAGES = 'pages';
var _siteDir;

function absPath(relativePath) {
  return Path.join(_siteDir, relativePath);
}

exports.init = function(siteDir, defaultLayout) {
  console.log('Initializing the site ...');
  _siteDir = siteDir;
  File.mkdirp(_siteDir, '0777', function(err) {
    var layoutAbsPath = absPath(PATH_LAYOUT);
    if (!Fs.existsSync(layoutAbsPath)) {
      Fs.writeFileSync(layoutAbsPath, defaultLayout);
    }
  });
};

exports.respond = function(request, response, content) {
  File.serveTemplate(response, absPath(PATH_LAYOUT), {
    request: request,
    content: content
  });
};

exports.layout = function(callback) {
  Fs.readFile(absPath(PATH_LAYOUT), {encoding: 'utf8'}, function(err, data) {
    callback(err ? '' : data);
  });
};

exports.saveLayout = function(layout, callback) {
  Fs.writeFile(absPath(PATH_LAYOUT), layout, callback);
};

exports.content = function(path, callback) {
  var filePath = urlToFileAbsPath(path);
  Fs.readFile(filePath, {encoding: 'utf8'}, function(err, data) {
    callback(err ? '' : data);
  });
};

exports.saveContent = function(path, content, callback) {
  var filePath = urlToFileAbsPath(path);
  File.mkdirp(Path.dirname(filePath), '0777', function(err) {
    // if (err) throw err;
    Fs.writeFile(filePath, content, callback);
  });
};

function urlToFileAbsPath(path) {
  if (path.match(new RegExp('/$'))) {
    return absPath(PATH_PAGES + path + '_index');
  }
  else {
    return absPath(PATH_PAGES + path);
  }
}


<commit_msg>added a TODO comment<commit_after>var Fs = require('fs');
var Path = require('path');
var File = require('./file');

var PATH_LAYOUT = 'layout.html';
var PATH_PAGES = 'pages';
var _siteDir;

function absPath(relativePath) {
  return Path.join(_siteDir, relativePath);
}

exports.init = function(siteDir, defaultLayout) {
  console.log('Initializing the site ...');
  _siteDir = siteDir;
  File.mkdirp(_siteDir, '0777', function(err) {
    var layoutAbsPath = absPath(PATH_LAYOUT);
    if (!Fs.existsSync(layoutAbsPath)) {
      Fs.writeFileSync(layoutAbsPath, defaultLayout);
    }
  });
};

exports.respond = function(request, response, content) {
  File.serveTemplate(response, absPath(PATH_LAYOUT), {
    request: request,
    content: content
  });
};

exports.layout = function(callback) {
  Fs.readFile(absPath(PATH_LAYOUT), {encoding: 'utf8'}, function(err, data) {
    callback(err ? '' : data);
  });
};

exports.saveLayout = function(layout, callback) {
  Fs.writeFile(absPath(PATH_LAYOUT), layout, callback);
};

exports.content = function(path, callback) {
  var filePath = urlToFileAbsPath(path);
  Fs.readFile(filePath, {encoding: 'utf8'}, function(err, data) {
    callback(err ? '' : data);
  });
};

exports.saveContent = function(path, content, callback) {
  var filePath = urlToFileAbsPath(path);
  File.mkdirp(Path.dirname(filePath), '0777', function(err) {
    // if (err) throw err;
    Fs.writeFile(filePath, content, callback);
  });
};

function urlToFileAbsPath(path) {
  if (path.match(new RegExp('/$'))) {
    return absPath(PATH_PAGES + path + '_index');
  }
  else {
    // TODO needs to url-encode the file name
    return absPath(PATH_PAGES + path);
  }
}



{'fraction_non_alphanumeric': 0.15960324616771868, 'fraction_numerical': 0.006011421701232342, 'mean_word_length': 4.464696223316913, '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': '3974143', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1116, 'n_words': 226}