<commit_before>'use strict';

const mongoose = require('mongoose');
const sanitizeHtml = require('sanitize-html');
const sanitizeHtmlNoTagsConfig = {
  allowedTags: [],
  allowedAttributes: []
};
const sanitizeHtmlContent = {
  allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
};

const contentItemSchema = mongoose.Schema({
  author: {
    type: String,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  content: {
    type: String,
    set: (val) => {
      return this.content = sanitizeHtml(val, sanitizeHtmlContent);
    }
  },
  description: String,
  image: {
    src: String,
    name: String
  },
  postType: {
    type: String,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  subtitle: {
    type: String,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  title: {
    type: String,
    required: true,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  uniqueTitleKey: {
    type: String,
    default: Date.now().toString()
  },
  createdAt: {
    type: Date,
    default: new Date()
  },
  uniqueTitle: String
});

// Define a pre-save method for contentItemSchema
contentItemSchema.pre('save', function (next) {
  this.uniqueTitle = `${this.title.toLowerCase().toString()
    .replace(/[^a-z0-9+]+/gi, '-')}-${this.uniqueTitleKey}`;
  next();
});

module.exports = mongoose.model('ContentItem', contentItemSchema);<commit_msg>add native mongoose timestamp<commit_after>'use strict';

const mongoose = require('mongoose');
const sanitizeHtml = require('sanitize-html');
const sanitizeHtmlNoTagsConfig = {
  allowedTags: [],
  allowedAttributes: []
};
const sanitizeHtmlContent = {
  allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
};

const contentItemSchema = mongoose.Schema({
  author: {
    type: String,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  content: {
    type: String,
    set: (val) => {
      return this.content = sanitizeHtml(val, sanitizeHtmlContent);
    }
  },
  description: String,
  image: {
    src: String,
    name: String
  },
  postType: {
    type: String,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  subtitle: {
    type: String,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  title: {
    type: String,
    required: true,
    set: (val) => {
      return this.author = sanitizeHtml(val, sanitizeHtmlNoTagsConfig);
    }
  },
  uniqueTitleKey: {
    type: String,
    default: Date.now().toString()
  },
  uniqueTitle: String
},
  {timestamps: true});

// Define a pre-save method for contentItemSchema
contentItemSchema.pre('save', function (next) {
  this.uniqueTitle = `${this.title.toLowerCase().toString()
    .replace(/[^a-z0-9+]+/gi, '-')}-${this.uniqueTitleKey}`;
  next();
});

module.exports = mongoose.model('ContentItem', contentItemSchema);
{'fraction_non_alphanumeric': 0.15323096609085093, 'fraction_numerical': 0.0012795905310300703, 'mean_word_length': 3.4544159544159543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3089921', 'n_tokens_mistral': 1016, 'n_tokens_neox': 1034, 'n_words': 204}