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.0 KiB

6 years ago
  1. const moment = require("moment")
  2. module.exports = class {
  3. onCreate({kind, value, updated}) {
  4. this.state = {text: null, color: "color-menu", 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. const dateStr = m.format("MMM D, YYYY")
  15. this.state.text = dateStr
  16. if (updated != null && Date.parse(updated) > Date.parse(value)) {
  17. const m2 = moment(updated)
  18. this.state.tooltip = "Originally posted: " + dateStr
  19. this.state.text = m2.format("MMM D, YYYY") + " *"
  20. }
  21. break
  22. }
  23. case "tag": {
  24. this.state.color = `color-tag-${value.kind.toLowerCase()}`
  25. this.state.text = value.name
  26. break
  27. }
  28. case "author": {
  29. this.state.text = value
  30. break
  31. }
  32. default: {
  33. this.state.color = "color-menu"
  34. this.state.text = value
  35. break
  36. }
  37. }
  38. }
  39. }