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
1013 B

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