{{/* Hugo Blox: Biography */}} {{/* Documentation: https://hugoblox.com/blocks/ */}} {{/* License: https://github.com/HugoBlox/kit/blob/main/LICENSE.md */}} {{/* Initialise */}} {{ $page := .wcPage }} {{ $block := .wcBlock }} {{ $content := $block.content }} {{ if not (reflect.IsMap $content) }}{{ $content = dict }}{{ end }} {{ $design := $block.design }} {{ if not (reflect.IsMap $design) }}{{ $design = dict }}{{ end }} {{ $username := "me" }} {{ $username_raw := index $content "username" }} {{ if eq (printf "%T" $username_raw) "string" }} {{ $username = strings.TrimSpace $username_raw }} {{ end }} {{ $profile := partial "functions/get_author_profile" $username }} {{ $avatar := $profile.avatar }} {{/* Avatar customization parameters */}} {{ $avatar_size := "medium" }} {{ $avatar_shape := "circle" }} {{ $avatar_design := index $design "avatar" }} {{ if reflect.IsMap $avatar_design }} {{ $size_raw := index $avatar_design "size" }} {{ if eq (printf "%T" $size_raw) "string" }} {{ $size_candidate := lower (strings.TrimSpace $size_raw) }} {{ if in (slice "small" "medium" "large" "xl" "xxl") $size_candidate }} {{ $avatar_size = $size_candidate }} {{ end }} {{ end }} {{ $shape_raw := index $avatar_design "shape" }} {{ if eq (printf "%T" $shape_raw) "string" }} {{ $shape_candidate := lower (strings.TrimSpace $shape_raw) }} {{ if in (slice "circle" "square" "rounded") $shape_candidate }} {{ $avatar_shape = $shape_candidate }} {{ end }} {{ end }} {{ end }} {{/* Size mappings optimized for 2025 standards: display_size -> [display_px, generation_px] */}} {{ $size_map := dict "small" (slice "150" "300") "medium" (slice "200" "400") "large" (slice "320" "640") "xl" (slice "400" "800") "xxl" (slice "500" "1000") }} {{ $size_config := index $size_map $avatar_size | default (index $size_map "medium") }} {{ $display_size := index $size_config 0 }} {{ $generation_size := index $size_config 1 }} {{/* Shape class mappings */}} {{ $shape_classes := dict "circle" "rounded-full" "square" "rounded-none" "rounded" "rounded-lg" }} {{ $shape_class := index $shape_classes $avatar_shape | default "rounded-full" }} {{ $img := "" }} {{ $banner := index $design "banner" }} {{ $banner_filename := "" }} {{ if reflect.IsMap $banner }} {{ with index $banner "filename" }}{{ $banner_filename = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ end }} {{ if $banner_filename }} {{/* Resolve image from page bundle, site assets, remote, or static URLs */}} {{ $image_resource := false }} {{ $image_url := "" }} {{ if $banner_filename }} {{ $image_path := strings.TrimSpace (printf "%v" $banner_filename) }} {{ $is_remote := or (strings.HasPrefix $image_path "http://") (strings.HasPrefix $image_path "https://") }} {{ if $is_remote }} {{ $remote := try (resources.GetRemote $image_path) }} {{ if and $remote (not $remote.Err) }} {{ $image_resource = $remote.Value }} {{ else }} {{/* If remote fetch fails, fall back to the original URL */}} {{ $image_url = $image_path }} {{ end }} {{ else }} {{/* Normalize common prefixes and dot paths */}} {{ $image_path = strings.TrimPrefix "/" $image_path }} {{ $image_path = strings.TrimPrefix "./" $image_path }} {{ $image_path = strings.TrimPrefix "assets/" $image_path }} {{ $image_path = strings.TrimPrefix "media/" $image_path }} {{ $normalized := path.Clean $image_path }} {{ if and $normalized (ne $normalized ".") }} {{/* Prefer page bundle image resources */}} {{ with $page }} {{ $image_resource = (.Resources.ByType "image").GetMatch $normalized }} {{ end }} {{ if not $image_resource }} {{/* Look in global assets/media - use resources.Get for exact path matching */}} {{ $image_resource = resources.Get (path.Join "media" $normalized) }} {{ end }} {{ if not $image_resource }} {{/* Static fallback (serves original size) */}} {{ $image_url = printf "/media/%s" $normalized }} {{ end }} {{ end }} {{ end }} {{ end }} {{ $img = $image_resource }} {{ if $img }} {{/* reflect.IsImageResourceProcessable → false for SVG; GIF skipped to preserve animation */}} {{ $canProcess := and (reflect.IsImageResourceProcessable $img) (ne $img.MediaType.SubType "gif") }} {{ if $canProcess }} {{ $responsive := partial "functions/process_responsive_image.html" (dict "image" $img "mode" "fill" "aspect_ratio" "16:9" "sizes" (slice 768 1024 1366 1920 2560) ) }}