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.

31 lines
1.0 KiB

  1. const moment = require("moment")
  2. const express = require("express")
  3. const router = express.Router()
  4. const common = require("./common")
  5. const {storyApi} = require("../../rpdata/api/Story")
  6. const listTemplate = require("../../marko/page/story/list.marko")
  7. router.get("/:yearmonth(\-{0,1}[0-9]{4}\-[0-9]{1,2})", common, async(req, res) => {
  8. try {
  9. const [year, month] = req.params.yearmonth.split("-").map(t => parseInt(t, 10))
  10. if (month > 12) {
  11. return res.status(400).end(`${month} is not a valid month number`)
  12. }
  13. // Month is zero-based, while input is one-based.
  14. const fromDate = new Date(Date.UTC(year, month - 1, 1))
  15. const toDate = new Date(Date.UTC(year, month, 1))
  16. res.markoAsync(listTemplate, {
  17. stories: storyApi.list({earliestFictionalDate: fromDate, latestFictionalDate: toDate}),
  18. menuMonth: {url: moment.utc(fromDate).format("YYYY-MM"), text: moment.utc(fromDate).format("MMMM YYYY")},
  19. selected: {special: "month"},
  20. })
  21. } catch(err) {
  22. console.error(err)
  23. }
  24. })
  25. module.exports = router