104 lines
2.4 KiB
Plaintext
104 lines
2.4 KiB
Plaintext
|
<%
|
||
|
htmlize = (text) => {
|
||
|
return (text || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||
|
};
|
||
|
|
||
|
prettyDate = (date) => {
|
||
|
// January 20, 2017 at 20:26
|
||
|
const
|
||
|
month_names = [
|
||
|
'January', 'February', 'March', 'April', 'May', 'June',
|
||
|
'July', 'August', 'September', 'October', 'November', 'December'
|
||
|
];
|
||
|
let
|
||
|
d = new Date(date),
|
||
|
has_time = d && !(d.getHours() === 0 && d.getMinutes() === 0 && d.getSeconds() === 0),
|
||
|
dArr = [];
|
||
|
if (d) {
|
||
|
dArr = [
|
||
|
month_names[d.getMonth()],
|
||
|
' ',
|
||
|
(d.getDate() < 10 ? '0' : ''),
|
||
|
d.getDate(),
|
||
|
', ',
|
||
|
d.getFullYear()
|
||
|
];
|
||
|
if (has_time) {
|
||
|
dArr = dArr
|
||
|
.concat([
|
||
|
' at ',
|
||
|
(d.getHours() < 10 ? '0' : ''),
|
||
|
d.getHours(),
|
||
|
':',
|
||
|
(d.getMinutes() < 10 ? '0' : ''),
|
||
|
d.getMinutes()
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return dArr.join('');
|
||
|
|
||
|
};
|
||
|
|
||
|
shortDate = (date) => {
|
||
|
// 2021-06-20 20:26
|
||
|
const
|
||
|
d = new Date(date),
|
||
|
has_time = d && !(d.getHours() === 0 && d.getMinutes() === 0 && d.getSeconds() === 0);
|
||
|
let dArr = [];
|
||
|
|
||
|
if (d) {
|
||
|
dArr = [
|
||
|
d.getFullYear(),
|
||
|
'-',
|
||
|
(d.getMonth() < 9 ? '0' : ''),
|
||
|
(d.getMonth() + 1),
|
||
|
'-',
|
||
|
(d.getDate() < 10 ? '0' : ''),
|
||
|
d.getDate()
|
||
|
];
|
||
|
if (has_time) {
|
||
|
dArr = dArr
|
||
|
.concat([
|
||
|
' @ ',
|
||
|
(d.getHours() < 10 ? '0' : ''),
|
||
|
d.getHours(),
|
||
|
':',
|
||
|
(d.getMinutes() < 10 ? '0' : ''),
|
||
|
d.getMinutes()
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
return dArr.join('');
|
||
|
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
snakeCase = (val) => {
|
||
|
return val.trim().toLowerCase().replace(/\W/g, '_');
|
||
|
};
|
||
|
|
||
|
sortByPath = (p1, p2) => {
|
||
|
if (p1.path < p2.path) return -1;
|
||
|
if (p1.path > p2.path) return 1;
|
||
|
return 0;
|
||
|
};
|
||
|
|
||
|
reverseSortByDate = (p1, p2) => {
|
||
|
if (p1.date_pub && p2.date_pub) {
|
||
|
let
|
||
|
p1_dt = (new Date(p1.date_pub)).getTime(),
|
||
|
p2_dt = (new Date(p2.date_pub)).getTime();
|
||
|
if (p1_dt < p2_dt) {
|
||
|
return 1;
|
||
|
}
|
||
|
if (p2_dt < p1_dt) {
|
||
|
return -1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
-%>
|