diff options
author | Oscar Najera <hi@oscarnajera.com> | 2023-11-02 00:30:06 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2023-11-02 00:33:48 +0100 |
commit | 76b72515b6d8078268077bd9d96db493fb7bd6f8 (patch) | |
tree | d3cf609717445b7022de5986b253d2f677f9f8c3 /layouts | |
parent | 0060dc0a5cd3e7486da6e360ffea7cebcbf99759 (diff) | |
download | hugo-minimalist-theme-76b72515b6d8078268077bd9d96db493fb7bd6f8.tar.gz hugo-minimalist-theme-76b72515b6d8078268077bd9d96db493fb7bd6f8.tar.bz2 hugo-minimalist-theme-76b72515b6d8078268077bd9d96db493fb7bd6f8.zip |
structured metadata image like leading image
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/head.html | 48 | ||||
-rw-r--r-- | layouts/partials/structured-data.html | 113 |
2 files changed, 115 insertions, 46 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 38e31b7..35384ba 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,20 +1,38 @@ <head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - {{ partial "structured-data.html" . }} + {{ partial "structured-data.html" . }} - {{ with resources.Get "scss/style.scss" | resources.ToCSS (dict "includePaths" (slice "node_modules") "targetPath" "css/style.css") | resources.Minify | fingerprint }} - <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous" type="text/css" media="screen" /> - {{ end }} - <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> - <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jpswalsh/academicons@1/css/academicons.min.css"> + {{ with resources.Get "scss/style.scss" | resources.ToCSS (dict "includePaths" (slice "node_modules") "targetPath" "css/style.css") | resources.Minify | fingerprint }} + <link + rel="stylesheet" + href="{{ .RelPermalink }}" + integrity="{{ .Data.Integrity }}" + crossorigin="anonymous" + type="text/css" + media="screen" + /> + {{ end }} + <link + rel="stylesheet" + href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" + integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" + crossorigin="anonymous" + referrerpolicy="no-referrer" + /> + <link + rel="stylesheet" + href="https://cdn.jsdelivr.net/gh/jpswalsh/academicons@1/css/academicons.min.css" + /> - {{ with resources.Get .Site.Params.favicon }} - <link rel="icon" href="{{ .RelPermalink }}"> - {{ end }} -{{ range .AlternativeOutputFormats -}} - {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} -{{ end -}} + {{ with resources.Get .Site.Params.favicon }} + <link rel="icon" href="{{ .RelPermalink }}" /> + {{ end }} + {{ range .AlternativeOutputFormats -}} + {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} + {{ end -}} -<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script> + + <script + type="text/javascript" + src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" + ></script> </head> diff --git a/layouts/partials/structured-data.html b/layouts/partials/structured-data.html index 8d4e917..c55bcdd 100644 --- a/layouts/partials/structured-data.html +++ b/layouts/partials/structured-data.html @@ -1,51 +1,102 @@ +<meta charset="utf-8" /> +<meta name="viewport" content="width=device-width, initial-scale=1" /> {{ $title := print .Site.Title " | " .Title }} {{ if .IsHome }}{{ $title = .Site.Title }}{{ end }} <title>{{ $title }}</title> +{{ $image := "" }} +{{ if (.Resources.ByType "image").GetMatch "*featured*" }} + {{ $image = (.Resources.ByType "image").GetMatch "*featured*" }} +{{ else if resources.Get (index .Params.images 0) }} + {{ $image = resources.Get (index .Params.images 0) }} +{{ end }} -{{ with resources.Get (index .Params.images 0) }} -{{ $image := .Fill (default "400x400" $.Params.image_size) }} -<meta name="twitter:card" content="summary_large_image"/> -<meta name="twitter:image" content="{{ $image.Permalink }}"/> -<meta property="og:image" content="{{ $image.Permalink }}"/> +{{ if and $image (ne $image.MediaType.SubType "svg") }} + {{ $image := $image.Fit (default "768x400" $.Params.image_size) }} + <meta name="twitter:card" content="summary_large_image" /> + <meta name="twitter:image" content="{{ $image.Permalink }}" /> + <meta property="og:image" content="{{ $image.Permalink }}" /> {{ else }} -<meta name="twitter:card" content="summary"/> + <meta name="twitter:card" content="summary" /> {{ end }} -<meta name="twitter:title" content="{{ .Title }}"/> -<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/> -{{ with .Site.Social.twitter -}} -<meta name="twitter:site" content="@{{ . }}"/> -{{ end -}} +<meta name="twitter:title" content="{{ .Title }}" /> +<meta + name="twitter:description" + content="{{ with .Description }} + {{ . }} + {{ else }} + {{ if .IsPage }} + {{ .Summary }} + {{ else }} + {{ with .Site.Params.description }}{{ . }}{{ end }} + {{ end }} + {{ end -}}" +/> <meta property="og:title" content="{{ .Title }}" /> -<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" /> -<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" /> +<meta + property="og:description" + content="{{ with .Description }} + {{ . }} + {{ else }} + {{ if .IsPage }} + {{ .Summary }} + {{ else }} + {{ with .Site.Params.description }}{{ . }}{{ end }} + {{ end }} + {{ end }}" +/> +<meta + property="og:type" + content="{{ if .IsPage }} + article + {{ else }} + website + {{ end }}" +/> <meta property="og:url" content="{{ .Permalink }}" /> {{- if .IsPage }} -{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} -<meta property="article:section" content="{{ .Section }}" /> -{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }} -{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }} + {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} + <meta property="article:section" content="{{ .Section }}" /> + {{ with .PublishDate }} + <meta + property="article:published_time" + {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} + /> + {{ end }} + {{ with .Lastmod }} + <meta + property="article:modified_time" + {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} + /> + {{ end }} {{- end -}} {{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }} -{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }} -{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}" />{{ end }} -{{- with .Params.videos }}{{- range . }} -<meta property="og:video" content="{{ . | absURL }}" /> -{{ end }}{{ end }} +{{- with .Params.locale }} + <meta property="og:locale" content="{{ . }}" /> +{{ end }} +{{- with .Site.Params.title }} + <meta property="og:site_name" content="{{ . }}" /> +{{ end }} +{{- with .Params.videos }} + {{- range . }} + <meta property="og:video" content="{{ . | absURL }}" /> + {{ end }} +{{ end }} {{- /* If it is part of a series, link to related articles */}} {{- $permalink := .Permalink }} {{- $siteSeries := .Site.Taxonomies.series }} {{- if $siteSeries }} -{{ with .Params.series }}{{- range $name := . }} - {{- $series := index $siteSeries ($name | urlize) }} - {{- range $page := first 6 $series.Pages }} - {{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}" />{{ end }} - {{- end }} -{{ end }}{{ end }} + {{ with .Params.series }} + {{- range $name := . }} + {{- $series := index $siteSeries ($name | urlize) }} + {{- range $page := first 6 $series.Pages }} + {{- if ne $page.Permalink $permalink }} + <meta property="og:see_also" content="{{ $page.Permalink }}" /> + {{ end }} + {{- end }} + {{ end }} + {{ end }} {{- end }} - -{{- /* Facebook Page Admin ID for Domain Insights */}} -{{- with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }} |