Skip to content

Commit ade467c

Browse files
changed office hours banner to use ical (#1221)
. replace ms embed with table.… disable mkdocs2 warning --------- Co-authored-by: nesi-mkdocs-bot <bots-mkdocs@nesi.org.nz>
1 parent 0bcf390 commit ade467c

File tree

12 files changed

+130
-38
lines changed

12 files changed

+130
-38
lines changed

.github/fetch_includes.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MODULES_UPDATE_URL="https://raw.githubusercontent.com/nesi/modules-list/main/rss
55
GLOSSARY_URL="https://raw.githubusercontent.com/nesi/nesi-wordlist/main/outputs/glossary.md"
66
DICTIONARY_URL="https://raw.githubusercontent.com/nesi/nesi-wordlist/main/outputs/dictionary.txt"
77
SNIPPETS_URL="https://raw.githubusercontent.com/nesi/nesi-wordlist/main/outputs/snippets.md"
8-
ICAL_URL="https://calendar.google.com/calendar/ical/c_hen6rr02et39kat2hmuamidots@group.calendar.google.com/public/basic.ics"
8+
ICAL_URL="https://outlook.office365.com/owa/calendar/3d4e3c7b28ca4549803470b109cba86a@reannz.co.nz/0830583db389420aaa843dc231af48d810099982634588501079/calendar.ics"
99

1010
mkdir -p docs/assets/glossary
1111

@@ -18,3 +18,4 @@ python3 .github/workflows/link_apps_pages.py
1818
wget -q -O overrides/partials/glossary.html "${GLOSSARY_URL}"
1919
wget -q -O docs/assets/glossary/dictionary.txt "${DICTIONARY_URL}"
2020
wget -q -O docs/assets/glossary/snippets.md "${SNIPPETS_URL}"
21+

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ jobs:
173173
fetch-depth: 0
174174
- run: pip3 install -r requirements.txt
175175
- run: ./checks/run_test_build.py
176-
- run: python3 checks/run_aria_check.py
176+
- run: export NO_MKDOCS_2_WARNING="1"; python3 checks/run_aria_check.py

.github/workflows/demo_deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Deploy PR branches
22
on:
33
pull_request:
4-
branches-ignore: "assets-update"
4+
branches-ignore: ["assets-update"]
55
env:
66
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77
TARGET_REPO: "mkdocs-demo-deploy"
@@ -10,6 +10,7 @@ env:
1010
DEPLOY_URL: "https://callumwalley.github.io/mkdocs-demo-deploy"
1111
HEAD: ${{ github.event.pull_request.head.ref }}
1212
GH_REPO: ${{ github.repository }}
13+
NO_MKDOCS_2_WARNING: "1"
1314
permissions: write-all
1415
jobs:
1516
demo-deploy:

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
env:
99
PYTHON_VERSION: 3.14.2
1010
GH_TOKEN: ${{ github.token }}
11+
NO_MKDOCS_2_WARNING: "1"
12+
1113
permissions:
1214
contents: write
1315
pull-requests: write

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"reveal":"never",
8383
"showReuseMessage": false
8484
},
85-
"command": "./checks/run_test_build.py",
85+
"command": "export NO_MKDOCS_2_WARNING=1 && ./checks/run_test_build.py",
8686
"problemMatcher": {
8787
"severity": "info",
8888
"pattern": {
@@ -163,7 +163,7 @@
163163
"reveal":"never",
164164
"showReuseMessage": false
165165
},
166-
"command": "mkdocs serve --dirty"
166+
"command": "export NO_MKDOCS_2_WARNING=1 && mkdocs serve --dirty"
167167
},
168168
]
169169
}

docs/Getting_Started/Weekly_Online_Office_Hours.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ description: |
1919

2020
## Office Hours Dates
2121

22-
Click on the links below to view the upcoming office hours:
23-
24-
<iframe src="https://outlook.office365.com/owa/calendar/3d4e3c7b28ca4549803470b109cba86a@reannz.co.nz/0830583db389420aaa843dc231af48d810099982634588501079/calendar.html" style="border-width:0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
22+
<link rel="stylesheet" href='/assets/stylesheets/office-hours-calendar.css'>
23+
<div id="office-hours-calendar">
24+
<p id="office-hours-calendar-message">Loading Calendar...</p>
25+
</div>
26+
<script src='/assets/javascripts/officeHours.js'></script>
2527

2628
If you are unable to add an Office Hour session to your calendar through
2729
these links, please email us at [training@reannz.co.nz](mailto:training@reannz.co.nz) and we can send a

docs/assets/javascripts/general.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const CALENDAR_ID = "c_hen6rr02et39kat2hmuamidots@group.calendar.google.com";
21
const MEETING_LINK = "https://nesi.zoom.us/j/83987449505?pwd=TzlYTk9pdGJXZFZVSUxhUFUyeFYrUT09";
32

43
function changeVersion(app, version, warn = false) {
@@ -36,27 +35,30 @@ async function showOfficeBanner() {
3635
.then(r => r.ok ? r.text() : "");
3736
if (!text) { console.warn("failed to load calendar ") };
3837

39-
4038
const now = new Date();
41-
let allmatch = text.matchAll(/DTSTART:(\d+T\d+Z)/g);
42-
// Extract all dates.
43-
for (const t of allmatch) {
44-
if (!t) continue;
45-
let d = format8601(t[1]);
46-
// if today
47-
if (now.toDateString() == d.toDateString()) {
48-
// if not finished.
49-
if (now.getTime() < d.getTime() + 3600000) {
50-
// if not started
51-
if (now < d) {
52-
addBanner(`<p><a href="https://docs.nesi.org.nz/Getting_Started/Getting_Help/Weekly_Online_Office_Hours/">Weekly Online Office Hour</a> on today, starting ${d.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}. Drop in for any queries.`, "calendar-banner");
53-
54-
} else {
55-
addBanner(`<p><a href="https://docs.nesi.org.nz/Getting_Started/Getting_Help/Weekly_Online_Office_Hours/">Weekly Online Office Hour</a> on now. <a href="${MEETING_LINK}">Join Zoom Meeting Now</a> for any queries.</p>`, "calendar-banner");
39+
try {
40+
const jcal = ICAL.parse(text);
41+
const comp = new ICAL.Component(jcal);
42+
const vevents = comp.getAllSubcomponents('vevent');
43+
for (const vevent of vevents) {
44+
const dtstart = vevent.getFirstPropertyValue('dtstart');
45+
const date = dtstart.toJSDate();
46+
// if today
47+
if (now.toDateString() == date.toDateString()) {
48+
// if not finished.
49+
if (now.getTime() < date.getTime() + 3600000) {
50+
// if not started
51+
if (now < date) {
52+
addBanner(`<p><a href="https://docs.nesi.org.nz/Getting_Started/Getting_Help/Weekly_Online_Office_Hours/">Weekly Online Office Hour</a> on today, starting ${date.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}. Drop in for any queries.`, "calendar-banner");
53+
} else {
54+
addBanner(`<p><a href="https://docs.nesi.org.nz/Getting_Started/Getting_Help/Weekly_Online_Office_Hours/">Weekly Online Office Hour</a> on now. <a href="${MEETING_LINK}">Join Zoom Meeting Now</a> for any queries.</p>`, "calendar-banner");
55+
}
5656
}
57+
break;
5758
}
58-
break;
5959
}
60+
} catch (error) {
61+
console.warn("ICAL parsing failed", error);
6062
}
6163
}
6264

@@ -81,14 +83,15 @@ function format8601(str){
8183
const dateStringFormatted =
8284
str.substring(0, 4) + '-' +
8385
str.substring(4, 6) + '-' +
84-
str.substring(6, 8) +
85-
str.substring(8, 9) +
86+
str.substring(6, 8) + 'T' +
8687
str.substring(9, 11) + ':' +
8788
str.substring(11, 13) + ':' +
88-
str.substring(13, 15) +
89-
str.substring(15, 16);
89+
str.substring(13, 15) + '+12:00';
9090
return new Date(dateStringFormatted);
9191
}
92+
93+
showOfficeBanner();
94+
9295
// Remove me later
9396
// showOfficeBanner().then(() => {
9497
// if (!document.getElementById("calendar-banner")){
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
async function displayOfficeHoursCalendar() {
2+
const calendarDiv = document.getElementById('office-hours-calendar');
3+
const calendarP = document.getElementById('office-hours-calendar-message');
4+
if (!calendarDiv) return;
5+
6+
const text = await fetch("/assets/training_calendar.ics")
7+
.then(r => r.ok ? r.text() : "");
8+
if (!text) {
9+
calendarP.innerHTML = 'Failed to load calendar.';
10+
return;
11+
}
12+
13+
try {
14+
const jcal = ICAL.parse(text);
15+
const comp = new ICAL.Component(jcal);
16+
const events = comp.getAllSubcomponents('vevent').map(vevent => {
17+
const summary = vevent.getFirstPropertyValue('summary');
18+
const dtstart = vevent.getFirstPropertyValue('dtstart');
19+
const description = (vevent.getFirstPropertyValue('description') || '').replace(/\\n/g, '\n').replace(/\\,/g, ',');
20+
const urlMatch = description.match(/(https?:\/\/[^\s]+)/);
21+
const start = dtstart.toJSDate();
22+
return {
23+
title: summary,
24+
start,
25+
description,
26+
meetingLink: urlMatch ? urlMatch[1] : MEETING_LINK,
27+
day: start.toLocaleDateString('en-US', { weekday: 'long' }),
28+
date: start.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }),
29+
time: start.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
30+
};
31+
});
32+
33+
// Sort events by date
34+
events.sort((a, b) => a.start - b.start);
35+
36+
// Create table
37+
const tableWrap = document.createElement('div');
38+
tableWrap.className = 'md-typeset__table'
39+
const table = document.createElement('table');
40+
let rows = '';
41+
events.forEach(event => {
42+
rows += `
43+
<tr>
44+
<td>${event.day}, ${event.date}</td>
45+
<td>${event.time}</td>
46+
<td><a href=" webcal://assets/training_calendar.ics" download class="md-button md-button--addcal"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M680-80v-120H560v-80h120v-120h80v120h120v80H760v120h-80Zm-480-80q-33 0-56.5-23.5T120-240v-480q0-33 23.5-56.5T200-800h40v-80h80v80h240v-80h80v80h40q33 0 56.5 23.5T760-720v244q-20-3-40-3t-40 3v-84H200v320h280q0 20 3 40t11 40H200Zm0-480h480v-80H200v80Zm0 0v-80 80Z"/></svg>Add to Calendar</a></td>
47+
</tr>
48+
`;
49+
});
50+
table.innerHTML = `<tbody>${rows}</tbody>`;
51+
tableWrap.appendChild(table);
52+
calendarDiv.appendChild(tableWrap);
53+
calendarP.innerHTML = '';
54+
} catch (error) {
55+
console.error('Error parsing ICS:', error);
56+
calendarP.innerHTML = '<div class="admonition bug"><p class="admonition-title">Error loading Calendar.</p></div>';
57+
}
58+
}
59+
window.addEventListener("load", displayOfficeHoursCalendar);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.md-button.md-button--addcal {
2+
padding: 0.1em;
3+
margin: auto;
4+
font-size: medium;
5+
padding: 0.5em;
6+
}
7+
.md-button.md-button--addcal > svg {
8+
height: 24px;
9+
margin: auto;
10+
vertical-align: middle;
11+
}
12+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ extra_javascript:
126126
- https://status.nesi.org.nz/embed/script.js
127127
- assets/javascripts/mathjax.js
128128
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
129+
- https://cdnjs.cloudflare.com/ajax/libs/ical.js/1.3.0/ical.min.js

0 commit comments

Comments
 (0)