fix: harden editorial brand rendering and SEO
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
fall back sensibly to brand data. */ -}}
|
||||
{{- $brand := .Site.Data.brand -}}
|
||||
|
||||
{{- $title := "" -}}
|
||||
{{- if .IsHome -}}
|
||||
{{- $title = .Params.title | default (printf "%s | %s" $brand.name $brand.tagline) -}}
|
||||
{{- else -}}
|
||||
{{- $title = printf "%s | %s" (.Params.title | default .Title) $brand.name -}}
|
||||
{{- $pageTitle := .Params.seoTitle | default .Params.title | default .Title -}}
|
||||
{{- $title := $pageTitle -}}
|
||||
{{- if and (not .IsHome) (not (in (lower $pageTitle) (lower $brand.name))) -}}
|
||||
{{- $title = printf "%s | %s" $pageTitle $brand.name -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $desc := "" -}}
|
||||
@@ -19,30 +18,55 @@
|
||||
{{- $desc = $desc | plainify | chomp | truncate 160 -}}
|
||||
|
||||
{{- /* Per-page OG image override (.Params.image) with fallback to the site default. */ -}}
|
||||
{{- $ogImage := (.Params.image | default .Site.Params.ogImage) | absURL -}}
|
||||
{{- $imagePath := .Params.image | default .Site.Params.ogImage -}}
|
||||
{{- $ogImage := cond (ne $imagePath "") ($imagePath | absURL) "" -}}
|
||||
{{- $ogImageAlt := .Params.imageAlt | default (printf "%s - %s" $brand.name $pageTitle) -}}
|
||||
{{- $ogLocale := $brand.defaultLocale | default .Language.LanguageCode | default .Language.Lang -}}
|
||||
{{- range $brand.supportedLocales -}}
|
||||
{{- if or (eq . $.Language.LanguageCode) (hasPrefix . (printf "%s-" $.Language.Lang)) -}}{{- $ogLocale = . -}}{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $isPlaceholderHost := or (in (lower .Site.BaseURL) "example.com") (in (lower .Site.BaseURL) ".example") -}}
|
||||
{{- $noindex := or .Params.noindex $isPlaceholderHost (eq .Kind "404") -}}
|
||||
{{- $schemaType := .Params.schemaType | default "none" -}}
|
||||
{{- $isArticle := in (slice "Article" "Review") $schemaType -}}
|
||||
{{- $canonical := .Params.canonicalURL | default .Permalink -}}
|
||||
|
||||
<title>{{ $title }}</title>
|
||||
<meta name="description" content="{{ $desc }}">
|
||||
<link rel="canonical" href="{{ .Permalink }}">
|
||||
<meta name="robots" content="{{ if .Params.noindex }}noindex,nofollow{{ else }}index,follow{{ end }}">
|
||||
<meta name="author" content="{{ $brand.name }}">
|
||||
{{- if ne .Kind "404" }}
|
||||
<link rel="canonical" href="{{ $canonical }}">
|
||||
{{- end }}
|
||||
<meta name="robots" content="{{ if $noindex }}noindex,follow{{ else }}index,follow{{ end }}">
|
||||
<meta name="author" content="{{ .Params.authorName | default $brand.name }}">
|
||||
|
||||
{{- /* Open Graph */ -}}
|
||||
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}">
|
||||
<meta property="og:type" content="{{ if $isArticle }}article{{ else }}website{{ end }}">
|
||||
<meta property="og:title" content="{{ $title }}">
|
||||
<meta property="og:description" content="{{ $desc }}">
|
||||
<meta property="og:url" content="{{ .Permalink }}">
|
||||
<meta property="og:site_name" content="{{ $brand.name }}">
|
||||
<meta property="og:locale" content="{{ replace (.Language.LanguageCode | default .Language.Lang) "-" "_" }}">
|
||||
<meta property="og:image" content="{{ $ogImage }}">
|
||||
<meta property="og:image:width" content="1200">
|
||||
<meta property="og:image:height" content="630">
|
||||
<meta property="og:locale" content="{{ replace $ogLocale "-" "_" }}">
|
||||
{{- with $ogImage }}
|
||||
<meta property="og:image" content="{{ . }}">
|
||||
<meta property="og:image:alt" content="{{ $ogImageAlt }}">
|
||||
<meta property="og:image:width" content="{{ $.Params.imageWidth | default 1200 }}">
|
||||
<meta property="og:image:height" content="{{ $.Params.imageHeight | default 630 }}">
|
||||
{{- end }}
|
||||
{{- if and $isArticle (not .Date.IsZero) }}
|
||||
<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
|
||||
{{- end }}
|
||||
{{- if and $isArticle (not .Lastmod.IsZero) }}
|
||||
<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">
|
||||
{{- end }}
|
||||
|
||||
{{- /* Twitter */ -}}
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="{{ $title }}">
|
||||
<meta name="twitter:description" content="{{ $desc }}">
|
||||
<meta name="twitter:image" content="{{ $ogImage }}">
|
||||
{{- with $ogImage }}
|
||||
<meta name="twitter:image" content="{{ . }}">
|
||||
<meta name="twitter:image:alt" content="{{ $ogImageAlt }}">
|
||||
{{- end }}
|
||||
|
||||
{{- /* hreflang alternates for the multilingual build. No-op on single-language
|
||||
sites (.IsTranslated is false), so it is safe to keep permanently. URL
|
||||
|
||||
Reference in New Issue
Block a user