From 74fb165358319f8315f542e2ee066737bc08583c Mon Sep 17 00:00:00 2001 From: Xin Date: Wed, 3 Apr 2024 22:36:58 +0000 Subject: [PATCH] feat: sidebar util to read data --- .../components/sidebar/read-data.html | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 layouts/partials/components/sidebar/read-data.html diff --git a/layouts/partials/components/sidebar/read-data.html b/layouts/partials/components/sidebar/read-data.html new file mode 100644 index 0000000..86592e0 --- /dev/null +++ b/layouts/partials/components/sidebar/read-data.html @@ -0,0 +1,20 @@ +{{/* + Get 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 := "" }} + +{{ if hugo.IsMultilingual }} + {{ with (index site.Data site.Language.Lang "sidebar") }} + {{ $data = . }} + {{ end }} +{{ else }} + {{ with (index site.Data "sidebar") }} + {{ $data = . }} + {{ end }} +{{ end }} + +{{ return $data }}