<commit_before>var helper = require('./extend').helper.list(),
  render = require('./render'),
  theme = require('./theme'),
  util = require('./util'),
  file = util.file,
  yfm = util.yfm,
  async = require('async'),
  fs = require('fs'),
  moment = require('moment'),
  path = require('path'),
  swig = require('swig'),
  _ = require('underscore');

swig.init({tags: helper});

var regex = {
  excerpt: /<!--\s*more\s*-->/
};

var load = function(source, callback){
  async.waterfall([
    function(next){
      file.read(source, function(err, result){
        if (err) throw err;
        fs.stat(source, function(err, stats){
          if (err) throw err;
          next(null, result, stats);
        });
      });
    },
    function(file, stats, next){
      var meta = yfm(file);

      meta.date = _.isDate(meta.date) ? moment(meta.date) : moment(meta.date, 'YYYY-MM-DD HH:mm:ss');
      meta.updated = moment(stats.mtime);

      render.render(meta._content, 'md', function(err, result){
        if (err) throw err;

        var result = swig.compile(result)();        
        delete meta._content;

        if (result.match(regex.excerpt)){
          meta.content = result.replace(regex.excerpt, '<span id="more"></span>');
          meta.excerpt = result.split(regex.excerpt)[0];
        } else {
          meta.content = result;
        }

        callback(meta);
      });
    }
  ]);
};

exports.loadPost = function(source, category, callback){
  var config = hexo.config,
    extname = path.extname(source),
    filename = path.basename(source, extname);

  load(source, function(meta){
    if (meta.tags){
      meta.tags = _.map(meta.tags, function(item){
        return {
          name: item,
          permalink: config.tag_dir + '/' + item + '/'
        };
      });
    }

    if (category){
      var categories = category.split(path.sep);

      meta.categories = [];

      for (var i=0, len=categories.length; i<len; i++){
        var item = categories[i];

        meta.categories.push({<commit_msg>Fixed bug when tag is not an array<commit_after>var helper = require('./extend').helper.list(),
  render = require('./render'),
  theme = require('./theme'),
  util = require('./util'),
  file = util.file,
  yfm = util.yfm,
  async = require('async'),
  fs = require('fs'),
  moment = require('moment'),
  path = require('path'),
  swig = require('swig'),
  _ = require('underscore');

swig.init({tags: helper});

var regex = {
  excerpt: /<!--\s*more\s*-->/
};

var load = function(source, callback){
  var extname = path.extname(source);

  async.waterfall([
    function(next){
      file.read(source, function(err, result){
        if (err) throw err;
        fs.stat(source, function(err, stats){
          if (err) throw err;
          next(null, result, stats);
        });
      });
    },
    function(file, stats, next){
      var meta = yfm(file);

      meta.date = _.isDate(meta.date) ? moment(meta.date) : moment(meta.date, 'YYYY-MM-DD HH:mm:ss');
      meta.updated = moment(stats.mtime);

      render.render(meta._content, extname, function(err, result){
        if (err) throw err;

        var result = swig.compile(result)();        
        delete meta._content;

        if (result.match(regex.excerpt)){
          meta.content = result.replace(regex.excerpt, '<span id="more"></span>');
          meta.excerpt = result.split(regex.excerpt)[0];
        } else {
          meta.content = result;
        }

        callback(meta);
      });
    }
  ]);
};

exports.loadPost = function(source, category, callback){
  var config = hexo.config,
    extname = path.extname(source),
    filename = path.basename(source, extname);

  load(source, function(meta){
    if (_.isArray(meta.tags)){
      meta.tags = _.map(meta.tags, function(item){
        return {
          name: item,
          permalink: config.tag_dir + '/' + item + '/'
        };
      });
    } else if (_.isString(meta.tags)){
      meta.tags = [{name: meta.tags, permalink: config.tag_dir + '/' + meta.tags + '/'}];
    }

    if (category){
      var categories = category.split(path.sep);

      meta.categories = [];

      for (var i=0, len=categories.length; i<len; i++){
        var item = categories[i];

        meta.categories.push({
{'fraction_non_alphanumeric': 0.17524077989194267, 'fraction_numerical': 0.0009396288466055908, 'mean_word_length': 2.436642453591606, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '7169968', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1341, 'n_words': 284}