UNPKG

gpreview

Version:

Preview Ghost themes locally without a full Ghost installation

38 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dateHelper = dateHelper; function dateHelper(date, options) { if (!options) { options = date; date = this.published_at || this.created_at || new Date(); } const format = options.hash?.format || 'MMMM DD, YYYY'; if (date === null) { date = 0; } else if (date === undefined) { return ''; } const dateObj = new Date(date); if (isNaN(dateObj.getTime())) { return ''; } const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; const formatMap = { 'YYYY': dateObj.getFullYear().toString(), 'YY': dateObj.getFullYear().toString().slice(-2), 'MMMM': months[dateObj.getMonth()], 'MMM': months[dateObj.getMonth()].slice(0, 3), 'MM': (dateObj.getMonth() + 1).toString().padStart(2, '0'), 'M': (dateObj.getMonth() + 1).toString(), 'DD': dateObj.getDate().toString().padStart(2, '0'), 'D': dateObj.getDate().toString(), }; let formatted = format; Object.keys(formatMap).forEach(key => { formatted = formatted.replace(key, formatMap[key]); }); return formatted; } //# sourceMappingURL=date.js.map