feat(currentMenuItem.html): add template partial to retrieve the current menu item based on the current page URL

The currentMenuItem.html template partial is added to the layouts/partials/function directory. This partial is used to retrieve the current menu item based on the current page URL. It iterates through the main menu items defined in the site configuration and compares the URL of each menu item with the URL of the current page. If a match is found, the name and ID of the menu item are stored in variables. Finally, a dictionary containing the name and ID is returned. This partial can be used to highlight the current menu item in the navigation menu.
This commit is contained in:
Sped0n
2023-10-30 15:57:32 +08:00
parent 1632803e91
commit a74f15b908

View File

@@ -0,0 +1,15 @@
{{- $currentPage := . -}}
{{- $name := "" -}}
{{- $id := -1 -}}
{{- range site.Menus.main -}}
{{ $menu_item_url := .URL | relLangURL }}
{{ $page_url:= $currentPage.RelPermalink | relLangURL }}
{{ if eq $menu_item_url $page_url }}
{{- $name = .Identifier -}}
{{- $id = .Weight -}}
{{- end -}}
{{- end -}}
{{- return (dict "Name" $name "ID" $id) -}}