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
31 lines
1013 B
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))
|
|
const monthStr = `${fromDate}-${month > 9 ? month : '0' + month}`
|
|
|
|
res.markoAsync(listTemplate, {
|
|
stories: storyApi.list({earliestFictionalDate: fromDate, latestFictionalDate: toDate}),
|
|
menuMonth: monthStr,
|
|
selected: {special: "month"},
|
|
})
|
|
} catch(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
|
|
module.exports = router
|