{{- /* num-list.html (shortcode): Renders a numbered list of weighted child pages Target: Section _index.md files. Example: {{< num-list STYLE="" TITLE="" LIMIT="" >}} Params: - TITLE (string, optional): `h2` heading. - STYLE (string, optional): Rendering style ('card'|'pill'|'list'|'card-list'). Default: 'card'. - LIMIT (int, optional): Maximum number of items. Error handler: - warnf - OCD To-do: Hugo build error negative or non-numeric values - Add `$limit` checks and pass errors to OCD. (low priority) Docs: https://alpha.oxypteros.com/shortcodes/num-list Repo: https://github.com/oxypteros/alpha */ -}} {{- /* Case-insensitive parameter retrieval (default chaining) */}} {{- $style := .Get "STYLE" | default (.Get "Style") | default (.Get "style") | default "card" }} {{- $title := .Get "TITLE" | default (.Get "Title") | default (.Get "title") }} {{- $limit := .Get "LIMIT" | default (.Get "Limit") | default (.Get "limit") }} {{- /* Context for error reporting (warnf, OCD)*/}} {{ $page := .Page.RelPermalink }} {{- /* OCD: Validate params manually against an allowlist. */}} {{- $allowedKeys := slice "style" "title" "limit" }} {{- $invalidKeys := slice }} {{- /* Invalid Parameter Error Handling (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-101 */}} {{- $errorCode := "ocd-sc-101" }} {{- $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-101 */}} {{- 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 "OcdScNumList101" $count | default "Invalid parameter in the numbered list 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:" }} STYLE, TITLE, LIMIT

{{- end }} {{- end }} {{- /* Shortcode Rendering */}} {{- $pages := .Page.Pages.ByWeight }} {{- /* Apply limit if specified (integer conversion)*/}} {{- if $limit }} {{- $pages = first (int $limit) $pages }} {{- end }}
{{- /* Optional title rendering. */}} {{- with $title }}

{{- $title }}

{{- end }} {{- /* Style-based rendering. */}} {{- if eq $style "card" }} {{- else if eq $style "pill" }} {{- else if eq $style "list" }} {{- else if eq $style "card-list" }} {{- else }} {{- /* Warnf for error: ocd-sc-100 */}} {{- $errorCode := "ocd-sc-100" }} {{- $errorMessage := printf "Wrong STYLE input - %s" $style }} {{- $logMessage := printf "OcdError [%s] Page: %s | %s)" $errorCode $page $errorMessage }} {{- warnf "%s" $logMessage }} {{- /* OCD error card for: odc-sc-101 */}} {{- if and (eq hugo.Environment "development") (hugo.IsServer) (eq .Page.Site.Params.ocd_enabled true) }}
{{- i18n "OcdScInputError" . |default "Shortcode Input Error" }}

{{- i18n "OcdScNumList100" . | default "Invalid style value in the numbered list shortcode, on:" }} {{ .Page.Title }}

{{- i18n "OcdScSpecifiedStyle" . | default "The specified style," }} STYLE="{{ $style }}" {{ i18n "OcdScNotRecognized" . | default "is not recognized" }}


{{ i18n "OcdScAvailableStyles" . | default "Available Styles:" }} card, pill, list, card-list

{{- end }} {{- end }}