From 884aa451d5c57cfd117e532fa15d8340a64e8d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emrik=20=C3=96stling?= Date: Mon, 20 Nov 2023 20:09:31 +0100 Subject: [PATCH] cache studyweek --- lasvecka-node/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lasvecka-node/index.js b/lasvecka-node/index.js index 3205182..7b09ec0 100644 --- a/lasvecka-node/index.js +++ b/lasvecka-node/index.js @@ -4,13 +4,20 @@ const app = express(); const computeTime = require('./calc_date.js'); const port = process.env.PORT || 3000; +let studyweek = ''; +let studyweekNum = ''; + +function updateStudyWeek() { + studyweek = computeTime(); + studyweekNum = studyweek.replace('LV ', '').replace('Självstudier', 'S').replace('Tentavecka', 'T'); + return { studyweek, studyweekNum }; +} + app.use(express.static('public')); app.get('/', (req, res) => { - let studyweek = computeTime(); - let studyweekNum = studyweek.replace('LV ', '').replace('Självstudier', 'S').replace('Tentavecka', 'T'); - // eg. 2023-W45 - let week = moment().format('YYYY-[W]WW'); + let { studyweek, studyweekNum } = updateStudyWeek(); + let week = moment().format('YYYY-[W]WW'); // eg. 2023-W45 let data = { studyweek, week, studyweekNum }; res.send(render(data)); });