refactor: extract author name extraction logic to a partial
Extracts duplicated logic for resolving an author's name from a generic author object (which can be a map or a string) into a new reusable partial `layouts/partials/get_author_name.html`. Updates multiple files to use this new partial, improving code maintainability.
Co-authored-by: KarelZe <12801659+KarelZe@users.noreply.github.com>
4 files modified
1 files added
| | |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- $authorName := "" -}} |
| | | {{- with site.Params.author -}} |
| | | {{- if reflect.IsMap . -}} |
| | | {{- with .name -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- else -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- $authorName := partial "get_author_name.html" site.Params.author -}} |
| | | {{- $pctx := . -}} |
| | | {{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} |
| | | {{- $pages := slice -}} |
| | |
| | | {{- $authorName := "" -}} |
| | | {{- with .context.Site.Params.author -}} |
| | | {{- if reflect.IsMap . -}} |
| | | {{- with .name -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- else -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- $authorName := partial "get_author_name.html" .context.Site.Params.author -}} |
| | | <footer class="footer footer__{{ .footerClassModifier }}"> |
| | | <ul |
| | | class="footer__list {{ with .context.Site.Params.doNotLoadAnimations }} |
| New file |
| | |
| | | {{- $authorName := "" -}} |
| | | {{- with . -}} |
| | | {{- if reflect.IsMap . -}} |
| | | {{- with .name -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- else -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- return $authorName -}} |
| | |
| | | <head> |
| | | <meta charset="utf-8" /> |
| | | {{- $authorName := "" -}} |
| | | {{- with .Site.Params.author -}} |
| | | {{- if reflect.IsMap . -}} |
| | | {{- with .name -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- else -}} |
| | | {{- $authorName = . -}} |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- $authorName := partial "get_author_name.html" .Site.Params.author -}} |
| | | <title> |
| | | {{ if (eq .Site.Params.reversepagetitle true) }} |
| | | {{ with .Title }} |
| | |
| | | } |
| | | </script> |
| | | {{ else if .IsPage }} |
| | | {{- $author := "" -}} |
| | | {{- with or (.Params.author) (.Site.Params.author) -}} |
| | | {{- if reflect.IsMap . -}} |
| | | {{- with .name -}} |
| | | {{- $author = . -}} |
| | | {{- end -}} |
| | | {{- else -}} |
| | | {{- $author = . -}} |
| | | {{- end -}} |
| | | {{- end -}} |
| | | {{- $author := partial "get_author_name.html" (or .Params.author .Site.Params.author) -}} |
| | | {{ $favicon := .Site.Params.favicon | absURL }} |
| | | <script type="application/ld+json"> |
| | | { |