<commit_before>'use strict';

const through = require('through2');
const gutil = require('gulp-util');
const fm = require('front-matter')

const PluginError = gutil.PluginError;
const PLUGIN_NAME = 'front-matter';

module.exports = () => {
  return through.obj(function(file, encoding, cb) {
    /////////////////////////////
    // Errors
    if (file.isNull()) {
      return cb();
    }
    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
      return cb();
    }

    /////////////////////////////
    // Manipulate
    let content = fm(file.contents.toString());

    if (!file.meta) {
      file.meta = content.attributes;
    }
    else {
      file.meta = {};
    }

    file.meta.today = Date.now();

    file.contents = new Buffer(content.body);

    this.push(file);

    cb();
  });
}<commit_msg>:art: Clean up front matter plugin logic<commit_after>'use strict';

const through = require('through2');
const gutil = require('gulp-util');
const fm = require('front-matter')

const PluginError = gutil.PluginError;
const PLUGIN_NAME = 'front-matter';

module.exports = () => {
  return through.obj(function(file, encoding, cb) {
    /////////////////////////////
    // Errors
    if (file.isNull()) {
      return cb();
    }
    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
      return cb();
    }

    /////////////////////////////
    // Manipulate
    let content = fm(file.contents.toString());

    file.meta = content.attributes;
    file.meta.today = Date.now();

    file.contents = new Buffer(content.body);

    this.push(file);

    cb();
  });
}
{'fraction_non_alphanumeric': 0.21887905604719765, 'fraction_numerical': 0.0011799410029498525, 'mean_word_length': 2.2243346007604563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1332453', 'n_tokens_mistral': 533, 'n_tokens_neox': 506, 'n_words': 112}