const moment = require("moment") module.exports = class { onCreate({kind, weak, value, updated}) { this.state = {text: null, color: "color-menu", href: null, tooltip: null} if (value == null || value == "") { return } switch (kind) { case "date": { const m = moment(value) if (m.year() < 2) { break } if (!weak) { this.state.tooltip = `See all stories set during ${m.format("MMMM YYYY")}` this.state.href = `/story/by-month/${m.format("YYYY-MM")}/` } const dateStr = m.format("MMM D, YYYY") this.state.text = dateStr if (updated != null && Date.parse(updated) > Date.parse(value)) { const m2 = moment(updated) this.state.tooltip = "Originally posted: " + dateStr this.state.text = m2.format("MMM D, YYYY") + " *" } break } case "author": { this.state.text = value this.state.tooltip = "See all stories by " + value this.state.href = `/story/by-author/${value}/` break } default: { this.state.color = "color-menu" this.state.text = value break } } } }