summaryrefslogtreecommitdiffstats
path: root/layouts/partials
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2024-09-29 15:54:01 +0200
committerSerghei Iakovlev <git@serghei.pl>2024-09-29 18:15:42 +0200
commit0882a21997b0830f43643cac9f0de4beaa698988 (patch)
tree581a1dea498805ef5b9259fbf095b5546d705a78 /layouts/partials
parentec19cd59b5fc2ee4dc12b65647099c595984c075 (diff)
downloadgohugo-theme-ed-0882a21997b0830f43643cac9f0de4beaa698988.tar.gz
Rework author configuration
Diffstat (limited to 'layouts/partials')
-rw-r--r--layouts/partials/author.html14
-rw-r--r--layouts/partials/head.html7
-rw-r--r--layouts/partials/head/author.html13
-rw-r--r--layouts/partials/post-meta/author.html3
-rw-r--r--layouts/partials/schema.org/article.html19
-rw-r--r--layouts/partials/site-author.html35
6 files changed, 35 insertions, 56 deletions
diff --git a/layouts/partials/author.html b/layouts/partials/author.html
deleted file mode 100644
index 4ca1209..0000000
--- a/layouts/partials/author.html
+++ /dev/null
@@ -1,14 +0,0 @@
-{{- $siteAuthor := partial "site-author.html" . -}}
-
-{{- /* First, check for current page author(s) */}}
-{{- if .Params.author }}
- {{- $author_type := (printf "%T" .Params.author) }}
- {{- if (or (eq $author_type "[]string") (eq $author_type "[]interface {}")) }}
- {{- (delimit .Params.author ", " ) }}
- {{- else }}
- {{- .Params.author }}
- {{- end }}
-{{- /* Otherwise, get site authors */}}
-{{- else if $siteAuthor.name }}
- {{- $siteAuthor.name }}
-{{- end -}}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 94684a2..0a4b02a 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -8,7 +8,12 @@
<meta name="description" content="{{ partial "description.html" . }}">
<meta name="keywords" content="{{ delimit (partial "keywords.html" .) ", " }}">
- <meta name="author" content="{{ partial "author.html" . }}">
+ {{ $showAuthor := .Site.Params.showAuthor | default false }}
+ {{- $author := partial "head/author.html" . }}
+ {{ if (and $showAuthor (ne $author ""))}}
+ <meta name="author" content="{{ $author }}">
+ {{- end }}
+
{{ hugo.Generator }}
{{ partial "styles.html" . }}
diff --git a/layouts/partials/head/author.html b/layouts/partials/head/author.html
new file mode 100644
index 0000000..94788e9
--- /dev/null
+++ b/layouts/partials/head/author.html
@@ -0,0 +1,13 @@
+{{- $author := "" -}}
+
+{{- with .Params.author -}}
+ {{- if (reflect.IsSlice .) -}}
+ {{- $author = delimit . ", " -}}
+ {{- else -}}
+ {{- $author = . -}}
+ {{- end -}}
+{{- else -}}
+ {{- $author = site.Params.author.name -}}
+{{- end -}}
+
+{{- return $author -}}
diff --git a/layouts/partials/post-meta/author.html b/layouts/partials/post-meta/author.html
deleted file mode 100644
index 1b56004..0000000
--- a/layouts/partials/post-meta/author.html
+++ /dev/null
@@ -1,3 +0,0 @@
-{{ with .Params.author }}
- <span class="author">{{ i18n "by" . }}</span>
-{{ end }}
diff --git a/layouts/partials/schema.org/article.html b/layouts/partials/schema.org/article.html
index f4112b6..1549784 100644
--- a/layouts/partials/schema.org/article.html
+++ b/layouts/partials/schema.org/article.html
@@ -13,7 +13,20 @@
{{- $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") -}}
{{- $logo = $logo.Resize "96x96" }}
-{{- $siteAuthor := partial "site-author.html" . }}
+{{- $siteAuthorName := "" }}
+{{- $siteAuthorTwitter := "" }}
+{{- with site.Params.author }}
+ {{- if reflect.IsMap . }}
+ {{- with .name }}
+ {{- $siteAuthorName = . }}
+ {{- end -}}
+ {{- with .twitter }}
+ {{- $siteAuthorTwitter = . }}
+ {{- end }}
+ {{- else }}
+ {{- $siteAuthorName = . }}
+ {{- end }}
+{{- end }}
<script type="application/ld+json" id="schema-data">
{
@@ -53,10 +66,10 @@
],
{{- end }}
{{- else }}
- {{- with $siteAuthor.name }}
+ {{- with $siteAuthorName }}
"author": {
"@type": "Person",
- "name": {{ . }}{{ with $siteAuthor.twitter }},
+ "name": {{ . }}{{ with $siteAuthorTwitter }},
"url": "https://twitter.com/{{ . }}"{{ end }}
},
{{- end }}
diff --git a/layouts/partials/site-author.html b/layouts/partials/site-author.html
deleted file mode 100644
index cd6dbf4..0000000
--- a/layouts/partials/site-author.html
+++ /dev/null
@@ -1,35 +0,0 @@
-{{- /*
-
-This partial is used to get the site author information.
-
-In Hugo v0.124.0, the site.Author variable was deprecated. Instead, it is recommended to use
-the "author" parameters in the site configuration file.
-
-This partial checks for the presence of author information in both site.Author and site.Params.author.
-If both are present, preference is given to site.Params.author.
-
-The result is stored in the $siteAuthor variable and returned by the partial.
-
-Usage:
-
- {{ $siteAuthor := partial "site-author.html" . }}
-
- {{ with $siteAuthor.name }} {{ . }} {{ end }}
- {{ with $siteAuthor.email }} {{ . }} {{ end }}
- {{ with $siteAuthor.github }} {{ . }} {{ end }}
- {{ with $siteAuthor.twitter }} {{ . }} {{ end }}
- {{ with $siteAuthor.location }} {{ . }} {{ end }}
-
-For more information, see: https://github.com/gohugoio/hugo/releases/tag/v0.124.0
-*/ -}}
-
-{{- $siteAuthor := dict "name" "" "email" "" "github" "" "twitter" "" "location" "" -}}
-
-{{- if site.Params.author -}}
- {{- $siteAuthor = merge $siteAuthor site.Params.author -}}
-{{- else if site.Author -}}
- {{- $siteAuthor = merge $siteAuthor site.Author -}}
- {{- warnf "The author key in site configuration is deprecated. Use site.params.author instead." }}
-{{- end -}}
-
-{{- return $siteAuthor -}}