The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

6 years ago
  1. const moment = require("moment")
  2. module.exports = class {
  3. onCreate({kind, weak, value, updated}) {
  4. this.state = {text: null, color: "color-menu", href: null, tooltip: null}
  5. if (value == null || value == "") {
  6. return
  7. }
  8. switch (kind) {
  9. case "date": {
  10. const m = moment(value)
  11. if (m.year() < 2) {
  12. break
  13. }
  14. if (!weak) {
  15. this.state.tooltip = `See all stories set during ${m.format("MMMM YYYY")}`
  16. this.state.href = `/story/by-month/${m.format("YYYY-MM")}/`
  17. }
  18. const dateStr = m.format("MMM D, YYYY")
  19. this.state.text = dateStr
  20. if (updated != null && Date.parse(updated) > Date.parse(value)) {
  21. const m2 = moment(updated)
  22. this.state.tooltip = "Originally posted: " + dateStr
  23. this.state.text = m2.format("MMM D, YYYY") + " *"
  24. }
  25. break
  26. }
  27. case "author": {
  28. this.state.text = value
  29. this.state.tooltip = "See all stories by " + value
  30. this.state.href = `/story/by-author/${value}/`
  31. break
  32. }
  33. default: {
  34. this.state.color = "color-menu"
  35. this.state.text = value
  36. break
  37. }
  38. }
  39. }
  40. }