From fdfdef69b57d0fd96896addd286b2ef964d68289 Mon Sep 17 00:00:00 2001 From: Xin Date: Fri, 5 Apr 2024 21:30:24 +0100 Subject: [PATCH] chore: basic structure using new sidebar data --- .../{read-data.html => get-section-data.html} | 10 +++--- layouts/partials/sidebar-ng.html | 33 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) rename layouts/partials/components/sidebar/{read-data.html => get-section-data.html} (56%) diff --git a/layouts/partials/components/sidebar/read-data.html b/layouts/partials/components/sidebar/get-section-data.html similarity index 56% rename from layouts/partials/components/sidebar/read-data.html rename to layouts/partials/components/sidebar/get-section-data.html index 86592e0..a93bad0 100644 --- a/layouts/partials/components/sidebar/read-data.html +++ b/layouts/partials/components/sidebar/get-section-data.html @@ -1,18 +1,18 @@ -{{/* - Get sidebar config from Hugo `data` directory +{{/* Get section sidebar config from Hugo `data` directory If the site is multilingual, the sidebar data is stored in a language-specific directory. For example, the English sidebar data is stored in `data/en/sidebar.yaml`. */}} - {{ $data := "" }} +{{ $section := .Section | default "" }} +{{ $sidebarKey := "sidebar" }} {{ if hugo.IsMultilingual }} - {{ with (index site.Data site.Language.Lang "sidebar") }} + {{ with (index site.Data site.Language.Lang $sidebarKey $section) }} {{ $data = . }} {{ end }} {{ else }} - {{ with (index site.Data "sidebar") }} + {{ with (index site.Data $sidebarKey $section) }} {{ $data = . }} {{ end }} {{ end }} diff --git a/layouts/partials/sidebar-ng.html b/layouts/partials/sidebar-ng.html index e695a32..0859002 100644 --- a/layouts/partials/sidebar-ng.html +++ b/layouts/partials/sidebar-ng.html @@ -8,34 +8,31 @@ {{- $navRoot := cond (eq site.Home.Type "docs") site.Home $context.FirstSection -}} {{- $pageURL := $context.RelPermalink -}} -{{ $data := partialCached "components/sidebar/read-data" $context $context.FirstSection }} +{{ $data := partialCached "components/sidebar/get-section-data" $context $context.Section }} -