1
Files
2025/themes/42/layouts/_partials/card.html

61 lines
2.3 KiB
HTML

<a href="{{ .RelPermalink }}" class="card panel panel-hero">
{{ $page := . -}}
{{- $coverPath := .Params.cover -}}
{{- $img := false -}}
{{- if $coverPath -}}
{{- $coverResourcePath := (urls.Parse $coverPath).Path -}}
{{- if ne $coverResourcePath "" -}}
{{- $coverPathLower := lower $coverResourcePath -}}
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
{{- $coverDataFile := $page.Resources.Get $coverResourcePath -}}
{{- if $coverDataFile -}}
{{- with $coverDataFile.Content | transform.Unmarshal -}}
{{- with index . "file" -}}
{{- $coverFilePath := strings.TrimSpace (printf "%v" .) -}}
{{- if ne $coverFilePath "" -}}
{{- $img = $page.Resources.Get $coverFilePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $img = $page.Resources.Get $coverResourcePath -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $img -}}
{{- with $img -}}
{{- $resized := .Fill "450x220" -}}
<div class="card-image" style="background-image: url({{ $resized.RelPermalink }});"></div>
{{ end -}}
{{ else }}<div class="card-image"></div>
{{ end -}}
<div class="card-content">
{{ index .Params.dossier 0 }}
<h3>{{ .Title }}</h3>
{{- if not $page.IsSection -}}
{{- with $page.Date -}}
<time datetime="{{ . }}">{{ . | time.Format ":date_long" }}</time>
{{- end -}}
{{- end -}}
<div class="card-meta">
{{ $section := "" -}}
{{- with .Parent -}}
{{- $sectionPath := path.Base .File.Dir -}}
{{- $section = $sectionPath -}}
{{- end -}}
<span class="section section-{{ $section }}">{{ .Parent.LinkTitle }}</span>
<span class="reading-time">
{{ if .IsSection -}}
{{- $count := len .Pages -}}
{{- $label := cond (eq $count 1) "article" "articles" -}}
{{- $count }} {{ $label -}}
{{- else -}}
{{- if ge .ReadingTime 5 -}}
{{- .ReadingTime }} min de lecture
{{- end -}}
{{- end }}
</span>
</div>
</div>
</a>