From ace1d30442778f2df8ce0713464041d9c24fa894 Mon Sep 17 00:00:00 2001 From: ionous Date: Thu, 19 Jun 2025 13:43:50 -0700 Subject: [PATCH 1/2] one approach to adding a counter --- README.md | 2 +- .../s2b_hugo_theme/assets/js/cal/main.js | 28 ++++++++++++++++++- .../layouts/partials/cal/events.html | 7 +++++ .../layouts/partials/cal/pp-header.html | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 44a0a773..9070ff84 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ If you are writing javascript code in the node backend, you can test everything ### Local previews using production data -As an alternative to `npm run dev`, you can preview a local frontend with the actual production backend by using: `npm run -w tools preview`. +As an alternative to `npm run dev`, you can preview a local frontend with the actual production backend by using: `npm run preview`. **NOTE:** any events you create while previewing this way *will* be seen by the world! diff --git a/site/themes/s2b_hugo_theme/assets/js/cal/main.js b/site/themes/s2b_hugo_theme/assets/js/cal/main.js index 3a30b522..ff874540 100755 --- a/site/themes/s2b_hugo_theme/assets/js/cal/main.js +++ b/site/themes/s2b_hugo_theme/assets/js/cal/main.js @@ -1,5 +1,24 @@ // uses CONSTANTS from config.js +class Summary { + constructor(title) { + this.title = title; + this.before = 0; + this.after = 0; + this.now = dayjs(); + this.total = 0; + } + addEvent(evt) { + const fullTime = dayjs(`${evt.date}T${evt.time}`); + if (fullTime.isBefore(this.now)) { + ++this.before; + } else { + ++this.after; + } + ++this.total; + } +}; + $(document).ready(function() { var container = $('#mustache-html'); @@ -16,6 +35,12 @@ $(document).ready(function() { throw Error("requires id or range"); } + const today = options.today; + const start = options.startdate; + const end = options.enddate; + const inRange = today >= start && today <= end; + const viewFrom = (options.pp) ? today : start; + var opts = { type: 'GET', url: url.toString(), @@ -114,9 +139,10 @@ $(document).ready(function() { // ( as will the normal calendar events page ) // 'from' is today; for other PP pages it's options startdate. startdate: from, + startdate: start, // if there was an enddate, use it; otherwise use a fixed number of days. // subtract 1 so range is inclusive - enddate: options.enddate ? end : from.add( (DEFAULT_DAYS_TO_FETCH - 1), 'day'), + enddate: options.enddate ? end : start.add( (DEFAULT_DAYS_TO_FETCH - 1), 'day'), // pass this on to the events listing. show_details: options.show_details, }; diff --git a/site/themes/s2b_hugo_theme/layouts/partials/cal/events.html b/site/themes/s2b_hugo_theme/layouts/partials/cal/events.html index 2824aa0b..cb00bd6e 100644 --- a/site/themes/s2b_hugo_theme/layouts/partials/cal/events.html +++ b/site/themes/s2b_hugo_theme/layouts/partials/cal/events.html @@ -3,6 +3,13 @@ Mustache.tags = ["[[", "]]"]; + +