aboutsummaryrefslogtreecommitdiff
path: root/documentation
diff options
context:
space:
mode:
authorDanilo G. Baio <dbaio@FreeBSD.org>2024-03-09 13:12:57 +0000
committerDanilo G. Baio <dbaio@FreeBSD.org>2024-03-23 17:50:54 +0000
commit2a6bab6bd4a181f1c4cdd2c166a811899aea7776 (patch)
tree8ff243798eeba7745cc36a2736ef1c8fa6e664e8 /documentation
parent6b0d45db9e38dbdbe0fa047bd7cdf15efc185909 (diff)
downloaddoc-2a6bab6bd4a181f1c4cdd2c166a811899aea7776.tar.gz
doc-2a6bab6bd4a181f1c4cdd2c166a811899aea7776.zip
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
Diffstat (limited to 'documentation')
-rw-r--r--documentation/themes/beastie/layouts/partials/menu.html10
-rw-r--r--documentation/themes/beastie/layouts/shortcodes/list-articles-directories.html32
-rw-r--r--documentation/themes/beastie/layouts/shortcodes/list-books-directories.html33
3 files changed, 18 insertions, 57 deletions
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 }}
<ul>
{{ range .Pages }}
<li>
diff --git a/documentation/themes/beastie/layouts/shortcodes/list-articles-directories.html b/documentation/themes/beastie/layouts/shortcodes/list-articles-directories.html
index 843300d4aa..33eab8f495 100644
--- a/documentation/themes/beastie/layouts/shortcodes/list-articles-directories.html
+++ b/documentation/themes/beastie/layouts/shortcodes/list-articles-directories.html
@@ -1,14 +1,3 @@
-{{ $articles := slice}}
-
-{{ range where .Site.Pages "Section" "articles" }}
- {{ with .File }}
- {{ $subDirsNumer := .File.Path | strings.Count "/" }}
- {{ if eq $subDirsNumer 2 }}
- {{ $articles = $articles | append (dict "page" . "path" .File.Path) }}
- {{ end }}
- {{ end }}
-{{ end }}
-
{{ partial "global-search.html" . }}
<h1>{{ i18n "articles" }}</h1>
@@ -17,25 +6,12 @@
<hr class="line"/>
-{{ $articles := slice}}
-
-{{ range where .Site.Pages "Section" "articles" }}
- {{ $subDirsNumer := .File.Path | strings.Count "/" }}
- {{ if eq $subDirsNumer 2 }}
- {{ $articles = $articles | append (dict "page" . "path" .File.Path) }}
- {{ end }}
-{{ end }}
-
<ul class="documents-list">
-{{ range sort $articles "weight" "path" }}
- {{ if in .path "_index.adoc" }}
- {{ $articlePath := replaceRE "/_index.adoc" "" .path }}
- {{ $articlePath = replaceRE "articles/" "" $articlePath }}
- {{ $articleName := replaceRE "articles/" "" $articlePath }}
+{{ $articles := .Site.GetPage "section" "articles" }}
+{{ range $articles.Sections }}
<li>
- <a href="{{ $articlePath }}"><strong>{{ .page.Title }}</strong></a>
- <p>{{ .page.Params.description }}</p>
+ <a href="{{ .Permalink }}"><strong>{{ .Title }}</strong></a>
+ <p>{{ .Params.description }}</p>
</li>
- {{ end }}
{{ end }}
</ul>
diff --git a/documentation/themes/beastie/layouts/shortcodes/list-books-directories.html b/documentation/themes/beastie/layouts/shortcodes/list-books-directories.html
index 10df5da34c..d98353f942 100644
--- a/documentation/themes/beastie/layouts/shortcodes/list-books-directories.html
+++ b/documentation/themes/beastie/layouts/shortcodes/list-books-directories.html
@@ -1,14 +1,3 @@
-{{ $books := slice}}
-
-{{ range where .Site.Pages "Section" "books" }}
- {{ with .File }}
- {{ $subDirsNumer := .File.Path | strings.Count "/" }}
- {{ if eq $subDirsNumer 2 }}
- {{ $books = $books | append (dict "page" . "path" .File.Path) }}
- {{ end }}
- {{ end }}
-{{ end }}
-
{{ partial "global-search.html" . }}
<h1>{{ i18n "books" }}</h1>
@@ -17,25 +6,13 @@
<hr class="line"/>
-{{ $books := slice}}
-
-{{ range where .Site.Pages "Section" "books" }}
- {{ $subDirsNumer := .File.Path | strings.Count "/" }}
- {{ if eq $subDirsNumer 2 }}
- {{ $books = $books | append (dict "page" . "path" .File.Path) }}
- {{ end }}
-{{ end }}
-
<ul class="documents-list">
-{{ range sort $books "bookOrder" "path" }}
- {{ if in .path "_index.adoc" }}
- {{ $bookPath := replaceRE "/_index.adoc" "" .path }}
- {{ $bookPath = replaceRE "books/" "" $bookPath }}
- {{ $articleName := replaceRE "books/" "" $bookPath }}
+
+{{ $books := .Site.GetPage "section" "books" }}
+{{ range $books.Sections }}
<li>
- <a href="{{ $bookPath }}"><strong>{{ .page.Title }}</strong></a>
- <p>{{ .page.Params.description }}</p>
+ <a href="{{ .Permalink }}"><strong>{{ .Title }}</strong></a>
+ <p>{{ .Params.description }}</p>
</li>
- {{ end }}
{{ end }}
</ul>