{%- capture api -%} events
-
ok
{%- endcapture -%} {%- include api/save.html -%} {%- assign now = “now” | date: “%s” | plus: 0 -%} {%- assign format = include.format | default: “%B %-d %A” -%} {%- assign day_seconds = 86400 -%} {%- assign year_seconds = day_seconds | times: 364 -%} {%- comment -%} LOOP CALENDARS {%- endcomment -%} {%- for calendar in site.data.tempus.events -%} {% if include.calendar == nil or include.calendar == calendar.title %}
**{{ calendar.title }}**
{%- if include.from or calendar.from or include.past == false -%} {%- assign start = include.from | default: calendar.from | date: "%s" | plus: 0 -%} {%- else -%} {%- assign start = "now" | date: "%s" | plus: 0 -%} {%- endif -%} {%- if include.to or calendar.to -%} {%- assign end = include.to | default: calendar.to | date: "%s" -%} {%- else -%} {%- comment -%} ADD ONE YEAR FROM THE START {%- endcomment -%} {%- assign end = start | plus: year_seconds -%} {%- endif -%} {%- comment -%} CALCULATE DAYS {%- endcomment -%} {%- assign days = end | minus: start | divided_by: day_seconds | round -%} {%- comment -%} LOOP DAYS {%- endcomment -%} {%- for d in (0..days) -%} {%- assign increment = d | times: day_seconds -%} {%- assign day = start | plus: increment -%} {%- assign week_day = day | date: "%A" -%} {%- assign loop_day = day | date: "%Y-%m-%d" -%} {%- assign found = false -%} {%- for e in calendar.events -%} {% if include.event == nil or include.event == e.title %} {%- comment -%} DAY EVENT {%- endcomment -%} {%- if e.day -%} {%- assign event_date = e.day | date: "%Y-%m-%d" -%} {%- if loop_day == event_date -%} {%- assign found = true -%} {%- assign unix = e.day | date: "%s" | plus: 0 -%} {%- assign difference = unix | plus: day_seconds | minus: now | divided_by: day_seconds | ceil | times: -1 -%} {% if difference == 0 %}{%- assign difference = "today" -%}{% endif %}
-
{% if unix <= now %}<span class=“tempus-past”>{% endif %}{{ e.day | date: format }}{% if e.title %}: {% if e.color %}<span style=“color: {{ e.color }}”>{% endif %}**{{ e.title }}**{% endif %} <span class=“tempus-difference”>{{ difference }}
{%- endif -%} {%- comment -%} WEEKLY EVENT {%- endcomment -%} {%- elsif e.weekly.day -%} {%- assign week_offset = e.weekly.offset | default: 0 -%} {%- assign week_jump = e.weekly.jump | default: 1 -%} {%- assign week = day | date: "%U" | minus: week_offset | modulo: week_jump -%} {%- assign split = e.weekly.day | split: "," -%} {%- for weekly_day in split -%} {%- assign weekly_day_stripped = weekly_day | strip -%} {%- if weekly_day_stripped == week_day and week == 0 -%} {%- assign found = true -%} {%- assign difference = day | minus: now | divided_by: day_seconds | ceil | times: -1 -%} {% if difference == 0 %}{%- assign difference = "today" -%}{% endif %}
-
{% if day <= now %}<span class=“tempus-past”>{% endif %}{{ day | date: format }}{% if e.title %}: {% if e.color %}<span style=“color: {{ e.color }}”>{% endif %}**{{ e.title }}**{% endif %} <span class=“tempus-difference”>{{ difference }}
{%- endif -%} {%- endfor -%} {%- endif -%} {%- endif -%} {%- endfor -%} {%- comment -%} SHOW EMPTY DAYS {%- endcomment -%} {% if include.empty and found == false %}
-
<span class=“tempus-empty”>{{ day | date: format }}
{% endif %}
{%- endfor -%}
{%- endif -%} {%- endfor -%}