mirror of https://github.com/fluxcd/website.git
calendar: use data template instead
Signed-off-by: Daniel Holbach <daniel@weave.works>
This commit is contained in:
parent
9f2fa73a24
commit
c4eb6a34e1
|
|
@ -1,7 +1,3 @@
|
|||
# Generated
|
||||
calendar_include.html
|
||||
next_event_include.html
|
||||
|
||||
# Imported
|
||||
community.md
|
||||
contributing.md
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
calendar.yaml
|
||||
|
||||
|
|
@ -25,14 +25,13 @@ from icalendar import Calendar
|
|||
import pytz
|
||||
import recurring_ical_events
|
||||
import urllib3
|
||||
import yaml
|
||||
|
||||
CAL_URL = 'https://lists.cncf.io/g/cncf-flux-dev/ics/4130481/1290943905/feed.ics'
|
||||
|
||||
TOP_LEVEL_DIR = os.path.realpath(
|
||||
os.path.join(os.path.dirname(__file__), '..'))
|
||||
CONTENT_DIR = os.path.join(TOP_LEVEL_DIR, 'content/en')
|
||||
CALENDAR_INCLUDE_HTML = os.path.join(CONTENT_DIR, 'calendar_include.html')
|
||||
NEXT_EVENT_INCLUDE_HTML = os.path.join(CONTENT_DIR, 'next_event_include.html')
|
||||
CALENDAR_YAML = os.path.join(TOP_LEVEL_DIR, 'data/calendar.yaml')
|
||||
|
||||
URL_RE = re.compile(r"((https?):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)", re.MULTILINE|re.UNICODE)
|
||||
|
||||
|
|
@ -54,7 +53,6 @@ def fix_double_url(text):
|
|||
return DOUBLE_URL_RE.sub(r"\1", text)
|
||||
|
||||
|
||||
|
||||
def download_calendar():
|
||||
http = urllib3.PoolManager()
|
||||
r = http.request('GET', CAL_URL)
|
||||
|
|
@ -73,6 +71,7 @@ def read_organizer(event):
|
|||
|
||||
return {"name": name, "email": email}
|
||||
|
||||
|
||||
def read_calendar(cal):
|
||||
events = []
|
||||
gcal = Calendar.from_ical(cal)
|
||||
|
|
@ -112,66 +111,36 @@ def format_location_html(event):
|
|||
return html
|
||||
|
||||
|
||||
def write_events_html(events):
|
||||
if os.path.exists(CALENDAR_INCLUDE_HTML):
|
||||
os.remove(CALENDAR_INCLUDE_HTML)
|
||||
def write_events_yaml(ical):
|
||||
if os.path.exists(CALENDAR_YAML):
|
||||
os.remove(CALENDAR_YAML)
|
||||
|
||||
if not events:
|
||||
if not ical:
|
||||
return
|
||||
|
||||
html = """
|
||||
<ul class="calendar-list">"""
|
||||
events = []
|
||||
for entry in ical:
|
||||
events += [{
|
||||
'date': entry['time'].strftime('%F'),
|
||||
'time': entry['time'].strftime('%H:%M'),
|
||||
'label': str(entry['title']),
|
||||
'where': format_location_html(entry),
|
||||
'org_email': entry['organizer']['email'],
|
||||
'org_name': entry['organizer']['name'],
|
||||
'description': entry['description']
|
||||
}]
|
||||
|
||||
for event in events:
|
||||
html += f"""
|
||||
<li>
|
||||
<div class="calendar-row">
|
||||
<div class="date">{event['time'].strftime('%F')}</div>
|
||||
<div class="time">{event['time'].strftime('%H:%M')}</div>
|
||||
<div class="label">{event['title']}</div>
|
||||
</div>
|
||||
<div class="calendar-card">
|
||||
<ul class="details-list">
|
||||
<li>
|
||||
<dt>Where</dt>
|
||||
<dd>{format_location_html(event)}</dd>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<dt>Organizer</dt>
|
||||
<dd><a href="mailto:{event['organizer']['email']}">{event['organizer']['name']}</a></dd>
|
||||
</li>
|
||||
</ul>
|
||||
with open(CALENDAR_YAML, 'w') as stream:
|
||||
yaml.dump(events, stream)
|
||||
stream.close()
|
||||
|
||||
<span class="description">{event['description']}</span>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
"""
|
||||
html += """
|
||||
</ul>"""
|
||||
|
||||
f = open(CALENDAR_INCLUDE_HTML, 'w')
|
||||
f.write(html)
|
||||
f.close()
|
||||
|
||||
with open(NEXT_EVENT_INCLUDE_HTML, 'w') as f:
|
||||
event = events[0]
|
||||
if not event['location'].startswith('http'):
|
||||
event['location'] = '/#calendar'
|
||||
f.write('📆 Next event: <a href="{where}">{date} {time} UTC: {title}</a>'.format(
|
||||
where=event['location'],
|
||||
date=event['time'].strftime('%F'),
|
||||
time=event['time'].strftime('%H:%M'),
|
||||
title=event['title']))
|
||||
f.close()
|
||||
|
||||
def main():
|
||||
cal = download_calendar()
|
||||
if not cal:
|
||||
sys.exit(1)
|
||||
events = read_calendar(cal)
|
||||
write_events_html(events)
|
||||
write_events_yaml(events)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,10 +1,35 @@
|
|||
{{ $_hugo_config := `{ "version": 1 }` }}
|
||||
<div class="team-calendar">
|
||||
<h3 id="calendar">Our Team Calendar</h3>
|
||||
{{ if (fileExists "/content/en/calendar_include.html") -}}
|
||||
<p class="caption">The upcoming meetings, talks and community events in the next month are listed below. (All times are UTC.)</p>
|
||||
{{ readFile "/content/en/calendar_include.html" | safeHTML }}
|
||||
{{ end }}
|
||||
|
||||
<ul class="calendar-list">
|
||||
{{ range $.Site.Data.calendar }}
|
||||
<li>
|
||||
<div class="calendar-row">
|
||||
<div class="date">{{ .date }}</div>
|
||||
<div class="time">{{ .time }}</div>
|
||||
<div class="label">{{ .label }}</div>
|
||||
</div>
|
||||
<div class="calendar-card">
|
||||
<ul class="details-list">
|
||||
<li>
|
||||
<dt>Where</dt>
|
||||
<dd>{{ .where }}</dd>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<dt>Organizer</dt>
|
||||
<dd><a href="mailto:{{ .org_email }}">{{ .org_name }}</a></dd>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<span class="description">{{ .description | safeHTML }}</span>
|
||||
</div>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
|
||||
<p class="details">See <a href="/community/#meetings">this page</a>
|
||||
for more detail and subscription options.</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,5 +2,7 @@
|
|||
{{ $blockID := printf "td-cover-block-%d" .Ordinal }}
|
||||
|
||||
<p class="next-event">
|
||||
{{- readFile "/content/en/next_event_include.html" | safeHTML -}}
|
||||
{{ range first 1 $.Site.Data.calendar }}
|
||||
📆 Next event: <a href="{{ .where }}">{{ .date }} {{ .time }} UTC: {{ .label }}</a>
|
||||
{{ end }}
|
||||
</p>
|
||||
|
|
|
|||
Loading…
Reference in New Issue