{{- $wcPage := .wcPage -}} {{- $wcBlock := .wcBlock -}} {{- $wcIdentifier := .wcIdentifier -}} {{ $content := $wcBlock.content }} {{ if not (reflect.IsMap $content) }}{{ $content = dict }}{{ end }} {{ $design := $wcBlock.design }} {{ if not (reflect.IsMap $design) }}{{ $design = dict }}{{ end }} {{ $spacing := index $design "spacing" }} {{ if not (reflect.IsMap $spacing) }}{{ $spacing = dict }}{{ end }} {{ $pad_raw := index $spacing "padding" }} {{ $pad := slice "4rem" "0" "4rem" "0" }} {{ if reflect.IsSlice $pad_raw }} {{ $pad_values := slice }} {{ range $pad_raw }} {{ $val := strings.TrimSpace (printf "%v" .) }} {{ if $val }}{{ $pad_values = $pad_values | append $val }}{{ end }} {{ end }} {{ if eq (len $pad_values) 4 }}{{ $pad = $pad_values }}{{ end }} {{ end }} {{ $background := index $design "background" }} {{ if not (reflect.IsMap $background) }}{{ $background = dict }}{{ end }} {{ $bg_color := "" }} {{ with index $background "color" }}{{ $bg_color = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ $title := "" }} {{ $title_raw := index $content "title" }} {{ if $title_raw }}{{ $title = strings.TrimSpace (printf "%v" $title_raw) }}{{ end }} {{ $subtitle := "" }} {{ $subtitle_raw := index $content "subtitle" }} {{ if $subtitle_raw }}{{ $subtitle = strings.TrimSpace (printf "%v" $subtitle_raw) }}{{ end }} {{ $view_all := index $content "view_all" }} {{ if not (reflect.IsMap $view_all) }}{{ $view_all = dict }}{{ end }} {{ $view_all_text := "" }} {{ $view_all_link := "" }} {{ with index $view_all "text" }}{{ $view_all_text = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index $view_all "link" }}{{ $view_all_link = strings.TrimSpace (printf "%v" .) }}{{ end }}
{{ with $title }}

{{ . | markdownify }}

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

{{ . | markdownify }}

{{ end }}
{{ if and $view_all_text $view_all_link }} {{ $view_link := $view_all_link }} {{ $view_target := "" }} {{ $view_scheme := (urls.Parse $view_link).Scheme }} {{ if not $view_scheme }} {{ if not (hasPrefix $view_link "#") }} {{ $view_link = $view_link | relLangURL }} {{ end }} {{ else if in (slice "http" "https") $view_scheme }} {{ $view_target = "target=\"_blank\" rel=\"noopener\"" }} {{ end }} {{ end }}
{{/* Get trending questions dynamically or from static config */}} {{ $questions := slice }} {{/* Method 1: Dynamic - Pull from pages with trending: true */}} {{ $count := partial "functions/coerce_int" (dict "value" (index $content "count") "default" 4 "min" 0) }} {{ $trending_pages := where site.RegularPages "Params.trending" true }} {{ $trending_pages = $trending_pages.ByParam "trending_weight" | default ($trending_pages.ByDate.Reverse) }} {{ $trending_pages = first $count $trending_pages }} {{ if $trending_pages }} {{ range $trending_pages }} {{ $question := "" }} {{ $question_raw := .Params.question | default .Title }} {{ if $question_raw }}{{ $question = strings.TrimSpace (printf "%v" $question_raw) }}{{ end }} {{ $link := .RelPermalink }} {{ $answer_preview := "" }} {{ $answer_raw := .Params.answer_preview | default .Params.answer | default .Summary }} {{ if $answer_raw }}{{ $answer_preview = (printf "%v" $answer_raw) | plainify | truncate 150 }}{{ end }} {{ $author := "" }} {{ with .Params.author }}{{ $author = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ $views := "" }} {{ with .Params.views }}{{ $views = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ $upvotes := "" }} {{ with .Params.upvote_count }}{{ $upvotes = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ $badge := dict }} {{ $badge_raw := .Params.badge }} {{ if reflect.IsMap $badge_raw }} {{ $badge_text := "" }} {{ $badge_color := "" }} {{ with index $badge_raw "text" }}{{ $badge_text = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index $badge_raw "color" }}{{ $badge_color = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ if $badge_text }} {{ $badge = dict "text" $badge_text "color" $badge_color }} {{ end }} {{ else if $badge_raw }} {{ $badge_text := strings.TrimSpace (printf "%v" $badge_raw) }} {{ if $badge_text }} {{ $badge = dict "text" $badge_text "color" "" }} {{ end }} {{ end }} {{ if eq (len $badge) 0 }} {{ $upvote_count := partial "functions/coerce_int" (dict "value" .Params.upvote_count "default" 0 "min" 0) }} {{ $featured := partial "functions/coerce_bool" (dict "value" .Params.featured "default" false) }} {{ if gt $upvote_count 50 }} {{ $badge = dict "text" "🔥 Popular" "color" "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-200" }} {{ else if $featured }} {{ $badge = dict "text" "⭐ Featured" "color" "bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-200" }} {{ else if (time .Date).After (now.AddDate 0 0 -7) }} {{ $badge = dict "text" "✨ New" "color" "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-200" }} {{ else }} {{ $badge = dict "text" "🔥 Trending" "color" "bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200" }} {{ end }} {{ end }} {{ if $question }} {{ $questions = $questions | append (dict "question" $question "link" $link "answer_preview" $answer_preview "author" $author "views" $views "upvotes" $upvotes "badge" $badge) }} {{ end }} {{ end }} {{ end }} {{/* Method 2: Static fallback - Use config if no trending pages found */}} {{ if not $questions }} {{ $questions_raw := index $content "questions" }} {{ $questions_iter := slice }} {{ if reflect.IsSlice $questions_raw }} {{ $questions_iter = $questions_raw }} {{ else if and $questions_raw (reflect.IsMap $questions_raw) }} {{ $questions_iter = slice $questions_raw }} {{ end }} {{ if gt (len $questions_iter) 0 }} {{ range $questions_iter }} {{ if reflect.IsMap . }} {{ $question := "" }} {{ $link := "" }} {{ $answer_preview := "" }} {{ $author := "" }} {{ $views := "" }} {{ $upvotes := "" }} {{ with index . "question" }}{{ $question = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "link" }}{{ $link = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "answer_preview" }}{{ $answer_preview = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "author" }}{{ $author = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "views" }}{{ $views = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "upvotes" }}{{ $upvotes = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ $badge := dict }} {{ $badge_raw := index . "badge" }} {{ if reflect.IsMap $badge_raw }} {{ $badge_text := "" }} {{ $badge_color := "" }} {{ with index $badge_raw "text" }}{{ $badge_text = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index $badge_raw "color" }}{{ $badge_color = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ if $badge_text }} {{ $badge = dict "text" $badge_text "color" $badge_color }} {{ end }} {{ else if $badge_raw }} {{ $badge_text := strings.TrimSpace (printf "%v" $badge_raw) }} {{ if $badge_text }} {{ $badge = dict "text" $badge_text "color" "" }} {{ end }} {{ end }} {{ if $question }} {{ $questions = $questions | append (dict "question" $question "link" $link "answer_preview" $answer_preview "author" $author "views" $views "upvotes" $upvotes "badge" $badge) }} {{ end }} {{ end }} {{ end }} {{ end }} {{ end }} {{/* Questions list or carousel */}}
{{ range $index, $question := $questions }}
{{/* Badge */}} {{ $badge := index $question "badge" }} {{ if reflect.IsMap $badge }} {{ $badge_text := index $badge "text" }} {{ $badge_color := index $badge "color" | default "bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200" }} {{ if $badge_text }}
{{ $badge_text }}
{{ end }} {{ end }} {{/* Question */}}

{{ $question_link := index $question "link" }} {{ $link := $question_link }} {{ if not $link }}{{ $link = "#" }}{{ end }} {{ $link_target := "" }} {{ $scheme := (urls.Parse $link).Scheme }} {{ if not $scheme }} {{ if not (hasPrefix $link "#") }} {{ $link = $link | relLangURL }} {{ end }} {{ else if in (slice "http" "https") $scheme }} {{ $link_target = "target=\"_blank\" rel=\"noopener\"" }} {{ end }} {{ index $question "question" }}

{{/* Answer preview */}} {{ with index $question "answer_preview" }}

{{ . }}

{{ end }} {{/* Meta info */}}
{{ with index $question "author" }} {{ . }} {{ end }} {{ with index $question "views" }} {{ . }} {{ end }} {{ with index $question "upvotes" }} {{ . }} helpful {{ end }}
Read →
{{ end }}
{{/* Mobile view all link */}} {{ if and $view_all_text $view_all_link }} {{ $mobile_link := $view_all_link }} {{ $mobile_target := "" }} {{ $mobile_scheme := (urls.Parse $mobile_link).Scheme }} {{ if not $mobile_scheme }} {{ if not (hasPrefix $mobile_link "#") }} {{ $mobile_link = $mobile_link | relLangURL }} {{ end }} {{ else if in (slice "http" "https") $mobile_scheme }} {{ $mobile_target = "target=\"_blank\" rel=\"noopener\"" }} {{ end }} {{ end }}