1
0
mirror of https://github.com/alanorth/hugo-theme-bootstrap4-blog.git synced 2024-11-16 01:07:03 +01:00
hugo-theme-bootstrap4-blog/layouts/_default/single.html
Alan Orth 2459ad9567
layouts/_default/single.html: Simplify sharing icon logic
Allowing users to select specific icons they want to show makes the
configuration and logic a bit tricky. A user brought up the case of
disabling sharing icons on certain pages/posts, and it was actaully
not possible without adding lots of extra logic, not to mention the
pain of having to test all possible configurations.

Instead, it is much simpler to just allow sharing icons to be either
on or off as desired in the site config or page/post frontmatter:

  sharingicons = false

Otherwise, sharing icons default to being enabled, as this is most
in line with what would be expected on a "blog".
2017-01-21 19:16:57 +02:00

88 lines
2.5 KiB
HTML

{{ define "title" }}{{ .Title | markdownify }} | {{ .Site.Title }}{{ end }}
{{ define "schema-dot-org" }}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
{{/* Google recommends the headline be no more than 110 characters */}}
"headline": {{ substr .Title 0 110 }},
{{- with .Params.images -}}{{ range first 1 . }}
"image": {
"@type": "ImageObject",
"url": {{ . | absURL }}
},
{{- end -}}{{ end }}
"url": {{ printf "%s" .Permalink }},
"wordCount": "{{ .WordCount }}",
{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}
{{ if not .PublishDate.IsZero }}
"datePublished": {{ .PublishDate.Format $ISO8601 }},
{{ else }}
"datePublished": {{ .Date.Format $ISO8601 }},
{{ end }}
{{ if not .Lastmod.IsZero }}
"dateModified": {{ .Lastmod.Format $ISO8601 }},
{{ end }}
{{ with .Site.Social.GooglePlus }}
"publisher": {{ printf "%s" . }},
{{ end }}
"author": {
"@type": "Person",
"name": {{ .Params.author | default .Site.Params.author }}
}
{{ if or (.Params.categories) (.Params.tags) }}
,
"keywords": "{{ with .Params.categories }}{{ range $i, $e := . }}{{ if $i }},{{ end }}{{ $e }}{{ end }},{{ end }}{{ with .Params.tags }}{{ range $i, $e := . }}{{ if $i }},{{ end }}{{ $e }}{{ end }}{{ end }}"
{{ end }}
{{- with .Params.description -}}
,
"description": {{ . }}
{{ end }}
}
</script>
{{ end }}
{{ define "main" }}
{{ $dateFormat := default "Mon Jan 2, 2006" (index .Site.Params "date_format") }}
<article class="blog-post">
<header>
<h2 class="blog-post-title"><a href="{{ .Permalink }}">{{ .Title | markdownify }}</a></h2>
<p class="blog-post-meta"><time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">{{ .Date.Format $dateFormat }}</time> by {{ .Params.author | default .Site.Params.author }}{{ if or (.Params.categories) (.Params.tags) }} in {{ partial "meta-terms.html" . }}{{ end }}</p>
</header>
{{ .Content }}
{{ if .IsTranslated }}
<h4>{{ i18n "translations" }}</h4>
<ul>
{{ range .Translations }}
<li>
<a href="{{ .Permalink }}">{{ .Lang }}: {{ .Title }}{{ if .IsPage }}{{ end }}</a>
</li>
{{ end }}
</ul>
{{ end }}
{{ if or (ne ($.Param "sharingicons") false) (.Site.DisqusShortname) }}
<hr>
<footer>
{{ if (ne ($.Param "sharingicons") false) }}
{{ partial "sharing-icons.html" . }}
{{ end }}
{{ if and (.Site.DisqusShortname) (ne .Params.comments false) }}
{{ partial "disqus.html" . }}
{{ end }}
</footer>
{{ end }}
</article> <!-- /.blog-post -->
{{ end }}
{{- /* vim: set ts=2 sw=2 et: */}}