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
|
# Imported
|
||||||
community.md
|
community.md
|
||||||
contributing.md
|
contributing.md
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
calendar.yaml
|
||||||
|
|
||||||
|
|
@ -25,14 +25,13 @@ from icalendar import Calendar
|
||||||
import pytz
|
import pytz
|
||||||
import recurring_ical_events
|
import recurring_ical_events
|
||||||
import urllib3
|
import urllib3
|
||||||
|
import yaml
|
||||||
|
|
||||||
CAL_URL = 'https://lists.cncf.io/g/cncf-flux-dev/ics/4130481/1290943905/feed.ics'
|
CAL_URL = 'https://lists.cncf.io/g/cncf-flux-dev/ics/4130481/1290943905/feed.ics'
|
||||||
|
|
||||||
TOP_LEVEL_DIR = os.path.realpath(
|
TOP_LEVEL_DIR = os.path.realpath(
|
||||||
os.path.join(os.path.dirname(__file__), '..'))
|
os.path.join(os.path.dirname(__file__), '..'))
|
||||||
CONTENT_DIR = os.path.join(TOP_LEVEL_DIR, 'content/en')
|
CALENDAR_YAML = os.path.join(TOP_LEVEL_DIR, 'data/calendar.yaml')
|
||||||
CALENDAR_INCLUDE_HTML = os.path.join(CONTENT_DIR, 'calendar_include.html')
|
|
||||||
NEXT_EVENT_INCLUDE_HTML = os.path.join(CONTENT_DIR, 'next_event_include.html')
|
|
||||||
|
|
||||||
URL_RE = re.compile(r"((https?):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)", re.MULTILINE|re.UNICODE)
|
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)
|
return DOUBLE_URL_RE.sub(r"\1", text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def download_calendar():
|
def download_calendar():
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
r = http.request('GET', CAL_URL)
|
r = http.request('GET', CAL_URL)
|
||||||
|
|
@ -73,6 +71,7 @@ def read_organizer(event):
|
||||||
|
|
||||||
return {"name": name, "email": email}
|
return {"name": name, "email": email}
|
||||||
|
|
||||||
|
|
||||||
def read_calendar(cal):
|
def read_calendar(cal):
|
||||||
events = []
|
events = []
|
||||||
gcal = Calendar.from_ical(cal)
|
gcal = Calendar.from_ical(cal)
|
||||||
|
|
@ -112,66 +111,36 @@ def format_location_html(event):
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def write_events_html(events):
|
def write_events_yaml(ical):
|
||||||
if os.path.exists(CALENDAR_INCLUDE_HTML):
|
if os.path.exists(CALENDAR_YAML):
|
||||||
os.remove(CALENDAR_INCLUDE_HTML)
|
os.remove(CALENDAR_YAML)
|
||||||
|
|
||||||
if not events:
|
if not ical:
|
||||||
return
|
return
|
||||||
|
|
||||||
html = """
|
events = []
|
||||||
<ul class="calendar-list">"""
|
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:
|
with open(CALENDAR_YAML, 'w') as stream:
|
||||||
html += f"""
|
yaml.dump(events, stream)
|
||||||
<li>
|
stream.close()
|
||||||
<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>
|
|
||||||
|
|
||||||
<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():
|
def main():
|
||||||
cal = download_calendar()
|
cal = download_calendar()
|
||||||
if not cal:
|
if not cal:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
events = read_calendar(cal)
|
events = read_calendar(cal)
|
||||||
write_events_html(events)
|
write_events_yaml(events)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,35 @@
|
||||||
{{ $_hugo_config := `{ "version": 1 }` }}
|
{{ $_hugo_config := `{ "version": 1 }` }}
|
||||||
<div class="team-calendar">
|
<div class="team-calendar">
|
||||||
<h3 id="calendar">Our Team Calendar</h3>
|
<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>
|
<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 }}
|
|
||||||
|
<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 }}
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
|
||||||
<p class="details">See <a href="/community/#meetings">this page</a>
|
<p class="details">See <a href="/community/#meetings">this page</a>
|
||||||
for more detail and subscription options.</p>
|
for more detail and subscription options.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,7 @@
|
||||||
{{ $blockID := printf "td-cover-block-%d" .Ordinal }}
|
{{ $blockID := printf "td-cover-block-%d" .Ordinal }}
|
||||||
|
|
||||||
<p class="next-event">
|
<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>
|
</p>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue