From 89e80937eec311cfa02c2397dc850cf633704f6e Mon Sep 17 00:00:00 2001 From: Lyn Fugmann Date: Fri, 4 Oct 2024 20:31:14 +0200 Subject: [PATCH] add ical generator --- _includes/program-ical.11ty.js | 66 ++++++++++++++++++++++++++++++++++ content/de/program.ical.njk | 3 ++ content/de/program.md | 2 ++ content/en/program.ical.njk | 3 ++ content/en/program.md | 2 ++ package-lock.json | 60 +++++++++++++++++++++++++++++++ package.json | 1 + 7 files changed, 137 insertions(+) create mode 100644 _includes/program-ical.11ty.js create mode 100644 content/de/program.ical.njk create mode 100644 content/en/program.ical.njk diff --git a/_includes/program-ical.11ty.js b/_includes/program-ical.11ty.js new file mode 100644 index 0000000..f00fbaf --- /dev/null +++ b/_includes/program-ical.11ty.js @@ -0,0 +1,66 @@ +const { ICalCalendar, ICalCalendarMethod } = require('ical-generator') + +module.exports = class ProgramIcal { + getDate(date, time) { + const d = new Date(date); + const [ hours, mins ] = time.split(":"); + d.setHours(hours); + d.setMinutes(mins); + return d + } + + getLocalized(item, lang) { + if (typeof item === "string") return item; + return item[lang]; + } + + data() { + return { + permalink: data => `/${data.lang}/program.ics` + } + } + + render({ ese, program, lang }) { + const url = `https://ese.ifsr.de/${ese.year}`; + + const cal = new ICalCalendar({ + name: `ESE ${ese.year}`, + url, + method: ICalCalendarMethod.PUBLISH, + }); + + for (const [date, events] of Object.entries(program)) { + for (const [i, event] of events.entries()) { + // nunjucks loops are 1-indexed by default + const id = `${date}_${i+1}`; + + let description = this.getLocalized(event.description, lang); + + if ("annotation" in event && event.annotation !== null) { + description += "\n\n"; + + (lang == "en" ? "Notice: " : "Hinweis: ") + + this.getLocalized(event.annotation, lang); + } + + if ("location" in event && event.location !== null) { + description += "\n\n" + + (lang == "en" ? "Location: " : "Veranstaltungsort: ") + + this.getLocalized(event.location, lang); + } + + cal.createEvent({ + id, + start: this.getDate(date, event.start), + end: ("end" in event && event.end !== null) + ? this.getDate(date, event.end) + : this.getDate(date, "23:59"), + summary: this.getLocalized(event.title, lang), + description, + url: `${url}/${lang}/program/#${id}`, + }); + } + } + + return cal.toString() + } +} diff --git a/content/de/program.ical.njk b/content/de/program.ical.njk new file mode 100644 index 0000000..07ff4fa --- /dev/null +++ b/content/de/program.ical.njk @@ -0,0 +1,3 @@ +--- +layout: program-ical.11ty.js +--- diff --git a/content/de/program.md b/content/de/program.md index 1b69436..c5a94bd 100644 --- a/content/de/program.md +++ b/content/de/program.md @@ -10,3 +10,5 @@ eleventyNavigation: Die ESE startet dieses Jahr am Montag, den {{ese.startDay}}. Oktober {{ese.year}}. Los geht es mit der Begrüßungsveranstaltung. Am Sonntag wird vorab schon eine Radtour angeboten. Einige Veranstaltungen übertragen wir auch Live in unserem ESE-Stream, gekennzeichnet mit diesem Symbol: {% icon "solid:video", title="Livestream" %} + +Der Wochenplan ist auch für deine Kalender-App verfügbar. Öffne oder kopiere dazu diesen Link: [ESE-Kalender](/de/program.ics) diff --git a/content/en/program.ical.njk b/content/en/program.ical.njk new file mode 100644 index 0000000..07ff4fa --- /dev/null +++ b/content/en/program.ical.njk @@ -0,0 +1,3 @@ +--- +layout: program-ical.11ty.js +--- diff --git a/content/en/program.md b/content/en/program.md index 7b1c034..9e31d6e 100644 --- a/content/en/program.md +++ b/content/en/program.md @@ -10,3 +10,5 @@ eleventyNavigation: The ESE starts this year on Monday, October {{ese.startDay}}, {{ese.year}} with the opening event. There is also a bicycle tour planned on Sunday. Some events will also be broadcast live in our ESE stream, marked with this symbol: {% icon "solid:video", title="Livestream" %} + +The schedule is also available for your calendar app. Open or copy this link: [ESE Calender](/en/program.ics) diff --git a/package-lock.json b/package-lock.json index 0d96be1..b881ab9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@fortawesome/fontawesome-free": "^6.6.0", "eleventy-plugin-gen-favicons": "^1.1.3", "eleventy-plugin-icons": "^4.5.1", + "ical-generator": "^8.0.0", "js-yaml": "^4.1.0", "markdown-it": "^14.1.0", "svg-text-to-path": "^2.0.3" @@ -2351,6 +2352,58 @@ "node": ">= 6" } }, + "node_modules/ical-generator": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/ical-generator/-/ical-generator-8.0.0.tgz", + "integrity": "sha512-CvVKK3JJrKop6z7i7/NS69FjYdR6ux1LswIeiZ3yaicX7ocMFLQI475JhQabCT7koUkaCVFNVxLaYaxtdPgwww==", + "dev": true, + "license": "MIT", + "dependencies": { + "uuid-random": "^1.3.2" + }, + "engines": { + "node": "18 || 20 || >=22.0.0" + }, + "peerDependencies": { + "@touch4it/ical-timezones": ">=1.6.0", + "@types/luxon": ">= 1.26.0", + "@types/mocha": ">= 8.2.1", + "dayjs": ">= 1.10.0", + "luxon": ">= 1.26.0", + "moment": ">= 2.29.0", + "moment-timezone": ">= 0.5.33", + "rrule": ">= 2.6.8" + }, + "peerDependenciesMeta": { + "@touch4it/ical-timezones": { + "optional": true + }, + "@types/luxon": { + "optional": true + }, + "@types/mocha": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "dayjs": { + "optional": true + }, + "luxon": { + "optional": true + }, + "moment": { + "optional": true + }, + "moment-timezone": { + "optional": true + }, + "rrule": { + "optional": true + } + } + }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -4224,6 +4277,13 @@ "requires-port": "^1.0.0" } }, + "node_modules/uuid-random": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/uuid-random/-/uuid-random-1.3.2.tgz", + "integrity": "sha512-UOzej0Le/UgkbWEO8flm+0y+G+ljUon1QWTEZOq1rnMAsxo2+SckbiZdKzAHHlVh6gJqI1TjC/xwgR50MuCrBQ==", + "dev": true, + "license": "MIT" + }, "node_modules/void-elements": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz", diff --git a/package.json b/package.json index f066cee..81f886a 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@fortawesome/fontawesome-free": "^6.6.0", "eleventy-plugin-gen-favicons": "^1.1.3", "eleventy-plugin-icons": "^4.5.1", + "ical-generator": "^8.0.0", "js-yaml": "^4.1.0", "markdown-it": "^14.1.0", "svg-text-to-path": "^2.0.3"