From 2a6bab6bd4a181f1c4cdd2c166a811899aea7776 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio" Date: Sat, 9 Mar 2024 10:12:57 -0300 Subject: documentation/themes: Refactor for Hugo 0.123.X compatibility - Simplify path extraction logic in menu partial to match only with the main document/book, enhancing maintainability and future Hugo compatibility. - Optimize articles and books directory listings by leveraging Hugo's built-in .Sections to fetch content, replacing manual slice construction and sorting logic. This approach streamlines the code and is more idiomatic with recent Hugo versions. - These changes are part of necessary adjustments for the upgrade to Hugo version 0.123.X, ensuring our theme's compatibility and taking advantage of Hugo's latest features and performance improvements. Reviewed by: fernape Differential Revision: https://reviews.freebsd.org/D44284 --- .../themes/beastie/layouts/partials/menu.html | 10 ++++++- .../shortcodes/list-articles-directories.html | 32 +++------------------ .../layouts/shortcodes/list-books-directories.html | 33 ++++------------------ 3 files changed, 18 insertions(+), 57 deletions(-) (limited to 'documentation') diff --git a/documentation/themes/beastie/layouts/partials/menu.html b/documentation/themes/beastie/layouts/partials/menu.html index 1b3ddf3b7d..e189abad53 100644 --- a/documentation/themes/beastie/layouts/partials/menu.html +++ b/documentation/themes/beastie/layouts/partials/menu.html @@ -1,4 +1,12 @@ -{{ with .Site.GetPage .Params.path }} +{{/* always extract the first part of the path to match it only with the main document/book. */}} +{{ $path := "" }} +{{ $regex := `^(\/[^\/]+\/[^\/]+)` }} +{{ $matches := findRE $regex .Params.path }} +{{ if gt (len $matches) 0 }} + {{ $path = index $matches 0 }} +{{ end }} + +{{ with .Site.GetPage $path }}