1

Refond la page d’accueil

This commit is contained in:
2025-09-20 01:38:54 +02:00
parent 03943034ca
commit 52ac7de5bc
6 changed files with 423 additions and 26 deletions

View File

@@ -1,27 +1,68 @@
{{- define "main" }}
<main>
<section id="hero">
{{ $logo := resources.GetMatch "logo-large.png" -}}
{{- with $logo.Resize "x256" -}}
<img src="{{ .RelPermalink }}" alt="Logo" class="site-logo" />
{{- end }}
{{- $site := .Site -}}
{{- $logoPath := $site.Params.logo | default "logo-large.png" -}}
{{- $logo := resources.GetMatch $logoPath -}}
{{- $siteDescription := $site.Params.description -}}
{{- $allArticles := $site.RegularPages.ByDate.Reverse -}}
{{- $totalArticles := len $site.RegularPages -}}
{{- $allSections := where $site.Pages "Kind" "section" -}}
{{- $allSections = where $allSections "RelPermalink" "!=" "/" -}}
{{- $leafSections := slice -}}
{{- range $allSections -}}
{{- if eq (len .Sections) 0 -}}
{{- $leafSections = $leafSections | append . -}}
{{- end -}}
{{- end -}}
{{- $sectionsCount := len $leafSections -}}
{{- $lastUpdated := $site.Lastmod -}}
<div class="article-content">
{{ .Content -}}
</div>
<main>
{{- partial "home-hero.html" (dict "Logo" $logo "Title" $site.Title "Description" $siteDescription "Content" .Content "TotalArticles" $totalArticles "SectionsCount" $sectionsCount "LastUpdated" $lastUpdated "HeroMenu" $site.Menus.hero) -}}
{{- $featured := index $allArticles 0 -}}
{{- $used := slice $featured.File.Path -}}
<section class="articles-list featured-section">
<h2>En vedette</h2>
{{- partial "featured-card.html" (dict "Page" $featured) -}}
</section>
{{- $recent := first 4 (after 1 $allArticles) -}}
{{- range $recent }}
{{- $used = $used | append .File.Path -}}
{{- end -}}
<section class="articles-list">
{{- $pages := site.RegularPages -}}
{{- $paginator := .Paginate $pages.ByDate.Reverse 12 -}}
{{- $context := . -}}
{{- $context.Scratch.Set "paginationPosition" "down" -}}
{{- $context.Scratch.Set "paginator" $paginator -}}
{{- partial "pagination.html" $context -}}
{{- partial "articles-list.html" (dict "Pages" $paginator.Pages "Context" $context) -}}
{{- $context.Scratch.Set "paginationPosition" "up" -}}
{{- $context.Scratch.Set "paginator" $paginator -}}
{{- partial "pagination.html" $context -}}
<h2>Dernières publications</h2>
{{- partial "articles-list.html" (dict "Pages" $recent "Context" .) -}}
</section>
{{- range sort $leafSections "Lastmod" "desc" -}}
{{- $section := . -}}
{{- $sectionPages := slice -}}
{{- range $section.RegularPagesRecursive.ByDate.Reverse -}}
{{- if not (in $used .File.Path) -}}
{{- $sectionPages = $sectionPages | append . -}}
{{- end -}}
{{- end -}}
{{- $sectionPages = first 4 $sectionPages -}}
<section class="articles-list">
{{- $trail := slice -}}
{{- range $ancestor := $section.Ancestors.Reverse -}}
{{- if ne $ancestor.RelPermalink "/" -}}
{{- $trail = $trail | append $ancestor -}}
{{- end -}}
{{- end -}}
<nav aria-label="Fil dAriane">
<ol>
{{- range $item := $trail -}}
<li><a href="{{ $item.RelPermalink }}">{{ with $item.LinkTitle }}{{ . }}{{ else }}{{ $item.Title }}{{ end }}</a></li>
{{- end -}}
</ol>
</nav>
<h2><a href="{{ $section.RelPermalink }}">{{ with $section.LinkTitle }}{{ . }}{{ else }}{{ $section.Title }}{{ end }}</a></h2>
{{- partial "articles-list.html" (dict "Pages" $sectionPages "Context" .) -}}
</section>
{{- end -}}
</main>
{{- end }}
{{- end }}

View File

@@ -0,0 +1,41 @@
{{- $page := .Page -}}
{{- $coverPath := $page.Params.cover -}}
{{- $img := false -}}
{{- if $coverPath -}}
{{- if strings.HasSuffix $coverPath ".yaml" -}}
{{- $coverAbsPath := printf "%s%s" $page.File.Dir $coverPath -}}
{{- $coverRaw := readFile $coverAbsPath -}}
{{- $coverData := $coverRaw | transform.Unmarshal -}}
{{- with $coverData.file -}}
{{- $img = $page.Resources.GetMatch . -}}
{{- end -}}
{{- else -}}
{{- $img = $page.Resources.GetMatch $coverPath -}}
{{- end -}}
{{- end -}}
<article class="featured-card">
<a class="featured-card__image" href="{{ $page.RelPermalink }}">
{{- if $img -}}
{{- $resized := $img.Resize "640x" -}}
<img src="{{ $resized.RelPermalink }}" alt="{{ default $page.Title $page.Params.cover_alt }}" loading="lazy" />
{{- else -}}
<div class="featured-card__image--placeholder" aria-hidden="true"></div>
{{- end -}}
</a>
<div class="featured-card__body">
<div class="featured-card__meta">
{{- with $page.Parent }}
<span class="featured-card__section">{{ .LinkTitle }}</span>
{{- end }}
{{- with $page.Date }}
<time datetime="{{ . | time.Format "2006-01-02" }}">{{ . | time.Format ":date_long" }}</time>
{{- end }}
</div>
<h3 class="featured-card__title"><a href="{{ $page.RelPermalink }}">{{ $page.Title }}</a></h3>
{{- with $page.Summary }}
<p class="featured-card__summary">{{ . | plainify }}</p>
{{- end }}
<a class="featured-card__cta" href="{{ $page.RelPermalink }}">Lire larticle</a>
</div>
</article>

View File

@@ -0,0 +1,56 @@
{{- $logo := .Logo -}}
{{- $title := .Title -}}
{{- $description := .Description -}}
{{- $content := .Content -}}
{{- $total := .TotalArticles -}}
{{- $sectionsCount := .SectionsCount -}}
{{- $lastUpdated := .LastUpdated -}}
{{- $menu := .HeroMenu -}}
<section id="hero">
<header>
{{- with $logo -}}
<figure>
<img src="{{ .RelPermalink }}" alt="Logo de {{ $title }}" />
</figure>
{{- end -}}
<div>
<h1>{{ $title }}</h1>
{{- with $description }}
<div class="site-description">{{ . }}</div>
{{- end }}
</div>
</header>
{{- with $content }}
<div>
{{ . }}
</div>
{{- end }}
<ul>
<li>
<strong>Articles publiés</strong>
<span>{{ $total }}</span>
</li>
<li>
<strong>Thématiques</strong>
<span>{{ $sectionsCount }}</span>
</li>
<li>
<strong>Dernière mise à jour</strong>
<time datetime="{{ $lastUpdated | time.Format "2006-01-02" }}">{{ $lastUpdated | time.Format "02/01/2006" }}</time>
</li>
</ul>
<hr class="hr-mirror">
{{- with $menu }}
<nav>
{{- range . }}
<a href="{{ .URL }}" title="{{ .Title }}">{{ .Name }}</a>
{{- end }}
</nav>
{{- end }}
<hr />
</section>