|
| 1 | +{{/* Display author list with truncation: show first 5 + owner (Aneesh C Subramanian). */}} |
| 2 | + |
| 3 | +{{- $authors := .Params.authors -}} |
| 4 | + |
| 5 | +{{ if $authors }} |
| 6 | + {{- if not (reflect.IsSlice $authors) -}} |
| 7 | + {{- $authors = slice $authors -}} |
| 8 | + {{- end -}} |
| 9 | + |
| 10 | + {{- $maxShow := 5 -}} |
| 11 | + {{- $totalAuthors := len $authors -}} |
| 12 | + |
| 13 | + {{/* Build list of authors to display */}} |
| 14 | + {{- $displayAuthors := slice -}} |
| 15 | + {{- $ownerIndex := -1 -}} |
| 16 | + {{- $ownerName := "" -}} |
| 17 | + |
| 18 | + {{/* Find the owner (Aneesh) in the author list */}} |
| 19 | + {{- range $index, $raw := $authors -}} |
| 20 | + {{- $lower := $raw | lower -}} |
| 21 | + {{- if or (in $lower "aneesh") (in $lower "subramanian") -}} |
| 22 | + {{- $ownerIndex = $index -}} |
| 23 | + {{- $ownerName = $raw -}} |
| 24 | + {{- end -}} |
| 25 | + {{- end -}} |
| 26 | + |
| 27 | + {{- if le $totalAuthors $maxShow -}} |
| 28 | + {{/* Show all authors if 5 or fewer */}} |
| 29 | + {{- $displayAuthors = $authors -}} |
| 30 | + {{- else -}} |
| 31 | + {{/* Take first 5 authors */}} |
| 32 | + {{- $first5 := first $maxShow $authors -}} |
| 33 | + {{- $ownerInFirst5 := false -}} |
| 34 | + {{- range $index, $raw := $first5 -}} |
| 35 | + {{- $lower := $raw | lower -}} |
| 36 | + {{- if or (in $lower "aneesh") (in $lower "subramanian") -}} |
| 37 | + {{- $ownerInFirst5 = true -}} |
| 38 | + {{- end -}} |
| 39 | + {{- end -}} |
| 40 | + |
| 41 | + {{- if $ownerInFirst5 -}} |
| 42 | + {{/* Owner is already in first 5, just use first 5 */}} |
| 43 | + {{- $displayAuthors = $first5 -}} |
| 44 | + {{- else if ne $ownerIndex -1 -}} |
| 45 | + {{/* Owner exists but not in first 5 — show first 5 + owner */}} |
| 46 | + {{- $displayAuthors = $first5 | append $ownerName -}} |
| 47 | + {{- else -}} |
| 48 | + {{/* Owner not found at all — just show first 5 */}} |
| 49 | + {{- $displayAuthors = $first5 -}} |
| 50 | + {{- end -}} |
| 51 | + {{- end -}} |
| 52 | + |
| 53 | + {{- $truncated := gt $totalAuthors $maxShow -}} |
| 54 | + {{- $displayCount := len $displayAuthors -}} |
| 55 | + |
| 56 | + {{ range $index, $raw := $displayAuthors }} |
| 57 | + {{- $slug := $raw | urlize -}} |
| 58 | + {{- $profile := partial "functions/get_author_profile" (dict "slug" $slug "title" $raw) -}} |
| 59 | + {{- $termPage := site.GetPage (printf "/authors/%s" $slug) -}} |
| 60 | + {{- $display := $profile.title | default $raw -}} |
| 61 | + {{- $highlight_name := false -}} |
| 62 | + |
| 63 | + {{- if gt $index 0 }}, {{ end -}} |
| 64 | + |
| 65 | + {{/* If truncated and this is the last display author and owner was appended, insert "..." before */}} |
| 66 | + {{- if and $truncated (eq $index (sub $displayCount 1)) (gt $index (sub $maxShow 1)) -}} |
| 67 | + ..., |
| 68 | + {{- end -}} |
| 69 | + |
| 70 | + <span {{ if $highlight_name }}class="font-bold"{{end}}> |
| 71 | + {{- if $termPage -}} |
| 72 | + <a href="{{ $termPage.RelPermalink }}">{{ $display }}</a> |
| 73 | + {{- else -}} |
| 74 | + {{ $display }} |
| 75 | + {{- end -}} |
| 76 | + </span> |
| 77 | + {{- if isset $.Params "author_notes" -}} |
| 78 | + {{- $origIndex := $index -}} |
| 79 | + {{/* Map display index back to original index for author_notes */}} |
| 80 | + {{- if and $truncated (gt $index (sub $maxShow 1)) (ne $ownerIndex -1) -}} |
| 81 | + {{- $origIndex = $ownerIndex -}} |
| 82 | + {{- end -}} |
| 83 | + {{- with (index $.Params.author_notes $origIndex) -}} |
| 84 | + <span class="relative inline-block ml-1" x-data="{ tooltip: false }"> |
| 85 | + <button |
| 86 | + @mouseenter="tooltip = true" |
| 87 | + @mouseleave="tooltip = false" |
| 88 | + @click="tooltip = !tooltip" |
| 89 | + class="author-notes text-primary-600 dark:text-primary-400 hover:text-primary-800 dark:hover:text-primary-200 transition-colors cursor-help" |
| 90 | + data-tooltip="{{.}}" |
| 91 | + aria-label="{{.}}" |
| 92 | + type="button" |
| 93 | + > |
| 94 | + <svg class="inline-block w-4 h-4" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> |
| 95 | + <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path> |
| 96 | + </svg> |
| 97 | + </button> |
| 98 | + <div |
| 99 | + x-show="tooltip" |
| 100 | + x-transition:enter="transition ease-out duration-200" |
| 101 | + x-transition:enter-start="opacity-0 transform scale-95" |
| 102 | + x-transition:enter-end="opacity-100 transform scale-100" |
| 103 | + x-transition:leave="transition ease-in duration-150" |
| 104 | + x-transition:leave-start="opacity-100 transform scale-100" |
| 105 | + x-transition:leave-end="opacity-0 transform scale-95" |
| 106 | + @click.away="tooltip = false" |
| 107 | + class="absolute z-50 bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 text-sm text-white bg-gray-900 dark:bg-gray-700 rounded-lg shadow-lg whitespace-nowrap" |
| 108 | + x-cloak |
| 109 | + > |
| 110 | + {{.}} |
| 111 | + <div class="absolute top-full left-1/2 transform -translate-x-1/2 -mt-1 w-0 h-0 border-l-4 border-r-4 border-t-4 border-transparent border-t-gray-900 dark:border-t-gray-700"></div> |
| 112 | + </div> |
| 113 | + </span> |
| 114 | + {{- end -}} |
| 115 | + {{- end -}} |
| 116 | + {{- end -}} |
| 117 | + |
| 118 | + {{/* Add "et al." if truncated and owner was in first 5 (no appended owner) */}} |
| 119 | + {{- if and $truncated (le $displayCount $maxShow) -}} |
| 120 | + , et al. |
| 121 | + {{- end -}} |
| 122 | + {{/* Add "et al." if truncated and owner was appended (already has "...") */}} |
| 123 | + {{- if and $truncated (gt $displayCount $maxShow) -}} |
| 124 | + , et al. |
| 125 | + {{- end -}} |
| 126 | +{{- end -}} |
0 commit comments