Create A calendar in Tera
It’s been a few months, so I could be remembering incorrectly, but I don’t believe that I found this anywhere. I am remembering rewriting my old Hugo template in Tera to generate my colander for my weather history calendar.
1 {%- set Year = page.year -%}
2
3 {% set First = Year~"-01-01" | date(format="%Y-%m-%d") %}
4 {%- set Last = Year~"-12-31" | date(format="%Y-%m-%d") -%}
5 {% set FirstMonth = First | date(format="%m" ) | int %}
6 {% set LastMonth = Last | date(format="%m" ) | int %}
7 {% set DaysPerMonth = config.extra.DaysPerMonth %}
8 {% set DaysOfWeek = config.extra.DaysOfWeek %}
9 {%- set PreviousYear = Year - 1 -%}
10 {%- set NextYear = Year + 1 -%}
11 {% set isLeapYear = ( Year % 4) %}
12 <article class="content">
13 <h1 id="top" class="title"> Mount Joy Personal Weather Station Data For {{ section.extra.date | date(format="%Y") }} </h1>{{ section.content | safe}}
14 {%- include "Wx/years.html" -%}
15 {%- include "Wx/months.html" -%}
16 {% for M in DaysPerMonth %}
17 <h2 class="month" id="{{- M.Name -}}"> {{- M.Name -}} </h2>
18 <ul class="days">
19 {%- if isLeapYear == 0 and M.Month == 2 -%}
20 {%- set TotalDays = 30 -%}
21 {%- else -%}
22 {%- set TotalDays = M.Days + 1 -%}
23 {%- set Date = Year~"-"~M.Month~"-"~"01" -%}
24 {%- set FirstWeekdayMondayOffset = Date | date(format="%w") | int -%}
25 {%- endif -%}
26 {%- for Day in DaysOfWeek -%}
27 <li class="weekdays">
28 {{ Day.Short }}
29 </li>
30 {% endfor %}
31 {% for D in range(start=0, end=FirstWeekdayMondayOffset) %}
32 <li class="calendar-day"></li>
33 {%- endfor -%}
34 {%- for D in range(start=1,end=TotalDays) -%}
35 {{ D }}
36 {%- endfor -%} </ul> {%- include "partials/top.html" -%}
37 {%- endfor -%}
Please don’t hesitate to use this if it will help you, and modify it as you need to make it work for your requirements.