<commit_before>'use strict';

var Project = function(obj) {
  this.title = obj.title;
  this.category = obj.category;
  this.url = obj.url;
  this.screenshot = obj.screenshot;
  this.description = obj.description;
  this.pubDate = obj.pubDate;
  this.year = obj.pubDate.slice(0,4);
};

Project.all = [];

Project.prototype.buildHtml = function() {
  var template = Handlebars.compile($('#article-template').html());
  return template(this);
};


Project.loadAll = function(data) {
  data.sort(function(a,b) {
    return (new Date(b.pubDate)) - (new Date(a.pubDate));
  });
  data.forEach(function(obj) {
    Project.all.push(new Project(obj));
  });
};







Project.serverGrab = function() {
  $.get(
    'data/projects.json',
    function(data) {
      Project.loadAll(data);
      localStorage.data = JSON.stringify(data);
      projectView.initIndex();
    },
    'JSON');
};
Project.serverGrab();<commit_msg>caching works<commit_after>'use strict';

var Project = function(obj) {
  this.title = obj.title;
  this.category = obj.category;
  this.url = obj.url;
  this.screenshot = obj.screenshot;
  this.description = obj.description;
  this.pubDate = obj.pubDate;
  this.year = obj.pubDate.slice(0,4);
};

Project.all = [];

Project.prototype.buildHtml = function() {
  var template = Handlebars.compile($('#article-template').html());
  return template(this);
};

Project.loadAll = function(data) {
  data.sort(function(a,b) {
    return (new Date(b.pubDate)) - (new Date(a.pubDate));
  });
  data.forEach(function(obj) {
    Project.all.push(new Project(obj));
  });
};

Project.fetchAll = function() {
  if (localStorage.data) {
    $.ajax({
      url: 'data/projects.json',
      type: 'HEAD',
      success: function (data, message, xhr) {
        var getETag = xhr.getResponseHeader('ETag');
        if(getETag === JSON.parse(localStorage.savedETag)) {
          Project.loadAll(JSON.parse(localStorage.data));
          projectView.initIndex();
        } else {
          Project.serverGrab();
        }
      }
    });
  } else {
    Project.serverGrab();
  }
};

Project.serverGrab = function() {
  $.ajax({
    url: 'data/projects.json',
    type: 'GET',
    dataType: 'JSON',
    success: function(rawData, message, xhr) {
      Project.loadAll(rawData);
      localStorage.data = JSON.stringify(rawData);
      projectView.initIndex();
      localStorage.savedETag = JSON.stringify(xhr.getResponseHeader('ETag'));
    }
  });
};
{'fraction_non_alphanumeric': 0.17007358953393295, 'fraction_numerical': 0.001635322976287817, 'mean_word_length': 3.2556521739130435, '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': '7185589', 'n_tokens_mistral': 827, 'n_tokens_neox': 819, 'n_words': 131}