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

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