{{- /* faq.html (shortcode): Renders a collapsible Frequently Asked Questions type element. Target: Global Example: {{< faq TITLE="" SUBTITLE="" >}} ## Question Answer {{< /faq >}} Params: - TITLE (string, optional): H2 heading. - SUBTITLE (string, optional): H3 heading. Error handler: - warnf - OCD Docs: https://alpha.oxypteros.com/docs/shortcodes/faq Repo: https://github.com/oxypteros/alpha */ -}} {{- /* Case-insensitive parameter retrieval (default chaining) */}} {{- $title := .Get "TITLE" | default (.Get "Title") | default (.Get "title") }} {{- $subtitle := .Get "SUBTITLE" | default (.Get "Subtitle") | default (.Get "subtitle") }} {{- $content := .Inner | markdownify }} {{- /* `h2` headings (Question) and `p` elements (Answer) detection */}} {{- $headings := findRE "(?s)]*>(.*?)" $content }} {{- $paragraphs := findRE "(?s)

(.*?)

" $content }} {{- /* Context for error reporting (warnf, OCD)*/}} {{ $page := .Page.RelPermalink }} {{- /* warnf, OCD: Validate params manually against an allowlist. */}} {{- $allowedKeys := slice "title" "subtitle" }} {{- $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-151 */}} {{- $errorCode := "ocd-sc-151" }} {{- $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-151 */}} {{- 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 "OcdScFaq151" $count | default "Invalid parameter detected in the faq shortcode, on:" }} {{ .Page.Title }}

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


{{ i18n "OcdScAcceptedParameters" . | default "Accepted parameters:" }} TITLE, SUBTITLE

{{- end }} {{- end }} {{- /* Shortcode Rendering */}}
{{- if or $title $subtitle }}
{{- with $title }}

{{ . | safeHTML | markdownify }}

{{- end }} {{- with $subtitle }}

{{ . | safeHTML | markdownify }}

{{- end }} {{- end }}
{{- range $index, $heading := $headings }}
{{ $heading | safeHTML }} {{- if index $paragraphs $index }}
{{ index $paragraphs $index | safeHTML }}
{{- end }}
{{- end }}