Skip to content

Commit

Permalink
theme: sync to Hugo's implementation #841
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Apr 22, 2024
1 parent f4df3a0 commit af29d89
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 43 deletions.
7 changes: 4 additions & 3 deletions layouts/_default/rss.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* based on Hugo 0.125.3 rss.xml */}}
{{- partialCached "page-meta.hugo" . .RelPermalink }}
{{- /* Deprecate site.Author.email in favor of site.Params.author.email */}}
{{- $authorEmail := "" }}
Expand Down Expand Up @@ -29,15 +30,15 @@
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
<language>{{ . }}</language>{{end}}{{ with $authorEmail }}
<generator>Hugo</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
<managingEditor>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with .Site.Copyright }}
<copyright>{{ . }}</copyright>{{ end }}{{ if not .Date.IsZero }}
<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "rss" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" ( partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true)) .MediaType | safeHTML }}
{{- end -}}
{{- end }}
{{- range $pages }}
{{- $relearnIsHiddenFrom := index ($page.Scratch.Get "relearnIsHiddenFrom") .RelPermalink }}
{{- if and .Permalink .Title (or (not $relearnIsHiddenFrom) (ne .Site.Params.disableSeoHiddenPages true) ) }}
Expand Down
5 changes: 3 additions & 2 deletions layouts/_default/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{- /* based on Hugo 0.125.3 sitemap.xml */}}
{{- partialCached "page-meta.hugo" . .RelPermalink }}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{- range where .Pages "Sitemap.Disable" "ne" true }}
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) }}
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) }}
<url>
<loc>{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}</loc>{{ if not .Lastmod.IsZero }}
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
Expand All @@ -11,6 +12,6 @@
<xhtml:link rel="alternate" hreflang="x-default" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />{{ end }}
<xhtml:link rel="alternate" hreflang="{{ .Language.LanguageCode }}" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />{{ end }}{{ end }}
</url>
{{- end -}}
{{- end -}}
{{- end }}
</urlset>
5 changes: 3 additions & 2 deletions layouts/alias.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* based on Hugo 0.125.3 alias.html */}}
<!DOCTYPE html>
<html>
<head>
Expand All @@ -22,9 +23,9 @@
<meta charset="utf-8">
<meta name="robots" content="noindex">
<meta http-equiv="refresh" content="0; url={{ $url }}">
{{- $link := "<link href=\"%s\" rel=\"%s\" type=\"%s\" title=\"%s\">" }}
{{- $link := "<link href=\"%s\" rel=\"%s\">" }}
<title>{{ $url }}</title>

{{ (printf $link $url "canonical" "text/html" ($url | htmlEscape)) | safeHTML }}
{{ (printf $link $url "canonical" ($url | htmlEscape)) | safeHTML }}
</head>
</html>
25 changes: 8 additions & 17 deletions layouts/partials/opengraph.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.0 _internal/opengraph.html but with modified title */}}
{{- /* based on Hugo 0.125.3 opengraph.html */}}
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- $basename := "index" }}
Expand Down Expand Up @@ -74,23 +74,14 @@
{{- end }}
{{- end }}

{{- $facebookAdmin := "" }}
{{- with site.Params.social.facebook_admin }}
{{- $facebookAdmin = . }}
{{- else }}
{{- with site.Social.facebook_admin }}
{{- $facebookAdmin = . }}
{{- $hugoVersion := "0.120.0" }}
{{- if ge hugo.Version $hugoVersion }}
{{- warnf "The social key in site configuration is deprecated. Use params.social.facebook_admin instead." }}
{{- end }}
{{- end }}
{{- end }}

{{- with $facebookApp }}
{{- with site.Params.social }}
{{- if reflect.IsMap . }}
{{- with .facebook_app_id }}
<meta property="fb:app_id" content="{{ . }}">
{{- else }}
{{- with $facebookAdmin }}
{{- else }}
{{- with .facebook_admin }}
<meta property="fb:admins" content="{{ . }}">
{{- end }}
{{- end }}
{{- end }}
{{- end }}
3 changes: 2 additions & 1 deletion layouts/partials/shortcodes/image.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* based on Hugo 0.125.3 render-image.html */}}
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
Expand Down Expand Up @@ -77,7 +78,7 @@
{{- $classes = $classes | append $c }}
{{- end }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
{{- $attributes = merge $attributes (dict "alt" $alt "src" $url "title" $title) }}
{{- $attributes = merge $attributes (dict "alt" $alt "src" $url "title" ($title | transform.HTMLEscape)) }}
{{- if $effects.lazy }}
{{- $attributes = merge $attributes (dict "loading" "lazy") }}
{{- end }}
Expand Down
3 changes: 2 additions & 1 deletion layouts/partials/shortcodes/link.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* based on Hugo 0.125.3 render-link.html */}}
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
Expand All @@ -10,7 +11,7 @@
{{- $attributes := dict }}
{{- $title := .title | default "" }}
{{- $title = trim $title " " }}
{{- $attributes = $attributes | merge (dict "title" $title) }}
{{- $attributes = $attributes | merge (dict "title" ($title | transform.HTMLEscape)) }}
{{- $content := .content }}
{{- $target := .target | default "" }}
{{- $u := urls.Parse $url }}
Expand Down
26 changes: 9 additions & 17 deletions layouts/partials/twitter_cards.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.0 _internal/twitter_cardss.html but with modified title */}}
{{- /* based on Hugo 0.125.3 twitter_cards.html */}}
{{- $images := partial "_funcs/get-page-images" . }}
{{- with index $images 0 }}
<meta name="twitter:card" content="summary_large_image">
Expand All @@ -10,22 +10,14 @@
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">

{{- $twitterSite := "" }}
{{- with site.Params.social.twitter }}
{{- $twitterSite = . }}
{{- else }}
{{- with site.Social.twitter }}
{{- $twitterSite = . }}
{{- $hugoVersion := "0.120.0" }}
{{- if ge hugo.Version $hugoVersion }}
{{- warnf "The social key in site configuration is deprecated. Use params.social.twitter instead." }}
{{- with site.Params.social }}
{{- if reflect.IsMap . }}
{{- with .twitter }}
{{- $content := . }}
{{- if not (strings.HasPrefix . "@") }}
{{- $content = printf "@%v" . }}
{{- end }}
<meta name="twitter:site" content="{{ $content }}"/>
{{- end }}
{{- end }}
{{- end }}

{{- with $twitterSite }}
{{- $content := . }}
{{- if not (strings.HasPrefix . "@") }}
{{- $content = printf "@%v" . }}
{{- end }}
<meta name="twitter:site" content="{{ $content }}">
{{- end }}

0 comments on commit af29d89

Please sign in to comment.