{{/* 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 }}