From b3b0f5a4af058ec0c617ab22de4495713bcd8f2b Mon Sep 17 00:00:00 2001 From: alexisben <alex@noesya.coop> Date: Tue, 20 Dec 2022 15:59:54 +0100 Subject: [PATCH] fix page toc --- .../sass/_theme/design-system/pagination.sass | 2 +- layouts/pages/list.html | 36 +++++-- layouts/partials/pages/toc.html | 93 ++++++------------- 3 files changed, 60 insertions(+), 71 deletions(-) diff --git a/assets/sass/_theme/design-system/pagination.sass b/assets/sass/_theme/design-system/pagination.sass index f675dedd..f2899634 100644 --- a/assets/sass/_theme/design-system/pagination.sass +++ b/assets/sass/_theme/design-system/pagination.sass @@ -38,7 +38,7 @@ .posts-navigation border-top: 1px solid $color-border margin-top: $spacing3 - margin-bottom: $spacing4 + padding-bottom: $spacing4 ul @include list-reset display: flex diff --git a/layouts/pages/list.html b/layouts/pages/list.html index 919a013a..3a0bf4f3 100644 --- a/layouts/pages/list.html +++ b/layouts/pages/list.html @@ -5,13 +5,35 @@ {{/* TOC PART */}} {{- $category := site.GetPage (printf "/categories%s" .Params.category) -}} - {{- if .Params.blocks }} - {{ $need_aside := false }} - {{ range .Params.blocks }} - {{ if .title }} - {{ $need_aside = true }} - {{ end }} - {{ end }} + {{- $show_aside := false -}} + + {{- $has_blocks := false -}} + {{- range .Params.blocks -}} + {{- $has_blocks = true -}} + {{- if .title -}} + {{- $show_aside = true -}} + {{- end -}} + {{- end -}} + + {{- if .Pages -}} + {{- if eq $has_blocks false -}} + {{- $show_aside = true -}} + {{- end -}} + {{- end -}} + + {{- if .Content -}} + {{- if eq $has_blocks false -}} + {{- $show_aside = true -}} + {{- end -}} + {{- end -}} + + {{- if $category -}} + {{- if eq $has_blocks false -}} + {{- $show_aside = true -}} + {{- end -}} + {{- end -}} + + {{- if $show_aside }} {{ partial "toc/container.html" (dict "category" $category diff --git a/layouts/partials/pages/toc.html b/layouts/partials/pages/toc.html index 581af884..41e837c2 100644 --- a/layouts/partials/pages/toc.html +++ b/layouts/partials/pages/toc.html @@ -1,73 +1,40 @@ -{{- $show_aside := false -}} +<nav class="toc toc-pages" id="nav-toc" aria-labelledby="toc-title"> + <ol> -{{- $has_blocks := false -}} -{{- range .context.Params.blocks -}} - {{- $has_blocks = true -}} - {{- if .title -}} - {{- $show_aside = true -}} - {{- end -}} -{{- end -}} + {{- if .context.Params.blocks -}} -{{- if .context.Pages -}} - {{- if eq $has_blocks false -}} - {{- $show_aside = true -}} - {{- end -}} -{{- end -}} + {{- partial "blocks/toc.html" .context.Params.blocks -}} -{{- if .context.Content -}} - {{- if eq $has_blocks false -}} - {{- $show_aside = true -}} - {{- end -}} -{{- end -}} + {{- else -}} -{{- if .category -}} - {{- if eq $has_blocks false -}} - {{- $show_aside = true -}} - {{- end -}} -{{- end -}} + {{/* TODO: Delete it */}} + {{ $h2s := partial "H2Extract" .context.Content }} + {{- if and (not $h2s) (partial "GetTextFromHTML" .context.Content) }} + <li> + <a href="#page-informations">{{ i18n "pages.informations" }}</a> + </li> + {{ end -}} -{{- if $show_aside }} - <nav class="toc toc-pages" id="nav-toc" aria-labelledby="toc-title"> - <ol> + {{- range $index, $h2 := $h2s }} + <li> + <a href="#page-h2-{{$index}}">{{ plainify $h2 }}</a> + </li> + {{ end -}} - {{- if .context.Params.blocks -}} + {{- if .context.Pages }} + <li> + <a href="#page-children">{{ i18n "pages.details" }}</a> + </li> + {{ end -}} - {{- partial "blocks/toc.html" .context.Params.blocks -}} + {{- if .category.Pages }} + <li> + <a href="#page-posts">{{ i18n "pages.posts" }}</a> + </li> + {{ end -}} - {{- else -}} - - {{/* TODO: Delete it */}} - {{ $h2s := partial "H2Extract" .context.Content }} - {{- if and (not $h2s) (partial "GetTextFromHTML" .context.Content) }} - <li> - <a href="#page-informations">{{ i18n "pages.informations" }}</a> - </li> - {{ end -}} - - {{- range $index, $h2 := $h2s }} - <li> - <a href="#page-h2-{{$index}}">{{ plainify $h2 }}</a> - </li> - {{ end -}} - - {{- if .context.Pages }} - <li> - <a href="#page-children">{{ i18n "pages.details" }}</a> - </li> - {{ end -}} - - {{- if .category.Pages }} - <li> - <a href="#page-posts">{{ i18n "pages.posts" }}</a> - </li> - {{ end -}} - - {{- end -}} - - </ol> - - </nav> - -{{ end -}} + {{- end -}} + </ol> +</nav> -- GitLab