themu/layouts/partials/header.html
David Wittman 117808b653 Improve meta description
Rather than use the same description on every page, prefer the post
summary if it's available and only use .Params.description on the root
page.

This mimics the behavior of the [opengraph internal
template](https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html#L2)
for the `og:description` tag.
2021-05-22 21:38:59 +05:30

55 lines
2.5 KiB
HTML

<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
{{- $title := ( .Title ) -}}
{{- $siteTitle := ( .Site.Title ) -}}
{{- if .IsHome -}}
<title>{{ $siteTitle }} | Home </title>
{{- else -}}
<title>{{ $title }} - {{ $siteTitle }}</title>
{{- end -}}
{{- if isset .Site.Params "favicon" -}}
<link rel="icon" type="image/png" href={{ .Site.Params.favicon }} />
{{- end -}}
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
<meta property="og:image" content="{{ .Site.Params.og_image }}"/>
{{ with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ end -}}
{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/twitter_cards.html" . -}}
{{ if and (isset .Site.Params "social") (.Site.Params.useCDN | default false) -}}
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
{{- else if (isset .Site.Params "social") -}}
<script src="{{ .Site.BaseURL }}js/feather.min.js"></script>
{{ end }}
{{ if .Site.Params.useCDN | default false -}}
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@1,500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fira+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
{{- else -}}
<link href="{{ .Site.BaseURL }}css/fonts.css" rel="stylesheet">
{{ end }}
<link rel="stylesheet" type="text/css" media="screen" href="{{ .Site.BaseURL }}css/main.css" />
{{- if or (eq .Site.Params.mode "auto") (eq .Site.Params.mode "dark") -}}
<link rel="stylesheet" type="text/css" href="{{ .Site.BaseURL }}css/dark.css" {{ if eq .Site.Params.mode "auto" }}media="(prefers-color-scheme: dark)"{{ end }} />
{{ end }}
<!-- Custom CSS style get applied last -->
{{- if isset .Site.Params "customcss" }}
{{ range .Site.Params.customCSS }}
<link rel="stylesheet" type="text/css" href="{{ . | relURL }}">
{{ end }}
{{- end -}}
{{- range .Site.Params.customJS }}
{{- if or (hasPrefix . "http://") (hasPrefix . "https://") }}
<script src="{{ . }}"></script>
{{- else }}
<script src="{{ $.Site.BaseURL }}{{ . }}"></script>
{{- end }}
{{- end }}
</head>