Browse Source

Use a partial to build the <title> tag and RSS link title

Code from Minimo theme:

https://github.com/MunifTanjim/minimo/blob/master/layouts/partials/data/title

Thanks @MunifTanjim.
master
Adrian Short 7 years ago
parent
commit
f831fcae03
2 changed files with 27 additions and 2 deletions
  1. +17
    -0
      layouts/partials/data/title
  2. +10
    -2
      layouts/partials/header.html

+ 17
- 0
layouts/partials/data/title View File

@@ -0,0 +1,17 @@
{{- $title := .Title -}}
{{- $siteTitle := .Site.Title -}}
{{- $authorName := .Site.Author.name -}}
{{- $sep := ( .Site.Params.SEO.titleSeparator | default "•" ) -}}
{{- if .IsHome -}}
{{ $siteTitle }}
{{- else if eq .Kind "taxonomy" -}}
{{ title .Data.Singular }}: {{ $title }} {{ $sep }} {{ $siteTitle }}
{{- else if ( or .IsNode ( eq .Section "page" ) ) -}}
{{ $title }} {{ $sep }} {{ $siteTitle }}
{{- else -}}
{{- with $authorName -}}
{{ $title }} {{ $sep }} {{ . }}
{{- else -}}
{{ $title }} {{ $sep }} {{ $siteTitle }}
{{- end -}}
{{- end -}}

+ 10
- 2
layouts/partials/header.html View File

@@ -1,13 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ .Site.Title }}</title>
<title>{{ partial "data/title" . }}</title>
{{ .Hugo.Generator }}
{{ "<!-- Tumble theme for Hugo: https://github.com/adrianshort/tumble -->" | safeHTML }}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ relURL "/css/main.css" }}">
<link rel="alternate" type="application/rss+xml" title="{{ .Site.Title }}"
<link rel="alternate" type="application/rss+xml" title="{{ partial "data/title" . }}"
href="{{ .RSSLink }}">
</head>
<body>
<h1 id="site-title"><a href="{{ relURL "/" }}">{{ .Site.Title }}</a></h1>
{{ with .RSSLink }}
<p><a href="{{ . }}" title="{{ partial "data/title" }}">RSS</a></p>
{{ end }}
<ul>
{{ range .Site.Sections }}
<li><a href="{{ .URL }}">{{ .Title }}</a></li>
{{ end }}
</ul>

Loading…
Cancel
Save