Skip to content

Commit

Permalink
theme: sync Hugo templates and unification #841 #845
Browse files Browse the repository at this point in the history
- description
- title
- tags
  • Loading branch information
McShelby committed Apr 27, 2024
1 parent aed8845 commit 64b4ad7
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 41 deletions.
16 changes: 11 additions & 5 deletions layouts/_default/index.search.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{{- partialCached "page-meta.hugo" . .RelPermalink }}
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- $pages := slice }}
{{- range .Site.Pages }}
{{- if and .Title .RelPermalink (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }}
{{- $tags := slice }}
{{- range .GetTerms "tags" }}
{{- $tags = $tags | append (partial "pageHelper/title.hugo" (dict "page" .Page "linkTitle" true "format" $format "outputFormat" $outputFormat) | plainify) }}
{{- end }}
{{- $pages = $pages | append (dict
"uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .))
"title" (partial "pageHelper/title.hugo" (dict "page" .))
"tags" .Params.tags
"breadcrumb" (trim ((partial "breadcrumbs.html" (dict "page" . "dirOnly" true)) | plainify | htmlUnescape) "\n\r\t ")
"description" (or .Description .Summary)
"content" (.Plain | htmlUnescape)
"title" (partial "pageHelper/title.hugo" (dict "page" . "format" $format "outputFormat" $outputFormat) | plainify)
"tags" $tags
"breadcrumb" (partial "breadcrumbs.html" (dict "page" . "dirOnly" true) | plainify | htmlUnescape | chomp)
"description" (or .Description .Summary | plainify | htmlUnescape | chomp)
"content" (.Plain | htmlUnescape | chomp)
) }}
{{- end }}
{{- end -}}
Expand Down
12 changes: 7 additions & 5 deletions layouts/_default/rss.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- /* based on Hugo 0.125.3 rss.xml */}}
{{- /* based on Hugo 0.125.5 rss.xml */}}
{{- partialCached "page-meta.hugo" . .RelPermalink }}
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- /* Deprecate site.Author.email in favor of site.Params.author.email */}}
{{- $authorEmail := "" }}
{{- if and .Site.Params.author (reflect.IsMap .Site.Params.author) .Site.Params.author.email }}
Expand Down Expand Up @@ -27,9 +29,9 @@
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<title>{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) }}</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>
<description>{{ or .Description .Summary | plainify | htmlUnescape | chomp | transform.XMLEscape | safeHTML }}</description>
<generator>Hugo</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
<managingEditor>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
Expand All @@ -43,12 +45,12 @@
{{- $relearnIsHiddenFrom := index ($page.Scratch.Get "relearnIsHiddenFrom") .RelPermalink }}
{{- if and .Permalink .Title (or (not $relearnIsHiddenFrom) (ne .Site.Params.disableSeoHiddenPages true) ) }}
<item>
<title>{{ .Title }}</title>
<title>{{ partial "pageHelper/title.hugo" (dict "page" . "format" $format "outputFormat" $outputFormat) }}</title>
<link>{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}</link>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{- with $authorEmail }}<author>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</author>{{ end }}
<guid>{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}</guid>
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
<description>{{ or .Description .Summary | plainify | htmlUnescape | chomp | transform.XMLEscape | safeHTML }}</description>
</item>
{{- end }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.3 sitemap.xml */}}
{{- /* based on Hugo 0.125.5 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">
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/term.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2 id="{{ $capital | plainify | anchorize }}">{{ $capital }}</h2>
{{- /* display pages of a term */}}
{{- $breadcrumb := "" }}
{{- if (ne .Page.Site.Params.disableTermBreadcrumbs true) }}
{{- $breadcrumb = (trim ((partial "breadcrumbs.html" (dict "page" .Page "dirOnly" true)) | plainify | htmlUnescape) "\n\r\t ") }}
{{- $breadcrumb = partial "breadcrumbs.html" (dict "page" .Page "dirOnly" true) | plainify | htmlUnescape | chomp }}
{{- end }}
<li><a href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" .Page) }}">{{ .Title }}</a>{{ with $breadcrumb }}<div class="breadcrumbs highlightable" title="{{ . }}">{{ . }}</div>{{ end }}</li>
{{- $lastCapital = $capital }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/alias.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.3 alias.html */}}
{{- /* based on Hugo 0.125.5 alias.html */}}
<!DOCTYPE html>
<html>
<head>
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{- if not (and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) ) }}
<meta name="robots" content="noindex, nofollow, noarchive, noimageindex">
{{- end }}
<meta name="description" content="{{ with or .Description .Summary }}{{ . }}{{ end }}">
<meta name="description" content="{{ with or .Description .Summary | plainify | htmlUnescape | chomp }}{{ . }}{{ end }}">
{{- $authorName := partialCached "authorname.hugo" . }}
<meta name="author" content="{{ $authorName }}">
{{- partial "twitter_cards.html" . }}
Expand Down
15 changes: 9 additions & 6 deletions layouts/partials/opengraph.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.3 opengraph.html */}}
{{- /* based on Hugo 0.125.5 opengraph.html */}}
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- $basename := "index" }}
Expand All @@ -7,12 +7,15 @@
{{- end }}
<meta property="og:url" content="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}">

{{- with or site.Title site.Params.title | plainify }}
{{- with site.Title | plainify }}
<meta property="og:site_name" content="{{ . }}">
{{- end }}
<meta property="og:title" content="{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) | plainify }}">

{{- with or .Description .Summary | plainify }}
{{- with partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) | plainify }}
<meta property="og:title" content="{{ . }}">
{{- end }}

{{- with or .Description .Summary | plainify | htmlUnescape | chomp }}
<meta property="og:description" content="{{ . }}">
{{- end }}

Expand All @@ -23,7 +26,7 @@
{{- if .IsPage }}
<meta property="og:type" content="article">
{{- with .FirstSection }}
<meta property="article:section" content="{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) | plainify }}">
<meta property="article:section" content="{{ partial "pageHelper/title.hugo" (dict "page" . "format" $format "outputFormat" $outputFormat) | plainify }}">
{{- end }}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" }}
{{- with .PublishDate }}
Expand All @@ -33,7 +36,7 @@
<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}>
{{- end }}
{{- range .GetTerms "tags" | first 6 }}
<meta property="article:tag" content="{{ .Page.Title | plainify }}">
<meta property="article:tag" content="{{ partial "pageHelper/title.hugo" (dict "page" .Page "linkTitle" true "format" $format "outputFormat" $outputFormat) | plainify }}">
{{- end }}
{{- else }}
<meta property="og:type" content="website">
Expand Down
4 changes: 3 additions & 1 deletion layouts/partials/pageHelper/taxonomyPages.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- $pages := slice }}
{{- range .Data.Terms }}
{{- $count := 0 }}
Expand All @@ -8,7 +10,7 @@
{{- end }}
{{- end }}
{{- if $count }}
{{- $pages = $pages| append (dict "Title" (default (humanize .Page.Data.Term | strings.Title) .Page.Title) "Page" .Page "Count" $count )}}
{{- $pages = $pages| append (dict "Title" (partial "pageHelper/title.hugo" (dict "page" .Page "linkTitle" true "format" $format "outputFormat" $outputFormat)) "Page" .Page "Count" $count )}}
{{- end }}
{{- end }}
{{- $pages = sort $pages ".Title" }}
Expand Down
9 changes: 5 additions & 4 deletions layouts/partials/pageHelper/title.hugo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{- end }}
{{- $format := $.format | default (partial "get-format.hugo" .) }}
{{- $outputFormat := $.outputFormat | default (partial "output-format.hugo" (dict "page" . "format" $format)) }}
{{- $siteTitle := site.Title }}
{{- $title = .Title }}
{{- if $.linkTitle }}
{{- $title = or $.page.LinkTitle $title }}
Expand All @@ -13,7 +14,7 @@
{{- if eq $outputFormat "searchpage" }}
{{- $title = T "Search" }}
{{- else if eq .Kind "home" }}
{{- $title = or $title site.Title }}
{{- $title = or $title $siteTitle }}
{{- else if eq .Kind "taxonomy" }}
{{- $title = default (default .Data.Plural (i18n .Data.Plural)) .Params.Title }}
{{- else if eq .Kind "term" }}
Expand All @@ -30,11 +31,11 @@
{{- end }}

{{- if $.fullyQualified }}
{{- if and $title site.Title (not (eq $title site.Title)) }}
{{- if and $title $siteTitle (not (eq $title $siteTitle)) }}
{{- if $.reverse }}
{{- $title = printf "%s %s %s" $title (default "::" site.Params.titleSeparator) site.Title }}
{{- $title = printf "%s %s %s" $title (default "::" site.Params.titleSeparator) $siteTitle }}
{{- else }}
{{- $title = printf "%s %s %s" site.Title (default "::" site.Params.titleSeparator) $title }}
{{- $title = printf "%s %s %s" $siteTitle (default "::" site.Params.titleSeparator) $title }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
14 changes: 8 additions & 6 deletions layouts/partials/schema.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{{- /* based on Hugo 0.125.3 schema.html */}}
{{- with partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true) }}
{{- /* based on Hugo 0.125.5 schema.html */}}
{{- $format := partial "get-format.hugo" . }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
{{- with partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) | plainify }}
<meta itemprop="name" content="{{ . }}">
{{- end }}

{{- with or .Description .Summary }}
{{- with or .Description .Summary | plainify | htmlUnescape | chomp }}
<meta itemprop="description" content="{{ . }}">
{{- end }}

Expand Down Expand Up @@ -36,17 +38,17 @@
*/}}
{{- $keywords := slice }}
{{- range .GetTerms "keywords" }}
{{- $keywords = $keywords | append .Title }}
{{- $keywords = $keywords | append (partial "pageHelper/title.hugo" (dict "page" .Page "linkTitle" true "format" $format "outputFormat" $outputFormat) | plainify) }}
{{- else }}
{{- with .Keywords }}
{{- $keywords = . }}
{{- else }}
{{- range .GetTerms "tags" }}
{{- $keywords = $keywords | append .Title }}
{{- $keywords = $keywords | append (partial "pageHelper/title.hugo" (dict "page" .Page "linkTitle" true "format" $format "outputFormat" $outputFormat) | plainify) }}
{{- else }}
{{- range $taxonomy, $_ := site.Taxonomies }}
{{- range $.GetTerms $taxonomy }}
{{- $keywords = $keywords | append .Title }}
{{- $keywords = $keywords | append (partial "pageHelper/title.hugo" (dict "page" .Page "linkTitle" true "format" $format "outputFormat" $outputFormat) | plainify) }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/shortcodes/image.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.3 render-image.html */}}
{{- /* based on Hugo 0.125.5 render-image.html */}}
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/shortcodes/link.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- /* based on Hugo 0.125.3 render-link.html */}}
{{- /* based on Hugo 0.125.5 render-link.html */}}
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/term-list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- $page := .page }}
{{- $format := partial "get-format.hugo" $page }}
{{- $outputFormat := partial "output-format.hugo" (dict "page" $page "format" $format) }}
{{- $taxonomy := .taxonomy }}
{{- $class := .class }}
{{- $color := .color | default "" }}
Expand All @@ -18,24 +20,24 @@
{{- $term := . }}
{{- $term_key := $term }}
{{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }}
{{- $term_pages = $term_pages | append (dict "Title" (default (humanize .Data.Term | strings.Title) .Title) "Term" . )}}
{{- $term_pages = $term_pages | append (dict "Title" (partial "pageHelper/title.hugo" (dict "page" . "linkTitle" true "format" $format "outputFormat" $outputFormat)) "Term" . )}}
{{- else }}
{{- $term = trim $term " " }}
{{- if not $term }}
{{- continue }}
{{- end }}
{{- $term_key = ($term | plainify | anchorize) }}
{{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }}
{{- $term_pages = $term_pages | append (dict "Title" (default (humanize .Data.Term | strings.Title) .Title) "Term" . )}}
{{- $term_pages = $term_pages | append (dict "Title" (partial "pageHelper/title.hugo" (dict "page" . "linkTitle" true "format" $format "outputFormat" $outputFormat)) "Term" . )}}
{{- else }}
{{- $term_key = ($term | urlize) }}
{{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }}
{{- $term_pages = $term_pages | append (dict "Title" (default (humanize .Data.Term | strings.Title) .Title) "Term" . )}}
{{- $term_pages = $term_pages | append (dict "Title" (partial "pageHelper/title.hugo" (dict "page" . "linkTitle" true "format" $format "outputFormat" $outputFormat)) "Term" . )}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- $taxonomy_title := default (default $taxonomy_page.Data.Plural (i18n $taxonomy_page.Data.Plural)) $taxonomy_page.Params.Title }}
{{- $taxonomy_title := partial "pageHelper/title.hugo" (dict "page" $taxonomy_page "format" $format "outputFormat" $outputFormat) }}
{{- with $term_pages }}
<div class=" taxonomy-{{ $taxonomy }} term-list cstyle {{ $style }} {{ $class }}" title="{{ $taxonomy_title }}"{{ if $color }}{{ printf " style=\"--VARIABLE-TAGS-BG-color: %s;\"" $color | safeHTMLAttr }}{{ end }}>
{{- if $icon }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/topbar/button/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{- $currentDisableToc := .Params.disableToc | default $defaultDisableToc }}
{{- if and (eq $outputFormat "html") (not $currentDisableToc) }}
{{- $content := partial "toc-class.html" . }}
{{- $hascontent := not (eq 0 (int (len (trim ($content | plainify) "\n\r\t ")))) }}
{{- $hascontent := not (eq 0 (int (len ($content | plainify | chomp)))) }}
{{- if not $hascontent }}
{{- $content = " " }}
{{- end }}
Expand Down
12 changes: 9 additions & 3 deletions layouts/partials/twitter_cards.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{{- /* based on Hugo 0.125.3 twitter_cards.html */}}
{{- /* based on Hugo 0.125.5 twitter_cards.html */}}
{{- $images := partial "_funcs/get-page-images" . }}
{{- with index $images 0 }}
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="{{ .Permalink }}">
{{- else }}
<meta name="twitter:card" content="summary">
{{- end }}
<meta name="twitter:title" content="{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true) }}">
<meta name="twitter:description" content="{{ with or .Description .Summary }}{{ . }}{{ end }}">

{{- with partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true) | plainify }}
<meta name="twitter:title" content="{{ . }}">
{{- end }}

{{- with or .Description .Summary | plainify | htmlUnescape | chomp }}
<meta name="twitter:description" content="{{ . }}">
{{- end }}

{{- $twitterSite := "" }}
{{- with site.Params.social }}
Expand Down

0 comments on commit 64b4ad7

Please sign in to comment.