{{- /* social.html (shortcode): Renders a social network list with icons or text. Target: Global Example: {{< social LIMIT="" >}} Params: - LIMIT (integral, optional): Number of menu item to show Error handler: - warnf - OCD Docs: https://alpha.oxypteros.com/shortcodes/social Repo: https://github.com/oxypteros/alpha */ -}} {{- /* Case-insensitive parameter retrieval (default chaining) */}} {{- $limit := .Get "LIMIT" | default (.Get "Limit") | default (.Get "limit") }} {{- /* Parameter and menu initial validation */}} {{- $isNumber := (printf "%v" $limit | findRE "^[1-9][0-9]*$") }} {{- $menu := .Site.Menus.sc_social }} {{- $firstN := $menu }} {{- $intNumber := 0 }} {{- $warnNumber := false }} {{- if $isNumber }} {{- $intNumber = (index $isNumber 0 | int) }} {{- $firstN = first $intNumber $menu }} {{- else if $limit }} {{- $warnNumber = true }} {{- end }} {{- /* Context for error reporting (warnf, OCD) */}} {{ $page := .Page.RelPermalink }} {{- /* warnf, OCD: Validate params manually against an allowlist. */}} {{- $allowedKeys := slice "limit" }} {{- $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-171 */}} {{- $errorCode := "ocd-sc-171" }} {{- $invalidKeysString := delimit $invalidKeys ", " }} {{- $errorMessage := printf "Invalid parameter: %s" $invalidKeysString }} {{- $logMessage := printf "OcdError [%s] Page: %s | %s" $errorCode $page $errorMessage }} {{- warnf "%s" $logMessage }} {{- /* OCD error card for: odc-sc-171 */}} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{- i18n "OcdScParamError" . | default "Shortcode Parameter Error" }}

{{- $count := len $invalidKeys }} {{- i18n "OcdScSocial171" $count | default "Invalid parameter in the social shortcode on:" }} {{ .Page.Title }}

{{- i18n "OcdScParameter" $count | default "The parameters," }}  {{ $invalidKeysString }}  {{ i18n "OcdScNotRecognized" $count | default "are not recognized." }}


{{ i18n "OcdScAcceptedParameters" . | default "Accepted parameters:" }} LIMIT

{{- end }} {{- end }} {{- /* Missing Menu Error Handling (warnf, OCD) */}} {{- if and hugo.IsServer (eq $menu nil) }} {{- /* Warnf for error: ocd-sc-172 */}} {{- $errorCode := "ocd-sc-172" }} {{- $errorMessage := printf "Menu sc_social is not set." }} {{- $logMessage := printf "OcdError [%s] - Page: %s | %s" $errorCode $page $errorMessage }} {{- warnf "%s" $logMessage }} {{- /* OCD error card for: odc-sc-172 */}} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{- i18n "OcdScContentError" . | default "Shortcode Content Error" }}

{{- i18n "OcdScSocial172" . | default "Missing menu for the social shortcode on page:" }} {{ .Page.Title }}

{{- i18n "OcdScTheMenu" . | default "The menu " }}  sc_social  {{ i18n "OcdScIsNotSet" . | default "is not set." }}


{{- i18n "OcdScCreatePopulate" . | default "Create or populate a" }} [[sc_social]] {{ i18n "OcdScMenuOn" . | default "menu on " }} /config/_defaults/menus.toml

{{- end }} {{- end }} {{- /* Wrong Number Value Error Handling (warnf, OCD) */}} {{- if and hugo.IsServer $warnNumber }} {{- /* Warnf for error: ocd-sc-173 */}} {{- $errorCode := "ocd-sc-173" }} {{- $errorMessage := printf "The value of the LIMIT parameter is not an integer: %s." $limit }} {{- $logMessage := printf "OcdError [%s] - Page: %s | %s" $errorCode $page $errorMessage }} {{- warnf "%s" $logMessage }} {{- /* OCD error card for: odc-sc-173 */}} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{- i18n "OcdScContentError" . | default "Shortcode Content Error" }}

{{- i18n "OcdScSocial173" . | default "Invalid parameter value for the social shortcode on:" }} {{ .Page.Title }}

{{- i18n "OcdScThe" . | default "The" }}  LIMIT  {{- i18n "OcdScParameterValue" . | default "parameter value" }}  {{ $limit }}  {{ i18n "OcdScIsInvalid" . | default "is invalid." }}


{{- i18n "OcdSc" . | default "" }} LIMIT {{ i18n "OcdSc" . | default "must be an integer." }}

{{- end }} {{- end }} {{- if $menu }}
{{- range $firstN }} {{ with .Pre }} {{- else }} {{ .Name }} {{- end }} {{- end }}
{{- end }}