{{/* Article Cover Component - Notion-inspired page cover with icon overlay */}} {{/* Requires: page context */}} {{ $cover := partial "functions/get_cover_image.html" . }} {{ if $cover }} {{/* Get cover configuration with defaults */}} {{ $cover_config := .Params.cover | default (dict) }} {{ if not (reflect.IsMap $cover_config) }} {{/* Simple string format: cover: "image.jpg" */}} {{ $cover_config = dict "image" $cover_config }} {{ end }} {{/* Default alt text to page title if not specified */}} {{ $alt_text := $cover_config.alt_text | default (.Title | plainify) }} {{/* Height configuration */}} {{ $height_map := dict "small" "200px" "medium" "320px" "large" "480px" "full" "60vh" }} {{ $height := index $height_map ($cover_config.height | default "medium") | default "320px" }} {{/* Style configuration */}} {{ $style := $cover_config.style | default "gradient" }} {{/* Position configuration */}} {{ $position := $cover_config.position | default (dict) }} {{ $x := $position.x | default 50 }} {{ $y := $position.y | default 50 }} {{/* Overlay configuration */}} {{ $overlay := $cover_config.overlay | default (dict) }} {{ $overlay_enabled := $overlay.enabled | default true }} {{ $overlay_type := $overlay.type | default "gradient" }} {{ $overlay_opacity := $overlay.opacity | default 0.3 }} {{ $overlay_color := $overlay.color | default "#000000" }} {{ $overlay_gradient := $overlay.gradient | default "bottom" }} {{/* Fade configuration */}} {{ $fade := $cover_config.fade | default (dict) }} {{ $fade_enabled := $fade.enabled | default true }} {{ $fade_height := $fade.height | default "60px" }} {{ $fade_blur := $fade.blur | default false }} {{/* Icon configuration */}} {{ $icon_config := $cover_config.icon | default (dict) }} {{ $has_icon := or $icon_config.name $icon_config.emoji }} {{ $icon_position := $icon_config.position | default "overlap" }} {{ $icon_size := $icon_config.size | default "large" }} {{ $icon_style := $icon_config.style | default "glass" }} {{ $icon_border := $icon_config.border | default true }} {{/* Responsive hide on mobile */}} {{ $hide_mobile := false }} {{ if $cover_config.responsive }} {{ $hide_mobile = $cover_config.responsive.hide_on_mobile | default false }} {{ end }} {{/* Process cover image */}} {{ $cover_width := 2560 }} {{ $cover_height := 520 }} {{ if eq ($cover_config.height | default "medium") "small" }} {{ $cover_height = 320 }} {{ else if eq ($cover_config.height | default "medium") "large" }} {{ $cover_height = 768 }} {{ else if eq ($cover_config.height | default "medium") "full" }} {{ $cover_height = 1080 }} {{ end }} {{/* Generate responsive images. - reflect.IsImageResourceProcessable → false for SVG (not processable by Hugo). - GIF: processable by Hugo but we skip to preserve animation frames. */}} {{ $processed_cover := $cover }} {{ $srcset := "" }} {{ $canProcess := and (reflect.IsImageResourceProcessable $cover) (ne $cover.MediaType.SubType "gif") }} {{ if $canProcess }} {{ $fill_spec := printf "%dx%d Center q85 webp" $cover_width $cover_height }} {{ $processed_cover = $cover.Fill $fill_spec }} {{ $variants := slice }} {{ $widths := slice 640 768 1024 1366 1920 2560 }} {{ range $widths }} {{ $w := . }} {{ $h := div (mul $w $cover_height) $cover_width }} {{ $variant_spec := printf "%dx%d Center q85 webp" $w $h }} {{ $variant := $cover.Fill $variant_spec }} {{ $variants = $variants | append (printf "%s %dw" $variant.RelPermalink $w) }} {{ end }} {{ $srcset = delimit $variants ", " }} {{ end }} {{/* Build CSS classes based on style */}} {{ $cover_classes := "article-cover relative w-full" }} {{ if $hide_mobile }} {{ $cover_classes = printf "%s hidden md:block" $cover_classes }} {{ end }} {{/* Container styles */}} {{ $container_style := printf "height: %s;" $height }} {{/* Calculate mask style for fade */}} {{ $mask_style := "" }} {{ if and $fade_enabled (ne $style "minimal") }} {{/* Mask fades from black (visible) to transparent (invisible) at the bottom */}} {{ $mask_style = printf "-webkit-mask-image: linear-gradient(to bottom, black calc(100%% - %s), transparent 100%%); mask-image: linear-gradient(to bottom, black calc(100%% - %s), transparent 100%%);" $fade_height $fade_height }} {{ end }}
{{/* Cover Image */}}
{{ if $canProcess }} {{ $alt_text }} {{ else }} {{ $alt_text }} {{ end }}
{{/* Overlay Effects */}} {{ if and $overlay_enabled (ne $style "minimal") }} {{ if eq $style "gradient" }}
{{ else if eq $style "glass" }}
{{ else if eq $style "blur" }}
{{ else if eq $overlay_type "gradient" }} {{ if eq $overlay_gradient "bottom" }}
{{ else if eq $overlay_gradient "top" }}
{{ else if eq $overlay_gradient "both" }}
{{ else if eq $overlay_gradient "radial" }}
{{ end }} {{ else if eq $overlay_type "solid" }}
{{ end }} {{ end }} {{/* Blur Effect at Bottom (Optional) */}} {{ if and $fade_enabled $fade_blur (ne $style "minimal") }} {{/* Taller blur zone with mask to create smooth blur transition before fade out */}} {{/* Semi-transparent background needed for backdrop-filter to render */}}
{{ end }} {{/* Caption */}} {{ with $cover_config.caption }}
{{ . | markdownify }}
{{ end }}
{{/* Icon Overlay - Only if position is "overlap" - NOW UNCLIPPED */}} {{ if and $has_icon (eq $icon_position "overlap") }} {{ $icon_size_map := dict "small" "w-8 h-8" "medium" "w-12 h-12" "large" "w-16 h-16" }} {{ $icon_size_class := index $icon_size_map $icon_size | default "w-16 h-16" }} {{ $icon_padding := cond (eq $icon_size "small") "p-1.5" (cond (eq $icon_size "medium") "p-2" "p-3") }}
{{ if $icon_config.emoji }} {{ $icon_config.emoji }} {{ else if $icon_config.name }} {{ partial "functions/get_icon.html" (dict "name" $icon_config.name "attributes" (printf "class=\"%s text-gray-700 dark:text-gray-200\"" $icon_size_class)) }} {{ end }}
{{ end }}
{{/* Icon Below Cover - If position is "below" */}} {{ if and $has_icon (eq $icon_position "below") }} {{ $icon_size_map := dict "small" "w-8 h-8" "medium" "w-12 h-12" "large" "w-16 h-16" }} {{ $icon_size_class := index $icon_size_map $icon_size | default "w-16 h-16" }} {{ $icon_padding := cond (eq $icon_size "small") "p-1.5" (cond (eq $icon_size "medium") "p-2" "p-3") }}
{{ if $icon_config.emoji }} {{ $icon_config.emoji }} {{ else if $icon_config.name }} {{ partial "functions/get_icon.html" (dict "name" $icon_config.name "attributes" (printf "class=\"%s text-gray-700 dark:text-gray-200\"" $icon_size_class)) }} {{ end }}
{{ end }} {{ end }}