{{- /* hero.html (shortcode): Renders a hero element with 2 links Target: _index.md Example: {{< hero TITLE="" SUBTITLE="" BTN-TEXT="" BTN-LINK="" BTN-LABEL="" LINK-TEXT="" LINK="" LINK-LABEL="" >}} Params: - TITLE (string, optional): `h2` heading. Falls back to `.Page.Title` - SUBTITLE (string, optional): `h3` heading - BTN-TEXT (string, optional): link text for link 1 (button styled) - BTN-LINK (string, optional): `href` attribute for link 1 - BTN-LABEL (string, optional): `aria-label` attribute for link 1 - LINK-TEXT (string, optional): link text for link 2 - LINK (string, optional): `href` attribute for link 2 - LINK-LABEL (string, optional): `aria-label` attribute for link 2 Error handler: - warnf - OCD Docs: https://alpha.oxypteros.com/docs/shortcodes/hero Repo: https://github.com/oxypteros/alpha */}} {{- /* Case-insensitive parameter retrieval (default chaining) */}} {{- $fullTitle := .Get "TITLE" | default (.Get "Title") | default (.Get "title") | default .Page.Title }} {{- $fullSubtitle := .Get "SUBTITLE" | default (.Get "Subtitle") | default (.Get "subtitle") }} {{- $btnLink := .Get "BTN-LINK" | default (.Get "Btn-Link") | default (.Get "btn-link") }} {{- $btnTxt := .Get "BTN-TEXT" | default (.Get "Btn-Text") | default (.Get "btn-text")}} {{- $btnAria := .Get "BTN-LABEL" | default (.Get "Btn-Label") | default (.Get "btn-label") }} {{- $link := .Get "LINK" | default (.Get "Link") | default (.Get "link") }} {{- $linkTxt := .Get "LINK-TEXT" | default (.Get "Link-Text") | default (.Get "link-text") }} {{- $linkAria := .Get "LINK-LABEL" | default (.Get "Link-Label") | default (.Get "link-label") }} {{- /* Extract the main text and trailing punctuation for styling */ -}} {{- $title := substr $fullTitle 0 -1 }} {{- $titlePunctuation := substr $fullTitle -1 1 }} {{- $subtitle := substr $fullSubtitle 0 -1 }} {{- $subtitlePunctuation := substr $fullSubtitle -1 1 }} {{- /* Responsive title font size based on string length */ -}} {{- $titleLen := len $fullTitle }} {{- $titleFontSize := cond (ge $titleLen 30) "lg:text-7xl" "lg:text-8xl" }} {{- /* Context for error reporting (warnf, OCD)*/}} {{ $page := .Page.RelPermalink }} {{- /* warnf, OCD: Validate params manually against an allowlist. */}} {{- $allowedKeys := slice "title" "subtitle" "btn-link" "btn-text" "btn-label" "link" "link-text" "link-label" }} {{- $invalidKeys := slice }} {{- /* Invalid Parameter Error Handling (warnf, OCD) */}} {{- range $key, $value := .Params }} {{- if not (in $allowedKeys (lower $key)) }} {{- $invalidKeys = $invalidKeys | append $key }} {{- end }} {{- end }} {{- if gt (len $invalidKeys) 0 }} {{- /* Warnf for error: ocd-sc-121 */}} {{- $errorCode := "ocd-sc-121" }} {{- $invalidKeysString := delimit $invalidKeys ", " }} {{- $errorMessage := printf "Invalid parameters: %s" $invalidKeysString }} {{- $logMessage := printf "OcdError [%s] Page: %s | %s" $errorCode $page $errorMessage }} {{- warnf "%s" $logMessage }} {{- /* OCD error card for: odc-sc-121 */}} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{- $count := len $invalidKeys }} {{- i18n "OcdScNumList121" $count | default "Invalid parameter in the hero shortcode on this page:" }} {{ .Page.Title }}
{{- i18n "OcdScParameter" $count | default "The parameters," }} {{ $invalidKeysString }} {{ i18n "OcdScNotRecognized" $count | default "are not recognized." }}
{{ i18n "OcdScAcceptedParameters" . | default "Accepted parameters:" }} TITLE, SUBTITLE, BTN-TEXT, BTN-LINK, BTN-LABEL, LINK-TEXT, LINK, LINK-LABEL
{{- i18n "OcdScHero122-3" . | default "Missing link text in the hero shortcode on page:" }} {{ .Page.Title }}
{{- i18n "OcdScTheParameter" . | default "The parameter" }} BTN-TEXT {{ i18n "OcdScLinkNotRendered" . | default "is missing, so the link will not be rendered." }}
{{- i18n "OcdScFillParameter" . | default "Provide a value for the parameter" }} BTN-TEXT="Your Button Text" {{ i18n "OcdScOrDeleteParameter" . | default "or delete the" }} BTN-LINK="{{ $btnLink }}"
{{- i18n "OcdScHero122-3" . | default "Missing link text in the hero shortcode on page:" }} {{ .Page.Title }}
{{- i18n "OcdScTheParameter" . | default "The parameter" }} LINK-TEXT {{ i18n "OcdScLinkNotRendered" . | default "is missing, so the link will not be rendered." }}
{{- i18n "OcdScFillParameter" . | default "Provide a value for the parameter" }} LINK-TEXT="Your link text" {{ i18n "OcdScOrDeleteParameter" . | default "or remove" }} LINK="{{ $link }}"