Fix twitter cards e tags

This commit is contained in:
loviuz 2022-07-03 23:31:05 +02:00
parent b1cd663da9
commit 0aa61b959f
6 changed files with 203 additions and 42 deletions

View File

@ -38,6 +38,8 @@ pygmentscodefencesguesssyntax = true
[taxonomies]
category = "categorie"
tags = "tags"
# Social links
[[params.social]]

View File

@ -0,0 +1,25 @@
{{- with $.Params.images -}}
{{- $image := $.Resources.GetMatch (index . 0) -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ $image.Permalink }}"/>
{{ else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{- with $featured -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ $featured.Permalink }}"/>
{{- else -}}
{{- with $.Site.Params.images -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
{{ else -}}
<meta name="twitter:card" content="summary"/>
{{- end -}}
{{- end -}}
{{- end }}
<meta name="twitter:title" content="{{ .Title }}"/>
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/>
{{ with .Site.Social.twitter -}}
<meta name="twitter:site" content="@{{ . }}"/>
{{ end -}}

View File

@ -15,50 +15,52 @@
{{ .Content }}
<ul class="news-list">
{{ range .Paginator.Pages }}
{{ $image := .Resources.GetMatch (index (.Params.images) 0) }}
<li>
{{ if $image }}
{{ $image := $image.Resize "x480" }}
{{ $image := $image.Crop "480x350" }}
<div class="news-image">
<a href="{{ .Params.externalLink | default .RelPermalink }}">
<img src="{{ $image.RelPermalink }}">
</a>
</div>
{{ if .Params.images }}
{{ $image := .Resources.GetMatch (index (.Params.images) 0) }}
{{ if $image }}
<li>
{{ $image := $image.Resize "x480" }}
{{ $image := $image.Crop "480x350" }}
<div class="news-image">
<a href="{{ .Params.externalLink | default .RelPermalink }}">
<img src="{{ $image.RelPermalink }}">
</a>
</div>
<div class="date">
<span class="posted-on">
<i class="fa fa-calendar" aria-hidden="true"></i>
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ .Date | time.Format (.Site.Params.dateFormat | default "2 January 2006" ) }}
</time>
</span>
<span class="reading-time">
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ i18n "reading_time" .ReadingTime }}
</span>
</div>
<hr class="light">
<a class="title" href="{{ .Params.externalLink | default .RelPermalink }}">{{ .Title }}</a><br>
<span class="description">{{ .Params.description }}</span>
<br><br>
{{ if .Params.tags }}
<div class="tags">
<i class="fa fa-tag" aria-hidden="true"></i>
{{- range $index, $el := .Params.tags -}}
{{- if gt $index 0 }}
<span class="separator"></span>
{{- end }}
<span class="tag">
<a href="{{ ( printf "tags/%s/" ( . | urlize ) ) | relLangURL }}">{{ . }}</a>
<div class="date">
<span class="posted-on">
<i class="fa fa-calendar" aria-hidden="true"></i>
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ .Date | time.Format (.Site.Params.dateFormat | default "2 January 2006" ) }}
</time>
</span>
{{- end -}}
</div>
{{ end }}
<div style="clear:both;"></div>
</li>
<span class="reading-time">
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ i18n "reading_time" .ReadingTime }}
</span>
</div>
<hr class="light">
<a class="title" href="{{ .Params.externalLink | default .RelPermalink }}">{{ .Title }}</a><br>
<span class="description">{{ .Params.description }}</span>
<br><br>
{{ if .Params.tags }}
<div class="tags">
<i class="fa fa-tag" aria-hidden="true"></i>
{{- range $index, $el := .Params.tags -}}
{{- if gt $index 0 }}
<span class="separator"></span>
{{- end }}
<span class="tag">
<a href="{{ ( printf "tags/%s/" ( . | urlize ) ) | relLangURL }}">{{ . }}</a>
</span>
{{- end -}}
</div>
{{ end }}
<div style="clear:both;"></div>
</li>
{{ end }}
{{ end }}
{{ end }}
</ul>

4
layouts/tags/li.html Normal file
View File

@ -0,0 +1,4 @@
<li>
<span class="date">{{ .Date | time.Format (.Site.Params.dateFormat | default "January 2, 2006" ) }}</span>
<a class="title" href="{{ .Params.externalLink | default .RelPermalink }}">{{ .Title }}</a>
</li>

69
layouts/tags/list.html Normal file
View File

@ -0,0 +1,69 @@
{{ define "title" }}
{{ title (i18n (lower .Title)) | default .Title }} · {{ .Site.Title }}
{{ end }}
{{ define "content" }}
<section class="container list">
<h1 class="title">
<a class="title-link" href="{{ .Permalink | safeURL }}">
{{- if eq .Kind "term" -}}
{{- i18n .Data.Plural 1 | title -}}
{{- print ": " -}}
{{- end -}}
{{- i18n (lower .Title) | default .Title | title -}}
</a>
</h1>
{{ .Content }}
<ul class="news-list">
{{ range .Paginator.Pages }}
{{ if .Params.images }}
{{ $image := .Resources.GetMatch (index (.Params.images) 0) }}
{{ if $image }}
<li>
{{ $image := $image.Resize "x480" }}
{{ $image := $image.Crop "480x350" }}
<div class="news-image">
<a href="{{ .Params.externalLink | default .RelPermalink }}">
<img src="{{ $image.RelPermalink }}">
</a>
</div>
<div class="date">
<span class="posted-on">
<i class="fa fa-calendar" aria-hidden="true"></i>
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ .Date | time.Format (.Site.Params.dateFormat | default "2 January 2006" ) }}
</time>
</span>
<span class="reading-time">
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ i18n "reading_time" .ReadingTime }}
</span>
</div>
<hr class="light">
<a class="title" href="{{ .Params.externalLink | default .RelPermalink }}">{{ .Title }}</a><br>
<span class="description">{{ .Params.description }}</span>
<br><br>
{{ if .Params.tags }}
<div class="tags">
<i class="fa fa-tag" aria-hidden="true"></i>
{{- range $index, $el := .Params.tags -}}
{{- if gt $index 0 }}
<span class="separator"></span>
{{- end }}
<span class="tag">
<a href="{{ ( printf "tags/%s/" ( . | urlize ) ) | relLangURL }}">{{ . }}</a>
</span>
{{- end -}}
</div>
{{ end }}
<div style="clear:both;"></div>
</li>
{{ end }}
{{ end }}
{{ end }}
</ul>
{{ partial "pagination.html" . }}
</section>
{{ end }}

59
layouts/tags/single.html Normal file
View File

@ -0,0 +1,59 @@
{{ define "title" }}
{{ .Title }} · {{ .Site.Title }}
{{ end }}
{{ define "content" }}
<section class="container post">
{{ if .Section }}
<a href="{{.Site.BaseURL}}/{{.Section}}"><i class="fa fa-chevron-left fa-fw"></i> Torna alle {{.Section}}</a>
{{ end }}
<article>
<header>
<div class="post-title">
<h1 class="title">
<a class="title-link" href="{{ .Permalink | safeURL }}">
{{ .Title }}
</a>
</h1>
</div>
<div class="post-meta">
<div class="date">
<span class="posted-on">
<i class="fa fa-calendar" aria-hidden="true"></i>
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ .Date | time.Format (.Site.Params.dateFormat | default "2 January 2006" ) }}
</time>
</span>
<span class="reading-time">
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ i18n "reading_time" .ReadingTime }}
</span>
</div>
{{ with .Page.Params.Authors }}{{ partial "taxonomy/authors.html" . }}{{ end }}
{{ with .Page.Params.Categories }}{{ partial "taxonomy/categories.html" . }}{{ end }}
{{ with .Page.Params.Tags }}{{ partial "taxonomy/tags.html" . }}{{ end }}
</div>
</header>
<div>
{{ with .Resources.GetMatch (index (.Params.images) 0) }}
{{ $image := . }}
{{ $image := $image.Crop "1280x250" }}
<img src="{{ $image.RelPermalink }}">
{{ end }}
{{ .TableOfContents }}
{{ .Content | safeHTML }}
</div>
<footer>
{{ partial "posts/series.html" . }}
{{ partial "posts/disqus.html" . }}
{{ partial "posts/commento.html" . }}
{{ partial "posts/utterances.html" . }}
</footer>
</article>
{{ partial "posts/math.html" . }}
</section>
{{ end }}