mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-13 02:14:21 +00:00
Hardened 1st batch of five homepage blocks by normalizing config types, clamping unsafe values, and guarding bad inputs so user‑supplied params fail safe without template errors. Changes coerce_bool.html and coerce_int.html: added shared coercion helpers for consistent, safe defaults across blocks. block.html: sanitized content/design inputs, robust user_groups parsing, safer role/affiliation/interest/link handling, and CTA URL validation. block.html: guarded avatar/banner/name/headings/bio, safe button/link resolution, and resilient parsing for affiliations, education, interests, and social links. block.html: hardened filters (kinds/folders/tags), safer sort/order handling, clamped numeric params, and archive link safety/fallbacks. block.html and block.html: defensive content rendering, clamped overlay opacity, and safe button link handling. schema.json, schema.json, schema.json: added view enum entries, added new_tab, and Biome formatting applied.
27 lines
988 B
HTML
27 lines
988 B
HTML
{{ $value := .value }}
|
|
{{ $result := .default }}
|
|
{{ if ne $value nil }}
|
|
{{ $valueType := printf "%T" $value }}
|
|
{{ if or (eq $valueType "int") (eq $valueType "int8") (eq $valueType "int16") (eq $valueType "int32") (eq $valueType "int64") (eq $valueType "uint") (eq $valueType "uint8") (eq $valueType "uint16") (eq $valueType "uint32") (eq $valueType "uint64") (eq $valueType "float32") (eq $valueType "float64") }}
|
|
{{ $result = int $value }}
|
|
{{ else if eq $valueType "string" }}
|
|
{{ $trimmed := strings.TrimSpace $value }}
|
|
{{ if gt (len (findRE "^-?[0-9]+$" $trimmed)) 0 }}
|
|
{{ $result = int $trimmed }}
|
|
{{ else if gt (len (findRE "^-?[0-9]*\\.[0-9]+$" $trimmed)) 0 }}
|
|
{{ $result = int (float $trimmed) }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ if isset . "min" }}
|
|
{{ if lt $result .min }}
|
|
{{ $result = .min }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ if isset . "max" }}
|
|
{{ if gt $result .max }}
|
|
{{ $result = .max }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ return $result }}
|