From 143e1b2d77675f8881fd62e1c490fe75f93109e8 Mon Sep 17 00:00:00 2001 From: Olivia206 <olivia.simonet206@gmail.com> Date: Thu, 18 Apr 2024 18:14:51 +0200 Subject: [PATCH] added options to posts layouts --- assets/sass/_theme/blocks/posts.sass | 59 +++++++++++-------- layouts/partials/blocks/templates/posts.html | 9 +++ .../blocks/templates/posts/alternate.html | 6 +- .../blocks/templates/posts/carousel.html | 2 + .../partials/blocks/templates/posts/grid.html | 3 + .../blocks/templates/posts/highlight.html | 24 +++++--- .../blocks/templates/posts/large.html | 39 ++++++------ .../partials/blocks/templates/posts/list.html | 4 ++ layouts/partials/posts/post.html | 49 +++++++++------ 9 files changed, 122 insertions(+), 73 deletions(-) diff --git a/assets/sass/_theme/blocks/posts.sass b/assets/sass/_theme/blocks/posts.sass index c73f7f07..f7e8ff91 100644 --- a/assets/sass/_theme/blocks/posts.sass +++ b/assets/sass/_theme/blocks/posts.sass @@ -46,8 +46,20 @@ .post-meta display: block line-height: 0 // Hack pour que les enfants de post-meta soient correctement - .post-categories * + > * + margin-right: $spacing-3 + time + vertical-align: baseline + .post-author + display: inline + p + display: inline + .post-categories display: inline + * + display: inline-block + li + margin-right: $spacing-2 // Désactiver le ratio forcé de la configuration $article-media-aspect-ratio .media &, img @@ -56,13 +68,6 @@ .post + .post margin-top: $spacing-4 - &-meta - .post-author - display: inline - p - display: inline - &::after - content: ' — ' p[itemprop="articleBody"] margin-top: 0 @include media-breakpoint-up(desktop) @@ -76,20 +81,10 @@ @include h2 p[itemprop="articleBody"] margin-top: $spacing-3 - .post-meta - > * - display: inline - &:not(:last-child)::after - content: ' — ' - .post-author - p - display: inline .post-categories li a display: inline - &:not(:last-child) a::after - content: ',' @include in-page-with-sidebar .large @@ -152,13 +147,13 @@ @include in-page-with-sidebar article padding-bottom: $spacing-3 + gap: var(--grid-gutter) // gap plutôt que marge pour l'affichage avec ou sans image + article margin-top: $spacing-3 .media width: columns(2) .post-content width: columns(6) - margin-left: var(--grid-gutter) @include in-page-without-sidebar article @@ -218,12 +213,12 @@ .highlight-post .post flex-direction: row + gap: var(--grid-gutter) // pour le cas où on masque l'image .media width: columns(3) margin-bottom: 0 .post-content width: columns(5) - margin-left: var(--grid-gutter) .list article @include grid(8, desktop, 0, 0) @@ -258,17 +253,29 @@ aspect-ratio: unset @include media-breakpoint-up(desktop) - .post - &.right + &:not(.without-images) + .post + &.right + margin-left: auto + &.portrait + + .portrait + margin-top: -30% + + .square, + + .landscape + margin-top: -15% + + .post:not(.portrait, .square, .landscape) + margin-top: -5% + &.without-images + .right margin-left: auto - &.portrait + .portrait + .portrait - margin-top: -30% + margin-top: 0 + .square, + .landscape - margin-top: -15% - + .post:not(.portrait, .square, .landscape) margin-top: -5% + + .post:not(.portrait, .square, .landscape) + margin-top: -3% @include media-breakpoint-down(desktop) .post diff --git a/layouts/partials/blocks/templates/posts.html b/layouts/partials/blocks/templates/posts.html index c8b0fb9c..af9fadeb 100644 --- a/layouts/partials/blocks/templates/posts.html +++ b/layouts/partials/blocks/templates/posts.html @@ -4,6 +4,14 @@ {{- $term := false -}} {{- $layout := .block.data.layout | default "grid" -}} {{- with .block.data }} + {{- $options := dict + "hide_image" .hide_image + "hide_summary" .hide_summary + "hide_category" .hide_category + "hide_author" .hide_author + "hide_date" .hide_date + -}} + {{ if .category }} {{- $term = site.GetPage (printf "/posts_categories%s" .category) -}} {{ end }} @@ -39,6 +47,7 @@ {{ partial (printf "blocks/templates/posts/%s.html" $layout) (dict "posts" .posts "heading_level" $block.ranks.children + "options" $options )}} {{ end }} diff --git a/layouts/partials/blocks/templates/posts/alternate.html b/layouts/partials/blocks/templates/posts/alternate.html index 840bb387..7cd85342 100644 --- a/layouts/partials/blocks/templates/posts/alternate.html +++ b/layouts/partials/blocks/templates/posts/alternate.html @@ -1,6 +1,9 @@ {{ $heading_level := .heading_level | default 3 }} {{ $heading := printf "h%d" $heading_level }} -<div class="alternate"> +{{ $options := .options }} +{{ $hide_image := .options.hide_image }} + +<div class="alternate {{- if $hide_image }} without-images{{ end }}"> {{ range $i, $post := .posts -}} {{ with site.GetPage (printf "/posts/%s" $post) }} {{ partial "posts/post.html" (dict @@ -8,6 +11,7 @@ "heading" $heading "index" $i "alternate" true + "options" $options ) }} {{ end }} {{ end }} diff --git a/layouts/partials/blocks/templates/posts/carousel.html b/layouts/partials/blocks/templates/posts/carousel.html index df639937..aa537630 100644 --- a/layouts/partials/blocks/templates/posts/carousel.html +++ b/layouts/partials/blocks/templates/posts/carousel.html @@ -1,5 +1,6 @@ {{ $heading_level := .heading_level | default 3 }} {{ $heading := printf "h%d" $heading_level }} +{{ $options := .options }} <div class="carousel draggable-container"> <div class="carousel-posts draggable-content"> @@ -9,6 +10,7 @@ <li class="draggable-item"> {{ partial "posts/post.html" (dict "post" . + "options" $options "heading" $heading) }} </li> {{ end }} diff --git a/layouts/partials/blocks/templates/posts/grid.html b/layouts/partials/blocks/templates/posts/grid.html index b09828e5..0d6bc38d 100644 --- a/layouts/partials/blocks/templates/posts/grid.html +++ b/layouts/partials/blocks/templates/posts/grid.html @@ -1,11 +1,14 @@ {{ $heading_level := .heading_level | default 3 }} {{ $heading := printf "h%d" $heading_level }} +{{ $options := .options }} + <div class="grid"> {{ range $post := .posts -}} {{ with site.GetPage (printf "/posts/%s" $post) }} {{ partial "posts/post.html" (dict "post" . "heading" $heading + "options" $options ) }} {{ end }} {{ end }} diff --git a/layouts/partials/blocks/templates/posts/highlight.html b/layouts/partials/blocks/templates/posts/highlight.html index 082a9b00..de4d08ae 100644 --- a/layouts/partials/blocks/templates/posts/highlight.html +++ b/layouts/partials/blocks/templates/posts/highlight.html @@ -4,6 +4,8 @@ "open" ((printf "<%s class='post-title' itemprop='headline'>" $heading) | safeHTML) "close" ((printf "</%s>" $heading) | safeHTML) ) }} +{{ $options := .options }} + <div class="highlight"> {{ $highlight := index .posts 0 }} {{ $highlight = site.GetPage (printf "/posts/%s" $highlight)}} @@ -14,6 +16,7 @@ {{ partial "posts/post" (dict "post" . "heading" $heading + "options" $options ) }} </div> {{ end }} @@ -29,10 +32,10 @@ <a href="{{ .Permalink }}" title="{{ safeHTML (i18n "commons.more_aria" (dict "Title" $title)) }}">{{ $title }}</a> {{ $heading_tag.close }} - {{ if site.Params.posts.index.show_categories }} + {{ if and site.Params.posts.index.show_categories (eq $options.hide_cathegory false) }} {{- partial "posts/categories" . -}} {{ end }} - {{ if site.Params.posts.index.show_description }} + {{ if and site.Params.posts.index.show_description (eq $options.hide_summary false) }} {{- if (partial "GetTextFromHTML" .Params.summary) -}} <p itemprop="articleBody">{{ partial "GetTruncateContent" ( dict "text" .Params.summary @@ -40,13 +43,16 @@ ) }}</p> {{- end -}} {{- end -}} - - <div class="post-meta"> - <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format site.Params.posts.date_format }}</time> - {{ if site.Params.posts.index.show_author }} - {{- partial "posts/author" . -}} - {{ end }} - </div> + {{- if or (eq $options.hide_author false) (eq $options.hide_date false) -}} + <div class="post-meta"> + {{- if eq $options.hide_date false -}} + <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format site.Params.posts.date_format }}</time> + {{ end }} + {{ if and site.Params.posts.index.show_author (eq $options.hide_author false) }} + {{- partial "posts/author" . -}} + {{ end }} + </div> + {{ end }} </article> {{ end }} {{ end }} diff --git a/layouts/partials/blocks/templates/posts/large.html b/layouts/partials/blocks/templates/posts/large.html index c434aa66..d1279d21 100644 --- a/layouts/partials/blocks/templates/posts/large.html +++ b/layouts/partials/blocks/templates/posts/large.html @@ -5,13 +5,13 @@ "attributes" "class='post-title' itemprop='headline'" )}} {{ $index := .index}} - +{{ $options := .options }} <div class="large"> {{ range .posts }} {{ with site.GetPage (printf "/posts/%s" .) }} - {{ if .Params.image }} + {{ if and .Params.image (eq $options.hide_image false) }} {{- $direction = partial "GetImageDirection" .Params.image -}} {{ end }} @@ -24,17 +24,19 @@ {{ $heading_tag.close }} <div class="post-meta"> - {{ if site.Params.posts.index.show_author }} + {{ if and site.Params.posts.index.show_author (eq $options.hide_author false) }} {{- partial "posts/author" . -}} {{ end }} - <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format site.Params.posts.date_format }}</time> - {{ if site.Params.posts.index.show_categories }} + {{ if eq $options.hide_date false }} + <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format site.Params.posts.date_format }}</time> + {{ end }} + {{ if and site.Params.posts.index.show_categories (eq $options.hide_cathegory false) }} {{- partial "posts/categories" . -}} {{ end }} </div> - {{ if site.Params.posts.index.show_description }} + {{ if and site.Params.posts.index.show_description (eq $options.hide_summary false) }} {{- if (partial "GetTextFromHTML" .Params.summary) -}} <p itemprop="articleBody">{{ partial "GetTruncateContent" ( dict "text" .Params.summary @@ -44,18 +46,19 @@ {{- end -}} <p class="more meta" aria-hidden="true">{{- i18n "commons.more" -}}</p> </div> - - <div class="media"> - {{- if .Params.image -}} - {{- partial "commons/image.html" - (dict - "image" .Params.image - "sizes" site.Params.image_sizes.sections.posts.item - ) -}} - {{- else -}} - {{- partial "commons/image-default.html" "posts" -}} - {{- end -}} - </div> + {{ if eq $options.hide_image false }} + <div class="media"> + {{- if .Params.image -}} + {{- partial "commons/image.html" + (dict + "image" .Params.image + "sizes" site.Params.image_sizes.sections.posts.item + ) -}} + {{- else -}} + {{- partial "commons/image-default.html" "posts" -}} + {{- end -}} + </div> + {{- end -}} </article> {{ end }} {{ end }} diff --git a/layouts/partials/blocks/templates/posts/list.html b/layouts/partials/blocks/templates/posts/list.html index 50ab8eb6..ef9714db 100644 --- a/layouts/partials/blocks/templates/posts/list.html +++ b/layouts/partials/blocks/templates/posts/list.html @@ -1,10 +1,14 @@ {{ $heading_level := .heading_level | default 3 }} {{ $heading := printf "h%d" $heading_level }} +{{ $alternate := .alternate }} +{{ $options := .options }} + <div class="list"> {{ range $post := .posts -}} {{ with site.GetPage (printf "/posts/%s" $post) }} {{ partial "posts/post.html" (dict "post" . + "options" $options "heading" $heading) }} {{ end }} {{ end }} diff --git a/layouts/partials/posts/post.html b/layouts/partials/posts/post.html index eb9f6614..3173d943 100644 --- a/layouts/partials/posts/post.html +++ b/layouts/partials/posts/post.html @@ -7,6 +7,11 @@ ) }} {{ $index := .index}} {{ $alternate := .alternate }} +{{- $show_image := (eq .options.hide_image false) -}} +{{- $show_summary := (eq .options.hide_summary false) -}} +{{- $show_category := (eq .options.hide_category false) -}} +{{- $show_author := (eq .options.hide_author false) -}} +{{- $show_date := (eq .options.hide_date false) -}} {{ with $post }} @@ -22,11 +27,11 @@ <a href="{{ .Permalink }}" title="{{ safeHTML (i18n "commons.more_aria" (dict "Title" $title)) }}">{{ $title }}</a> {{ $heading_tag.close }} - {{ if site.Params.posts.index.show_categories }} + {{ if and site.Params.posts.index.show_categories $show_category }} {{- partial "posts/categories" . -}} {{ end }} - {{ if site.Params.posts.index.show_description }} + {{ if and site.Params.posts.index.show_description $show_summary }} {{- if (partial "GetTextFromHTML" .Params.summary) -}} <p itemprop="articleBody">{{ partial "GetTruncateContent" ( dict "text" .Params.summary @@ -35,25 +40,31 @@ {{- end -}} {{- end -}} - <div class="post-meta"> - <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format site.Params.posts.date_format }}</time> - {{ if site.Params.posts.index.show_author }} - {{- partial "posts/author" . -}} - {{ end }} - </div> + {{ if or $show_author $show_date }} + <div class="post-meta"> + {{ if $show_date }} + <time itemprop="datePublished" datetime="{{ .Date.Format "2006-01-02T15:04" }}">{{ .Date | time.Format site.Params.posts.date_format }}</time> + {{ end }} + {{ if and site.Params.posts.index.show_author $show_author }} + {{- partial "posts/author" . -}} + {{ end }} + </div> + {{ end }} </div> - <div class="media"> - {{- if .Params.image -}} - {{- partial "commons/image.html" - (dict - "image" .Params.image - "sizes" site.Params.image_sizes.sections.posts.item - ) -}} - {{- else -}} - {{- partial "commons/image-default.html" "posts" -}} - {{- end -}} - </div> + {{ if $show_image }} + <div class="media"> + {{- if and .Params.image -}} + {{- partial "commons/image.html" + (dict + "image" .Params.image + "sizes" site.Params.image_sizes.sections.posts.item + ) -}} + {{- else -}} + {{- partial "commons/image-default.html" "posts" -}} + {{- end -}} + </div> + {{- end -}} </article> {{ end }} \ No newline at end of file -- GitLab