From db0000244a6f6725b3271ed0bcb1839bb5783ac2 Mon Sep 17 00:00:00 2001 From: jtbx Date: Fri, 20 Oct 2023 23:36:39 +0200 Subject: [PATCH] Home: Add calendar --- .gitignore | 2 ++ README.md | 2 ++ content/home/2-kalender/index.md | 2 +- fetch-calendar.sh | 9 ++++++++ hugo.toml | 1 + .../layouts/shortcodes/calendar-table.html | 22 +++++++++++++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 fetch-calendar.sh create mode 100644 themes/ccchh/layouts/shortcodes/calendar-table.html diff --git a/.gitignore b/.gitignore index 29db922..8b91929 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ hugo.linux /.hugo_build.lock # End of https://www.toptal.com/developers/gitignore/api/hugo + +data/ diff --git a/README.md b/README.md index 37240ee..43c8926 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ All other information like details on groups, projects and recurring events shou ### Build and Deploy +To populate the calendar data, please run `fetch-calendar.sh` before running hugo. + Running the hugo command without and parameters will re-generate the site in the `public` directory. To deploy the website, just copy the whole folder to a directory which is servered by the webserver of your preference. diff --git a/content/home/2-kalender/index.md b/content/home/2-kalender/index.md index 525fa7c..c374881 100644 --- a/content/home/2-kalender/index.md +++ b/content/home/2-kalender/index.md @@ -5,4 +5,4 @@ draft: false headless: true --- -TODO: Termine (next 5 events or full calendar?) +{{< calendar-table >}} diff --git a/fetch-calendar.sh b/fetch-calendar.sh new file mode 100755 index 0000000..6586fdb --- /dev/null +++ b/fetch-calendar.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -eu + +ICAL_URL=https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/6CJcM7XDfoYire5d +START_TIME=$(date -v-1d +%s) # yesterday +END_TIME=$(date -v+1m +%s) # now + 1 month +OUTFILE=data/calendar.json + +curl -s $ICAL_URL\?export\&accept=jcal\&expand\=1\&start\=$START_TIME\&end\=$END_TIME | jq '.[2]|map({_type:.[0]}+(.[1]|map({key:.[0],value:.[3]})|from_entries))' > $OUTFILE diff --git a/hugo.toml b/hugo.toml index 84ceee6..ab422b6 100644 --- a/hugo.toml +++ b/hugo.toml @@ -1,6 +1,7 @@ baseURL = 'https://hamburg.ccc.de/' languageCode = 'de-de' defaultContentLanguage = 'de' +timeZone = 'Europe/Berlin' title = 'CCC Hansestadt Hamburg e.V.' theme = 'ccchh' diff --git a/themes/ccchh/layouts/shortcodes/calendar-table.html b/themes/ccchh/layouts/shortcodes/calendar-table.html new file mode 100644 index 0000000..15189d7 --- /dev/null +++ b/themes/ccchh/layouts/shortcodes/calendar-table.html @@ -0,0 +1,22 @@ +{{- index .Site.Data "calendar.json" }} + + + + + + + + + + {{- range first 10 (sort $.Site.Data.calendar "dtstart" ) }} + {{- if eq ._type "vevent"}} + + {{- $start := time .dtstart }} + + + + + {{- end }} + {{- end }} + +
DatumTitelOrt
{{ $start.Local | time.Format "Mon, 2006-01-02 15:04" }}{{ .summary }}{{ .location }}