Files
Aki ArigaandClaude Opus 4.6 611be3562f feat: use get_featured_image partial consistently for og:image and JSON-LD (#3311)
site_head.html, jsonld/article.html, jsonld/qapage.html, and
jsonld/event.html hardcode `(.Resources.ByType "image").GetMatch
"*featured*"` to find featured images. This ignores custom filenames
set via `.Params.image.filename` in front matter, causing og:image
and JSON-LD image to fall back to the site icon.

Replace the hardcoded pattern with the `get_featured_image` partial
(already used by jsonld/webpage.html), which properly searches for:
1. Files matching `*featured*` in the page directory
2. Custom filename from `.Params.image.filename` in the page directory
3. Custom filename in `assets/media/` directory

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 20:29:18 +01:00

89 lines
3.0 KiB
HTML

{{- $page := .page }}
{{ $summary := .summary }}
{{ $featured_image := partial "functions/get_featured_image" $page }}
{{/* Get author and publisher info */}}
{{ $author := partial "functions/get_author_name" $page }}
{{ $branding := partialCached "functions/get_branding" $page "branding" }}
{{ $publisher := $branding.organization }}
{{/* Extract question - prioritize explicit param, fallback to title */}}
{{ $question := $page.Params.question | default $page.Title }}
{{/* Extract answer - prioritize explicit param, fallback to summary, then content */}}
{{ $answer := "" }}
{{ if $page.Params.answer }}
{{ $answer = $page.Params.answer }}
{{ else if $page.Params.summary }}
{{ $answer = $page.Params.summary }}
{{ else }}
{{ $answer = $page.Content | plainify | truncate 500 }}
{{ end }}
{{/* Get upvote/downvote counts if available */}}
{{ $upvote_count := $page.Params.upvote_count | default 0 }}
{{ $downvote_count := $page.Params.downvote_count | default 0 }}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "QAPage",
"mainEntity": {
"@type": "Question",
"name": {{ $question | jsonify }},
"text": {{ $question | jsonify }},
"answerCount": 1,
{{ if $upvote_count }}"upvoteCount": {{ $upvote_count }},{{ end }}
"dateCreated": {{ $page.Date.Format "2006-01-02T15:04:05Z07:00" | jsonify }},
{{- with $author -}}
"author": {
"@type": "Person",
"name": {{ . | jsonify }}
},
{{- end -}}
"acceptedAnswer": {
"@type": "Answer",
"text": {{ $answer | plainify | jsonify }},
{{ if $upvote_count }}"upvoteCount": {{ $upvote_count }},{{ end }}
{{ if $downvote_count }}"downvoteCount": {{ $downvote_count }},{{ end }}
"dateCreated": {{ $page.Date.Format "2006-01-02T15:04:05Z07:00" | jsonify }},
{{- with $author -}}
"author": {
"@type": "Person",
"name": {{ . | jsonify }}
}{{- if or $page.Params.url $featured_image -}},{{- end -}}
{{- end -}}
{{- with $page.Params.url -}}
"url": {{ . | jsonify }}{{ if $featured_image }},{{ end }}
{{- end -}}
{{ if $featured_image }}
"image": {{ $featured_image.Permalink | jsonify }}
{{ end }}
}{{ if or $page.Params.suggested_answer $page.Params.additional_answers }},{{ end }}
{{- with $page.Params.suggested_answer -}}
"suggestedAnswer": [
{{- range $index, $answer := . -}}
{{- if $index }},{{ end -}}
{
"@type": "Answer",
"text": {{ $answer.text | jsonify }},
{{- with $answer.author -}}
"author": {
"@type": "Person",
"name": {{ . | jsonify }}
}{{ if or $answer.upvote_count $answer.date }},{{ end }}
{{- end -}}
{{- with $answer.upvote_count -}}
"upvoteCount": {{ . }},
{{- end -}}
{{- with $answer.date -}}
"dateCreated": {{ (time .) | time.Format "2006-01-02T15:04:05Z07:00" | jsonify }}
{{- end -}}
}
{{- end -}}
]
{{- end -}}
}
}
</script>