hugo-theme/layouts/shortcodes/calendar.html

116 lines
2.3 KiB
HTML
Raw Normal View History

{{ $date:= .Get "date" }}
{{ if not $date }}
{{ errorf "Error: 'date' is a required parameter." }}
2024-02-13 20:55:36 +00:00
{{ end }}
{{ $date := time.AsTime $date }}
2024-02-13 20:55:36 +00:00
{{ $month := $date.Month | int }}
{{ $year := $date.Year }}
2024-02-13 20:55:36 +00:00
{{ $t1 := printf "%4d-%02d-01" $year $month }}
{{ $t1 := time.AsTime $t1 }}
{{ $t2 := $t1.AddDate 0 1 0 }}
2024-02-13 20:55:36 +00:00
{{ $daysInMonth := $t2.Sub $t1 }}
{{ $daysInMonth := $daysInMonth.Hours }}
{{ $daysInMonth := div $daysInMonth 24 }}
2024-02-13 20:55:36 +00:00
{{ $padding := $t1.Weekday | int }}
2024-02-13 20:55:36 +00:00
<div class="calendar">
<a class="month">{{ if eq .Site.Language.Lang "pl" }}{{ $polish_month_names := slice "Styczeń" "Luty" "Marzec" "Kwiecień" "Maj" "Czerwiec" "Lipiec" "Sierpień" "Wrzesień" "Październik" "Listopad" "Grudzień" }}{{ $month := sub $month 1}}{{ $label := index $polish_month_names $month }}{{ printf "%s %d" $label $year }}{{ else }}{{ time.Format "January 2006" $t1 }}{{ end }}</a>
2024-02-13 20:55:36 +00:00
<div class="days">
{{ if gt $padding 0 }}
{{ range seq 1 $padding }}
<div class="pad-day"></div>
{{ end }}
{{ end }}
2024-02-15 20:54:26 +00:00
{{ range seq 1 $daysInMonth }}
<div class="day">
{{ $startDate := printf "%4d-%02d-%02dT00:00:00" $year $month . }}
{{ $startDate := time.AsTime $startDate }}
{{ $endDate := printf "%4d-%02d-%02dT23:59:59" $year $month . }}
{{ $endDate := time.AsTime $endDate }}
{{ . }}
`
{{ range where $.Site.RegularPages "Section" "eq" "events" }}
{{ $eventStart := time.AsTime .Params.start_date | int }}
{{ if after $eventStart $startDate }}
<h2>{{ .Title }}</h2>
{{ end }}
2024-02-13 20:55:36 +00:00
{{ end }}
2024-02-15 20:54:26 +00:00
</div>
{{ end }}
{{ range where .Site.Pages "Type" "event" }}
{{ if (and (gt .Params.start_date $.Date) (lt .Params.end_date $.Date)) }}
<h2>{{ .Title }}</h2>
{{ end }}
{{ end }}
2024-02-13 20:55:36 +00:00
</div>
</div>
2024-02-13 20:55:36 +00:00
<style>
.calendar {
width: 100%;
max-width: 1000px;
margin: 20px auto;
2024-02-13 20:55:36 +00:00
padding: 0;
background-color: darkslategray;
}
a.month {
display: block;
padding: 15px 0;
margin: 0;
text-align: center;
width: 100%;
background-color: black;
}
.days {
width: calc(100% - 10px) ;
padding: 5px;
margin: auto;
display: flex;
flex-wrap: wrap;
}
.pad-day, .day {
width: calc(14.28% - 3px) ;
margin: 1.5px;
aspect-ratio: 1;
}
.day {
background-color: gray;
transition: 400ms;
}
.day:hover {
transform: scale(1.2);
background-color: black;
}
</style>