work on cal shorcode - now only needs a date, will auto calc pad days and month length

This commit is contained in:
Jakub 2024-02-14 00:25:55 -05:00
parent c2532014be
commit 2f1228da9a
2 changed files with 27 additions and 22 deletions

View File

@ -1,29 +1,31 @@
{{ $month := .Get "month" }} {{ $date:= .Get "date" }}
{{ if not $month }} {{ if not $date }}
{{ errorf "Error: 'month' is a required parameter." }} {{ errorf "Error: 'date' is a required parameter." }}
{{ end }} {{ end }}
{{ $date := time.AsTime $date }}
{{ $year := .Get "year" }} {{ $month := $date.Month | int }}
{{ if not $year }} {{ $year := $date.Year }}
{{ errorf "Error: 'year' is a required parameter." }}
{{ end }}
{{ $label := .Get "label" }} {{ $t1 := printf "%4d-%02d-01" $year $month }}
{{ if not $label }} {{ $t1 := time.AsTime $t1 }}
{{ errorf "Error: 'label' is a required parameter." }} {{ $t2 := $t1.AddDate 0 1 0 }}
{{ end }}
{{ $daysInMonth := $t2.Sub $t1 }}
{{ $daysInMonth := $daysInMonth.Hours }}
{{ $daysInMonth := div $daysInMonth 24 }}
{{ $daysInMonth := 27 }} {{ $padding := $t1.Weekday | int }}
<div class="calendar"> <div class="calendar">
<a class="month">{{ time.Format "January 2006" "01 Dec 2024" }}</a> <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>
<div class="days"> <div class="days">
{{ $padding := 4 }} {{ if gt $padding 0 }}
{{ range seq 1 1}} {{ range seq 1 $padding }}
<div class="pad-day"></div> <div class="pad-day"></div>
{{ end }} {{ end }}
{{ end }}
{{ range seq 1 $daysInMonth }} {{ range seq 1 $daysInMonth }}
<div class="day">{{ . }}</div> <div class="day">{{ . }}</div>
{{ end }} {{ end }}
@ -31,10 +33,12 @@
</div> </div>
<style> <style>
.calendar { .calendar {
width: 100%; width: 100%;
margin: 20px 0; max-width: 1000px;
margin: 20px auto;
padding: 0; padding: 0;
background-color: darkslategray; background-color: darkslategray;
} }
@ -77,4 +81,4 @@
</style> </style>

View File

@ -118,8 +118,9 @@ a.home-link { display: none; }
.menu-btn:checked ~ .menu .menu-entries { .menu-btn:checked ~ .menu .menu-entries {
/* Reveal Entries */ /* Reveal Entries */
height: auto; height: auto;
max-height: 900px; /* May Need to be change manually for nav lists */ max-height: 75%; /* May Need to be change manually for nav lists */
} overflow: scroll;
}
.menu-btn:checked ~ .menu .logo, .menu-entries a:hover { .menu-btn:checked ~ .menu .logo, .menu-entries a:hover {
/* BG Color on logo an hover effect */ /* BG Color on logo an hover effect */