{%- capture api -%} Next events {%- 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 span_days = include.days | default: 2 -%} {%- assign span_seconds = day_seconds | times: span_days | plus: 1 -%} {%- comment -%} LOOP CALENDARS {%- endcomment -%} {%- for calendar in site.data.tempus.events -%} {%- if include.calendar == nil or include.calendar == calendar.title -%} {%- assign start = now | minus: span_seconds -%} {%- if include.past == false or include.past == "false" -%}{%- assign start = now | plus: 1 -%}{%- endif -%} {%- assign end = now | plus: span_seconds -%} {%- comment -%} CALCULATE DAYS {%- endcomment -%} {%- assign days = end | minus: start | divided_by: day_seconds | round -%} {%- comment -%} LOOP DAYS {%- endcomment -%} {%- assign present = false -%} {%- 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 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 present == false -%} {% assign present = true %} **{{ calendar.title }}** {%- endif -%} {% assign found = true %} - {{ e.day | date: format }}{% if e.title %}: {% if e.color %}{% endif %}**{{ e.title }}**{% endif %} {{ 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 -%} {%- if present == false -%} {% assign present = true %} **{{ calendar.title }}** {%- endif -%} {%- 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 %}{% endif %}{{ day | date: format }}{% if e.title %}: {% if e.color %}{% endif %}**{{ e.title }}**{% endif %} {{ difference }} {%- endif -%} {%- endfor -%} {%- endif -%} {%- endif -%} {%- endfor -%} {%- comment -%} SHOW EMPTY DAYS {%- endcomment -%} {% if include.empty and found == false %} - {{ day | date: format }} {% endif %} {%- endfor -%} {%- endif -%} {%- endfor -%}