<commit_before>var moment = require('moment'),
  clc = require('cli-color'),
  extend = require('../extend'),
  util = require('../util'),
  file = util.file;

extend.console.register('new_post', 'Create a new post', function(args){
  var slug = args[0];

  if (slug === undefined){
    console.log('Usage: hexo new_post <title>');
    return false;
  }

  var date = moment().format('YYYY-MM-DD HH:mm:ss'),
    target = hexo.source_dir + '_posts/' + slug + '.md';

  var content = [
    '---',
    'layout: post',
    'title: ' + slug,
    'date: ' + date,
    'comments: true',
    'tags:',
    '---'
  ];

  file.write(target, content.join('\n') + '\n', function(err){
    if (err) throw err;
    console.log('Post created in %s', clc.bold(target));
  });
});

extend.console.register('new_page', 'Create a new page', function(args){
  var slug = args[0];

  if (slug === undefined){
    console.log('Usage: hexo new_page <title>');
    return false;
  }

  var date = moment().format('YYYY-MM-DD HH:mm:ss'),
    target = hexo.source_dir + slug + '/index.md';

  var content = [
    '---',
    'layout: page',
    'title: ' + slug,
    'date: ' + date,
    'comments: true',
    '---'
  ];

  file.write(target, content.join('\n') + '\n', function(err){
    if (err) throw err;
    console.log('Page created in %s', clc.bold(target));
  });
});<commit_msg>check existence before create a new post/page<commit_after>var moment = require('moment'),
  clc = require('cli-color'),
  fs = require('fs'),
  extend = require('../extend'),
  util = require('../util'),
  file = util.file;

extend.console.register('new_post', 'Create a new post', function(args){
  var slug = args[0];

  if (slug === undefined){
    console.log('Usage: hexo new_post <title>');
    return false;
  }

  var date = moment().format('YYYY-MM-DD HH:mm:ss'),
    target = hexo.source_dir + '_posts/' + slug + '.md';

  var content = [
    '---',
    'layout: post',
    'title: ' + slug,
    'date: ' + date,
    'comments: true',
    'tags:',
    '---'
  ];

  fs.exists(target, function(exist){
    if (exist){
      console.log('%s already exists. Use other filename instead.', clc.bold(target));
    } else {
      file.write(target, content.join('\n') + '\n', function(err){
        if (err) throw err;
        console.log('Post created in %s', clc.bold(target));
      });
    }
  });
});

extend.console.register('new_page', 'Create a new page', function(args){
  var slug = args[0];

  if (slug === undefined){
    console.log('Usage: hexo new_page <title>');
    return false;
  }

  var date = moment().format('YYYY-MM-DD HH:mm:ss'),
    target = hexo.source_dir + slug + '/index.md';

  var content = [
    '---',
    'layout: page',
    'title: ' + slug,
    'date: ' + date,
    'comments: true',
    '---'
  ];

  fs.exists(target, function(exist){
    if (exist){
      console.log('%s already exists. Use other filename instead.', clc.bold(target));
    } else {
      file.write(target, content.join('\n') + '\n', function(err){
        if (err) throw err;
        console.log('Page created in %s', clc.bold(target));
      });
    }
  });
});
{'fraction_non_alphanumeric': 0.20772176132737716, 'fraction_numerical': 0.0012763241863433313, 'mean_word_length': 2.8, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4960131', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1084, 'n_words': 256}