{{- /*
SEO partial — OpenGraph, Twitter Cards, JSON-LD Article schema.
Override: drop `layouts/_partials/head/seo.html` into your site to replace.
*/ -}}
{{- $ogTitle := cond .IsHome site.Title .Title -}}
{{- $fullTitle := cond .IsHome site.Title (printf "%s · %s" .Title site.Title) -}}
{{- $rawDesc := .Description | default .Summary | default site.Params.description -}}
{{- $desc := "" -}}
{{- with $rawDesc -}}{{- $desc = . | plainify | truncate 200 -}}{{- end -}}
{{- /* OG/Twitter image: per-post `cover.image` → per-post `image` → site `og.fallbackImage` → `data/profile.yaml: avatar`. */ -}}
{{- $img := "" -}}
{{- with .Params.cover -}}{{- $img = .image -}}{{- end -}}
{{- if not $img -}}{{- $img = .Params.image -}}{{- end -}}
{{- if not $img -}}{{- $img = site.Params.og.fallbackImage -}}{{- end -}}
{{- if not $img -}}{{- with site.Data.profile -}}{{- $img = .avatar -}}{{- end -}}{{- end -}}
{{- /* OG locale: map common Hugo lang codes to OpenGraph IETF-with-region. */ -}}
{{- $ogLocale := site.Params.og.locale | default (index (dict "vi" "vi_VN" "en" "en_US" "ja" "ja_JP" "zh" "zh_CN" "ko" "ko_KR" "fr" "fr_FR" "de" "de_DE") site.Language.Lang) | default site.LanguageCode -}}
{{/* OpenGraph */}}
{{- with $desc }}
{{- end }}
{{- with $ogLocale }}
{{- end }}
{{- with $img }}
{{- end }}
{{- if and .IsPage (eq .Kind "page") .Date }}
{{- with .Lastmod }}
{{- end }}
{{- with site.Params.author | default (and site.Data.profile site.Data.profile.name) }}
{{- end }}
{{- range .GetTerms "tags" }}
{{- end }}
{{- end }}
{{/* Twitter Card */}}
{{- with $desc }}
{{- end }}
{{- with site.Params.social.twitter }}
{{- end }}
{{- with $img }}
{{- end }}
{{- /* JSON-LD Article — only on single posts (IsPage + Kind page). */ -}}
{{- if and .IsPage (eq .Kind "page") -}}
{{- $authorName := site.Params.author | default (and site.Data.profile site.Data.profile.name) | default site.Title -}}
{{- $authorURL := "" -}}
{{- with site.Params.profile -}}{{- $authorURL = .url -}}{{- end -}}
{{- if not $authorURL -}}{{- with site.Data.profile -}}{{- $authorURL = .url -}}{{- end -}}{{- end -}}
{{- if not $authorURL -}}{{- $authorURL = site.Home.Permalink -}}{{- end -}}
{{- $keywords := slice -}}
{{- range .GetTerms "tags" -}}{{- $keywords = $keywords | append .LinkTitle -}}{{- end -}}
{{- $publisher := dict "@type" "Organization" "name" site.Title -}}
{{- with $img }}{{- $publisher = merge $publisher (dict "logo" (dict "@type" "ImageObject" "url" (. | absURL))) -}}{{- end -}}
{{- $ld := dict
"@context" "https://schema.org"
"@type" "Article"
"headline" .Title
"url" .Permalink
"mainEntityOfPage" (dict "@type" "WebPage" "@id" .Permalink)
"datePublished" (.Date.Format "2006-01-02T15:04:05Z07:00")
"dateModified" (.Lastmod.Format "2006-01-02T15:04:05Z07:00")
"author" (dict "@type" "Person" "name" $authorName "url" $authorURL)
"publisher" $publisher
-}}
{{- with $img }}{{- $ld = merge $ld (dict "image" (. | absURL)) -}}{{- end -}}
{{- with $desc }}{{- $ld = merge $ld (dict "description" .) -}}{{- end -}}
{{- if $keywords }}{{- $ld = merge $ld (dict "keywords" $keywords) -}}{{- end -}}
{{- end -}}