|
|
@ -0,0 +1,31 @@ |
|
|
|
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 |