Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for externally hosted calendars #519

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ $(CALENDAR_DIR):
mkdir -p $(CALENDAR_DIR)

$(CALENDAR_DIR)/%.ics: calendars/%.yaml $(CALENDAR_DIR)
yaml2ics $< > $@
@if [[ -z "$(shell grep -E 'external-ics:' $<)" ]]; then \
echo "yaml2ics $< > $@"; \
yaml2ics $< > $@; \
else \
echo "python tools/fetch-external-ics.py $< > $@"; \
python tools/fetch-external-ics.py $< > $@; \
fi

CALENDAR_SOURCES = $(wildcard calendars/*.yaml)
calendars: $(subst calendars,$(CALENDAR_DIR),$(CALENDAR_SOURCES:.yaml=.ics))
Expand Down
4 changes: 4 additions & 0 deletions assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ table.spec__table thead {
font-style: italic;
}

.calendar-list {
padding-top: 1rem;
}

.calendar-list .calendar {
padding-bottom: 1rem;
}
Expand Down
2 changes: 2 additions & 0 deletions calendars/pandas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: Pandas Community Calendar
external-ics: https://calendar.google.com/calendar/ical/pgbn14p6poja8a1cf2dv2jhrmg%40group.calendar.google.com/public/basic.ics
23 changes: 12 additions & 11 deletions layouts/calendars/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="content-padding flex-row">
<div class="shortcuts-container">
<div><i class="fa-solid fa-list"></i> On this page</div>
<div><i class="fa-solid fa-list"></i> On this page</div>
<div id="shortcuts"></div>
</div>
<div class="content-container">
Expand All @@ -20,12 +20,13 @@ <h5 class="subtitle is-5 is-muted">{{ .Params.Subtitle }}</h5>

<div class="calendar-list">
{{ range $key, $value := $.Site.Data.calendars }}
<div class="calendar"><a href="{{ $key }}.ics">{{ .name }}</a>
<img
class="calendar-copy"
src="/images/content_copy.svg"
onclick="navigator.clipboard.writeText('{{ printf "%s%s.ics" $pageLink $key }}');"
/>
{{ $url := (index $value "external-ics") | default (printf "%s%s.ics" $pageLink $key) }}
<div class="calendar">
<a href="{{ $url }}">{{ if isset $value "external-ics" }}<i class="fa fa-external-link" aria-hidden="true"></i>&nbsp;{{ end }}{{ .name }}</a>
{{ if isset $value "external-ics" }}(<i class="fas fa-sync"></i> {{ now.Format "2006/01/02" }}){{ end }}
<i class="fa-regular fa-copy calendar-copy"
onclick="navigator.clipboard.writeText('{{ $url }}');" >
</i>
{{ range .events }}
<div class="calendar-event">{{ .summary }}</div>
{{ end }}
Expand Down Expand Up @@ -56,13 +57,13 @@ <h5 class="subtitle is-5 is-muted">{{ .Params.Subtitle }}</h5>
eventSources: [
{{ range $key, $value := $.Site.Data.calendars }}
{
url: '{{ $key }}.ics',
format: 'ics',
color: cal_colors.shift(),
url: '{{ $key }}.ics',
format: 'ics',
color: cal_colors.shift(),
},
{{ end }}
],
eventClick: function(info) {
eventClick: function(info) {
info.jsEvent.preventDefault();
alert('Event: ' + info.event.title + '\n' + info.event.extendedProps.description + '\n' + 'URL: ' +info.event.url);
},
Expand Down
9 changes: 9 additions & 0 deletions tools/fetch-external-ics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import yaml
import urllib.request
import sys


data = yaml.load(open(sys.argv[1]), Loader=yaml.SafeLoader)
url = data["external-ics"]

print(urllib.request.urlopen(url).read().decode("utf-8"))