Skip to content

Commit

Permalink
Update isNewMap helper to automate end of year summary tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchts committed Jan 12, 2024
1 parent 1edda40 commit 6ca57fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/assets/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ displayUserInfo();
displayRates();
applyUserPreferences();
hideAlerts();

// check is the page is being loaded in development directory
var is_development = /\/(out|src)\//i.test(window.location.href);
var is_development = !window.location.href.includes("mcresourcepile.github.io");

// the current page directory
var current_path = window.location.pathname.replace('.html', '');
Expand Down Expand Up @@ -55,7 +55,7 @@ function getUrlParam(param) {
return param;
}

/**
/**
* Create a new or update an existing cookie.
*
* @param {string} cname The cookie name
Expand All @@ -68,12 +68,12 @@ function setCookie(cname, cvalue) {
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

/**
/**
* Get the value of a saved cookie. Returns an empty string if the cookie
* could not be found.
*
* @param {string} cname The cookie name
* @return {string} The value of the cookie
* @return {string} The value of the cookie
*/
function getCookie(cname) {
var name = cname + "=";
Expand All @@ -91,7 +91,7 @@ function getCookie(cname) {
return "";
}

/**
/**
* Displays current User information on the page.
* Username is inserted in elements with the '.user-username' class.
* Avatar is placed in images with the '.user-avatar' class.
Expand All @@ -101,7 +101,7 @@ function displayUserInfo() {
$('img.user-avatar').attr('src', user._avatar);
}

/**
/**
* Displays current User API rate limits on the page.
* Limit is inserted in elements with the '.user-rate-limit' class.
* Remaining is inserted in elements with the '.user-rate-remaining' class.
Expand Down Expand Up @@ -142,7 +142,7 @@ function hideAlerts() {
$(this).hide();
}
});

// we want to filter out any alerts that no longer exist
// so that we aren't storing trash data forever
var inactiveAlerts = user._hidden_alerts.filter(x => activeAlerts.indexOf(x) === -1);
Expand Down
16 changes: 12 additions & 4 deletions src/helpers/isNewMap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// returns true when a date is within the past 2 months
// except in the month of december, which returns true
// if the date is within the same year
//
// used to give maps a 'new' tag and highlight

module.exports = function(created) {
var threshold = new Date();
threshold = threshold.setMonth(threshold.getMonth() - 2); // 2 months ago
const today = new Date();
var threshold = new Date().setMonth(today.getMonth() - 2);
if (today.getMonth() === 11) {
threshold = new Date(`${today.getFullYear()}-01-01`);
};

// return Date.parse(created) > threshold;
return Date.parse(created) > new Date('2023-01-01');
return Date.parse(created) > threshold;
};

0 comments on commit 6ca57fe

Please sign in to comment.