|
14 | 14 | ) }} |
15 | 15 | </div> |
16 | 16 |
|
17 | | - {{- .Scratch.Set "contributorContent" (dict) -}} |
| 17 | + {{/* --- STEP 1: SCAN CONTENT AND NORMALIZE CONTRIBUTIONS --- */}} |
| 18 | + {{/* We build a map: Slug -> Slice of Contribution Objects {Page, Year, Role} */}} |
| 19 | + {{- .Scratch.Set "contributorMap" (dict) -}} |
| 20 | + |
18 | 21 | {{- $contentSectionsToScan := slice "blog" "workshops" -}} |
19 | 22 | {{- $contentTypesToScan := slice "hacking-hours" "initiatives" "student-talks" -}} |
20 | | - |
21 | | - {{/* --- UPDATED LOGIC START --- */}} |
22 | | - {{/* Get all pages that might have contributors (authors OR credits) */}} |
| 23 | + |
| 24 | + {{/* Get all pages that might have contributors */}} |
23 | 25 | {{- $allPotentialPages := where site.RegularPages "Type" "in" (union $contentSectionsToScan $contentTypesToScan) -}} |
24 | 26 |
|
25 | | - {{- range $allPotentialPages -}} |
26 | | - {{- $page := . -}} |
27 | | - |
28 | | - {{- if and $page.Date (not $page.Date.IsZero) -}} |
29 | | - |
30 | | - {{/* 1. Process Authors */}} |
31 | | - {{- if $page.Params.author -}} |
32 | | - {{- $authors := cond (reflect.IsSlice $page.Params.author) $page.Params.author (slice $page.Params.author) -}} |
33 | | - {{- range $authorName := $authors -}} |
34 | | - {{- $nameForProcessing := $authorName | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" -}} |
35 | | - {{- $slug := $nameForProcessing | anchorize -}} |
36 | | - |
37 | | - {{- $currentMap := $.Scratch.Get "contributorContent" -}} |
38 | | - {{- $existingContributions := index $currentMap $slug | default (slice) -}} |
39 | | - {{/* Avoid duplicates if someone is listed twice on one page */}} |
40 | | - {{- if not (in $existingContributions $page) -}} |
41 | | - {{- $newContributions := $existingContributions | append $page -}} |
42 | | - {{- $.Scratch.SetInMap "contributorContent" $slug $newContributions -}} |
43 | | - {{- end -}} |
44 | | - {{- end -}} |
45 | | - {{- end -}} |
46 | | - |
47 | | - {{/* 2. Process Production Credits */}} |
48 | | - {{- if $page.Params.production_credits -}} |
49 | | - {{- range $credit := $page.Params.production_credits -}} |
50 | | - {{- $nameForProcessing := $credit.name | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" -}} |
51 | | - {{- $slug := $nameForProcessing | anchorize -}} |
52 | | - |
53 | | - {{- $currentMap := $.Scratch.Get "contributorContent" -}} |
54 | | - {{- $existingContributions := index $currentMap $slug | default (slice) -}} |
55 | | - {{/* Avoid duplicates if someone is author AND credit on same page */}} |
56 | | - {{- if not (in $existingContributions $page) -}} |
57 | | - {{- $newContributions := $existingContributions | append $page -}} |
58 | | - {{- $.Scratch.SetInMap "contributorContent" $slug $newContributions -}} |
59 | | - {{- end -}} |
60 | | - {{- end -}} |
61 | | - {{- end -}} |
62 | | - |
63 | | - {{- end -}} |
| 27 | + {{- range $page := $allPotentialPages -}} |
| 28 | + {{- if or $page.Date (not $page.Date.IsZero) -}} |
| 29 | + |
| 30 | + {{/* Logic Branch A: Page has 'active_contributors' (Granular Year Control) */}} |
| 31 | + {{- if $page.Params.active_contributors -}} |
| 32 | + {{- range $yearBlock := $page.Params.active_contributors -}} |
| 33 | + {{- $year := string $yearBlock.year -}} |
| 34 | + {{- range $name := $yearBlock.names -}} |
| 35 | + {{- $slug := $name | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" | anchorize -}} |
| 36 | + {{- $contribObj := dict "Page" $page "Year" $year "Role" "Contributor" -}} |
| 37 | + |
| 38 | + {{- $currentMap := $.Scratch.Get "contributorMap" -}} |
| 39 | + {{- $existing := index $currentMap $slug | default slice -}} |
| 40 | + {{- $.Scratch.SetInMap "contributorMap" $slug ($existing | append $contribObj) -}} |
| 41 | + {{- end -}} |
| 42 | + {{- end -}} |
| 43 | + |
| 44 | + {{/* Logic Branch B: Standard Page (Authors + Credits + Legacy Date Ranges) */}} |
| 45 | + {{- else -}} |
| 46 | + {{- $yearsToCredit := slice ($page.Date.Format "2006") -}} |
| 47 | + |
| 48 | + {{/* Handle Legacy Initiatives Date Ranges */}} |
| 49 | + {{- if and (eq (lower $page.Type) "initiatives") $page.Params.legacy -}} |
| 50 | + {{- $dateEndVal := "" -}} |
| 51 | + {{- if isset $page.Params "date_end" }}{{ $dateEndVal = $page.Params.date_end }}{{ else if isset $page.Params "date-end" }}{{ $dateEndVal = index $page.Params "date-end" }}{{ end -}} |
| 52 | + {{- with $dateEndVal -}} |
| 53 | + {{- with time.AsTime . -}} |
| 54 | + {{- $startYear := $page.Date.Format "2006" | int -}} |
| 55 | + {{- $endYear := .Year -}} |
| 56 | + {{- if gt $endYear $startYear -}} |
| 57 | + {{- range seq (add $startYear 1) $endYear -}} |
| 58 | + {{- $yearsToCredit = $yearsToCredit | append (string .) -}} |
| 59 | + {{- end -}} |
| 60 | + {{- end -}} |
| 61 | + {{- end -}} |
| 62 | + {{- end -}} |
| 63 | + {{- end -}} |
| 64 | + |
| 65 | + {{/* Loop through calculated years (usually just one) */}} |
| 66 | + {{- range $year := $yearsToCredit -}} |
| 67 | + |
| 68 | + {{/* 1. Authors */}} |
| 69 | + {{- if $page.Params.author -}} |
| 70 | + {{- $authors := cond (reflect.IsSlice $page.Params.author) $page.Params.author (slice $page.Params.author) -}} |
| 71 | + {{- range $authorName := $authors -}} |
| 72 | + {{- $slug := $authorName | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" | anchorize -}} |
| 73 | + {{- $contribObj := dict "Page" $page "Year" $year "Role" "Author" -}} |
| 74 | + {{- $currentMap := $.Scratch.Get "contributorMap" -}} |
| 75 | + {{- $existing := index $currentMap $slug | default slice -}} |
| 76 | + {{/* Deduplicate: Check if we already added this page for this year/slug (simple check) */}} |
| 77 | + {{- $alreadyExists := false -}} |
| 78 | + {{- range $e := $existing -}} |
| 79 | + {{- if and (eq $e.Page $page) (eq $e.Year $year) (eq $e.Role "Author") -}}{{ $alreadyExists = true }}{{- end -}} |
| 80 | + {{- end -}} |
| 81 | + {{- if not $alreadyExists -}} |
| 82 | + {{- $.Scratch.SetInMap "contributorMap" $slug ($existing | append $contribObj) -}} |
| 83 | + {{- end -}} |
| 84 | + {{- end -}} |
| 85 | + {{- end -}} |
| 86 | + |
| 87 | + {{/* 2. Production Credits */}} |
| 88 | + {{- if $page.Params.production_credits -}} |
| 89 | + {{- range $credit := $page.Params.production_credits -}} |
| 90 | + {{- $slug := $credit.name | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" | anchorize -}} |
| 91 | + {{- $contribObj := dict "Page" $page "Year" $year "Role" $credit.role -}} |
| 92 | + {{- $currentMap := $.Scratch.Get "contributorMap" -}} |
| 93 | + {{- $existing := index $currentMap $slug | default slice -}} |
| 94 | + {{- $.Scratch.SetInMap "contributorMap" $slug ($existing | append $contribObj) -}} |
| 95 | + {{- end -}} |
| 96 | + {{- end -}} |
| 97 | + |
| 98 | + {{- end -}} {{/* End Year Loop */}} |
| 99 | + {{- end -}} {{/* End Branch B */}} |
| 100 | + {{- end -}} |
64 | 101 | {{- end -}} |
65 | | - {{/* --- UPDATED LOGIC END --- */}} |
66 | | - |
67 | | - {{- $allContributorProfiles := where site.RegularPages "Section" "contributors" -}} |
68 | | - {{- $contributorContentMap := .Scratch.Get "contributorContent" -}} |
69 | 102 |
|
| 103 | + {{/* --- STEP 2: AGGREGATE YEARS --- */}} |
| 104 | + {{- $contributorMap := .Scratch.Get "contributorMap" -}} |
70 | 105 | {{- $allYearsSlice := slice -}} |
71 | | - {{- range $slug, $pages := $contributorContentMap -}} |
72 | | - {{- range $page := $pages -}} |
73 | | - {{- $allYearsSlice = $allYearsSlice | append ($page.Date.Format "2006") -}} |
74 | | - {{- if and (eq (lower $page.Type) "initiatives") $page.Params.legacy -}} |
75 | | - {{- $dateEndVal := "" -}} |
76 | | - {{- if isset $page.Params "date_end" }}{{ $dateEndVal = $page.Params.date_end }}{{ else if isset $page.Params "date-end" }}{{ $dateEndVal = index $page.Params "date-end" }}{{ end -}} |
77 | | - {{- with $dateEndVal -}} |
78 | | - {{- with time.AsTime . -}} |
79 | | - {{- range seq ($page.Date.Format "2006" | int) .Year -}} |
80 | | - {{- $allYearsSlice = $allYearsSlice | append (string .) -}} |
81 | | - {{- end -}} |
82 | | - {{- end -}} |
83 | | - {{- end -}} |
84 | | - {{- end -}} |
85 | | - {{- end -}} |
| 106 | + |
| 107 | + {{- range $slug, $contributions := $contributorMap -}} |
| 108 | + {{- range $c := $contributions -}} |
| 109 | + {{- $allYearsSlice = $allYearsSlice | append $c.Year -}} |
| 110 | + {{- end -}} |
86 | 111 | {{- end -}} |
87 | 112 | {{- $uniqueYearsSorted := $allYearsSlice | uniq | sort | collections.Reverse -}} |
88 | 113 |
|
| 114 | + {{/* --- STEP 3: RENDER BY YEAR --- */}} |
89 | 115 | {{- $contributionSectionDefs := slice |
90 | | - (dict "id" "blog" "plural" "Blog Posts" "matchField" "Section") |
91 | | - (dict "id" "workshops" "plural" "Workshops" "matchField" "Section") |
92 | | - (dict "id" "student-talks" "plural" "Student Talks" "matchField" "Type") |
93 | | - (dict "id" "hacking-hours" "plural" "Hacking Hours" "matchField" "Type") |
| 116 | + (dict "id" "blog" "plural" "Blog Posts" "matchField" "Section") |
| 117 | + (dict "id" "workshops" "plural" "Workshops" "matchField" "Section") |
| 118 | + (dict "id" "student-talks" "plural" "Student Talks" "matchField" "Type") |
| 119 | + (dict "id" "hacking-hours" "plural" "Hacking Hours" "matchField" "Type") |
94 | 120 | -}} |
95 | 121 |
|
96 | 122 | {{- range $year_str := $uniqueYearsSorted -}} |
97 | | - {{- $current_loop_year := int $year_str -}} |
98 | | - <div class="year-section mb-6"> |
99 | | - <h2 class="text-3xl text-center font-bold mb-10 pb-2">{{ $year_str }} Contributors</h2> |
100 | | - {{- $contributorsInThisYear := slice -}} |
101 | | - {{- range $contributorProfilePage := $allContributorProfiles -}} |
102 | | - {{- $contributorName := $contributorProfilePage.Title -}} |
103 | | - {{- $nameForProcessing := $contributorName | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" -}} |
104 | | - {{- $slug := $nameForProcessing | anchorize -}} |
105 | | - |
106 | | - {{- with index $contributorContentMap $slug -}} |
107 | | - {{- $authoredPages := . -}} |
108 | | - {{- $contributionsThisYearBadges := dict -}} |
109 | | - {{- $initiativesLedThisYear := slice -}} |
110 | | - {{- range $contentPage := $authoredPages -}} |
111 | | - {{- $contentItemStartYear := $contentPage.Date.Format "2006" | int -}} |
112 | | - {{- $isActualInitiativePage := eq (lower $contentPage.Type) "initiatives" -}} |
113 | | - {{- $countThisItemForThisYearLoop := false -}} |
114 | | - {{- if $isActualInitiativePage -}} |
115 | | - {{- if $contentPage.Params.legacy -}} |
116 | | - {{- $endYear := $contentItemStartYear -}} |
117 | | - {{- $dateEndVal := "" -}} |
118 | | - {{- if isset $contentPage.Params "date_end" }}{{ $dateEndVal = $contentPage.Params.date_end }}{{ else if isset $contentPage.Params "date-end" }}{{ $dateEndVal = index $contentPage.Params "date-end" }}{{ end -}} |
119 | | - {{- with $dateEndVal -}}{{- with time.AsTime . -}}{{- $endYear = .Year -}}{{- end -}}{{- end -}} |
120 | | - {{- if and (ge $current_loop_year $contentItemStartYear) (le $current_loop_year $endYear) -}} |
121 | | - {{- $countThisItemForThisYearLoop = true -}} |
122 | | - {{- end -}} |
123 | | - {{- else -}} |
124 | | - {{- if ge $current_loop_year $contentItemStartYear -}}{{- $countThisItemForThisYearLoop = true -}}{{- end -}} |
125 | | - {{- end -}} |
126 | | - {{- else -}} |
127 | | - {{- if eq $current_loop_year $contentItemStartYear -}}{{- $countThisItemForThisYearLoop = true -}}{{- end -}} |
128 | | - {{- end -}} |
129 | | - {{- if $countThisItemForThisYearLoop -}} |
130 | | - {{- if $isActualInitiativePage -}} |
131 | | - {{- $initiativesLedThisYear = $initiativesLedThisYear | append $contentPage -}} |
132 | | - {{- else -}} |
133 | | - {{- range $def := $contributionSectionDefs -}} |
134 | | - {{- $matchValue := cond (eq $def.matchField "Section") $contentPage.Section $contentPage.Type -}} |
135 | | - {{- if eq (lower $matchValue) (lower $def.id) -}} |
136 | | - {{- $currentCount := index $contributionsThisYearBadges $def.plural | default 0 -}} |
137 | | - {{- $contributionsThisYearBadges = merge $contributionsThisYearBadges (dict $def.plural (add $currentCount 1)) -}} |
138 | | - {{- end -}} |
139 | | - {{- end -}} |
140 | | - {{- end -}} |
141 | | - {{- end -}} |
142 | | - {{- end -}} |
143 | | - |
144 | | - {{- $badgeCount := 0 -}} |
145 | | - {{- range $key, $value := $contributionsThisYearBadges -}} |
146 | | - {{- $badgeCount = add $badgeCount $value -}} |
147 | | - {{- end -}} |
148 | | - {{- $totalContributionsThisYear := add (len $initiativesLedThisYear) $badgeCount -}} |
149 | | - |
150 | | - {{- if gt $totalContributionsThisYear 0 -}} |
151 | | - {{- $contributorsInThisYear = $contributorsInThisYear | append (dict |
152 | | - "profile" $contributorProfilePage |
153 | | - "badges" $contributionsThisYearBadges |
154 | | - "initiatives_led" $initiativesLedThisYear |
155 | | - "has_initiatives_this_year" (gt (len $initiativesLedThisYear) 0) |
156 | | - "total" $totalContributionsThisYear |
157 | | - ) |
158 | | - -}} |
159 | | - {{- end -}} |
160 | | - {{- end -}} |
161 | | - {{- end -}} |
| 123 | + <div class="year-section mb-6"> |
| 124 | + <h2 class="text-3xl text-center font-bold mb-10 pb-2">{{ $year_str }} Contributors</h2> |
| 125 | + |
| 126 | + {{- $contributorsInThisYear := slice -}} |
| 127 | + {{- $allContributorProfiles := where site.RegularPages "Section" "contributors" -}} |
| 128 | + |
| 129 | + {{- range $profile := $allContributorProfiles -}} |
| 130 | + {{- $nameForProcessing := $profile.Title | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" -}} |
| 131 | + {{- $slug := $nameForProcessing | anchorize -}} |
| 132 | + |
| 133 | + {{- $allContributions := index $contributorMap $slug -}} |
| 134 | + {{- if $allContributions -}} |
| 135 | + |
| 136 | + {{/* Filter contributions for THIS year */}} |
| 137 | + {{- $myContributionsThisYear := slice -}} |
| 138 | + {{- range $c := $allContributions -}} |
| 139 | + {{- if eq $c.Year $year_str -}} |
| 140 | + {{- $myContributionsThisYear = $myContributionsThisYear | append $c -}} |
| 141 | + {{- end -}} |
| 142 | + {{- end -}} |
| 143 | + |
| 144 | + {{- if gt (len $myContributionsThisYear) 0 -}} |
| 145 | + {{- $badges := dict -}} |
| 146 | + {{- $initiativesLed := slice -}} |
| 147 | + |
| 148 | + {{- range $c := $myContributionsThisYear -}} |
| 149 | + {{- $page := $c.Page -}} |
| 150 | + {{- if eq (lower $page.Type) "initiatives" -}} |
| 151 | + {{/* Dedup initiatives */}} |
| 152 | + {{- if not (in $initiativesLed $page) -}} |
| 153 | + {{- $initiativesLed = $initiativesLed | append $page -}} |
| 154 | + {{- end -}} |
| 155 | + {{- else -}} |
| 156 | + {{- range $def := $contributionSectionDefs -}} |
| 157 | + {{- $matchValue := cond (eq $def.matchField "Section") $page.Section $page.Type -}} |
| 158 | + {{- if eq (lower $matchValue) (lower $def.id) -}} |
| 159 | + {{- $currentCount := index $badges $def.plural | default 0 -}} |
| 160 | + {{- $badges = merge $badges (dict $def.plural (add $currentCount 1)) -}} |
| 161 | + {{- end -}} |
| 162 | + {{- end -}} |
| 163 | + {{- end -}} |
| 164 | + {{- end -}} |
| 165 | + |
| 166 | + {{- $badgeCount := 0 -}} |
| 167 | + {{- range $k, $v := $badges -}}{{ $badgeCount = add $badgeCount $v }}{{- end -}} |
| 168 | + {{- $total := add (len $initiativesLed) $badgeCount -}} |
| 169 | + |
| 170 | + {{- $contributorsInThisYear = $contributorsInThisYear | append (dict |
| 171 | + "profile" $profile |
| 172 | + "badges" $badges |
| 173 | + "initiatives_led" $initiativesLed |
| 174 | + "has_initiatives" (gt (len $initiativesLed) 0) |
| 175 | + "total" $total |
| 176 | + ) |
| 177 | + -}} |
| 178 | + {{- end -}} |
| 179 | + {{- end -}} |
| 180 | + {{- end -}} |
162 | 181 |
|
163 | | - {{- $sortedContributorsInThisYear := sort $contributorsInThisYear "has_initiatives_this_year" "desc" "total" "desc" -}} |
164 | | - {{- if $sortedContributorsInThisYear -}} |
165 | | - <div class="row"> |
166 | | - {{- range $contribData := $sortedContributorsInThisYear -}} |
167 | | - <div class="md:col-6 lg:col-4 mb-8 flex flex-col"> |
168 | | - {{- partial "components/author-card.html" (dict |
169 | | - "context" $contribData.profile |
170 | | - "variant" "compact" |
171 | | - "contribution_badges" $contribData.badges |
172 | | - "initiatives_led" $contribData.initiatives_led |
173 | | - "total_contributions" $contribData.total |
174 | | - ) |
175 | | - -}} |
| 182 | + {{- $sortedContributors := sort $contributorsInThisYear "has_initiatives" "desc" "total" "desc" -}} |
| 183 | + |
| 184 | + {{- if $sortedContributors -}} |
| 185 | + <div class="row"> |
| 186 | + {{- range $data := $sortedContributors -}} |
| 187 | + <div class="md:col-6 lg:col-4 mb-8 flex flex-col"> |
| 188 | + {{- partial "components/author-card.html" (dict |
| 189 | + "context" $data.profile |
| 190 | + "variant" "compact" |
| 191 | + "contribution_badges" $data.badges |
| 192 | + "initiatives_led" $data.initiatives_led |
| 193 | + "total_contributions" $data.total |
| 194 | + ) |
| 195 | + -}} |
| 196 | + </div> |
| 197 | + {{- end -}} |
176 | 198 | </div> |
| 199 | + {{- else -}} |
| 200 | + <p class="italic text-gray-600 dark:text-darkmode-light/80 text-center">No contributors found for {{ $year_str }}.</p> |
177 | 201 | {{- end -}} |
178 | 202 | </div> |
179 | | - {{- else -}} |
180 | | - <p class="italic text-gray-600 dark:text-darkmode-light/80">No contributors with categorized content found for {{ $year_str }}.</p> |
181 | | - {{- end -}} |
182 | | - </div> |
183 | 203 | {{- end -}} |
184 | 204 | </div> |
185 | 205 | </section> |
|
0 commit comments