From 30aeb6578ef6b46561f2d2ce259a5f73666f8a98 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 28 Jan 2025 16:02:07 +0100 Subject: [PATCH] feat: Add bulma navbar --- themes/animals/assets/js/main.js | 23 +++++- themes/animals/layouts/partials/head.html | 1 + themes/animals/layouts/partials/header.html | 3 +- themes/animals/layouts/partials/menu.html | 82 ++++++++++++--------- 4 files changed, 72 insertions(+), 37 deletions(-) diff --git a/themes/animals/assets/js/main.js b/themes/animals/assets/js/main.js index e2aac52..842298c 100644 --- a/themes/animals/assets/js/main.js +++ b/themes/animals/assets/js/main.js @@ -1 +1,22 @@ -console.log('This site was generated by Hugo.'); +// Add is-active to burger menu +document.addEventListener('DOMContentLoaded', () => { + + // Get all "navbar-burger" elements + const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); + + // Add a click event on each of them + $navbarBurgers.forEach(el => { + el.addEventListener('click', () => { + + // Get the target from the "data-target" attribute + const target = el.dataset.target; + const $target = document.getElementById(target); + + // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" + el.classList.toggle('is-active'); + $target.classList.toggle('is-active'); + + }); + }); + +}); diff --git a/themes/animals/layouts/partials/head.html b/themes/animals/layouts/partials/head.html index 8601c59..0f8a889 100644 --- a/themes/animals/layouts/partials/head.html +++ b/themes/animals/layouts/partials/head.html @@ -1,6 +1,7 @@ + {{ if .IsHome }}{{ site.Title }}{{ else }}{{ printf "%s | %s" .Title site.Title }}{{ end }} {{ partialCached "head/css.html" . }} {{ partialCached "head/js.html" . }} diff --git a/themes/animals/layouts/partials/header.html b/themes/animals/layouts/partials/header.html index 7980a00..6488e90 100644 --- a/themes/animals/layouts/partials/header.html +++ b/themes/animals/layouts/partials/header.html @@ -1,2 +1 @@ -

{{ site.Title }}

-{{ partial "menu.html" (dict "menuID" "main" "page" .) }} +{{ partial "menu.html" (dict "menuID" "main" "page" .) }} \ No newline at end of file diff --git a/themes/animals/layouts/partials/menu.html b/themes/animals/layouts/partials/menu.html index 7183180..c2752f1 100644 --- a/themes/animals/layouts/partials/menu.html +++ b/themes/animals/layouts/partials/menu.html @@ -11,41 +11,55 @@ Renders a menu for the given menu ID. {{- $menuID := .menuID }} {{- with index site.Menus $menuID }} - + {{- end }} {{- define "partials/inline/menu/walk.html" }} - {{- $page := .page }} - {{- range .menuEntries }} - {{- $attrs := dict "href" .URL }} - {{- if $page.IsMenuCurrent .Menu . }} - {{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }} - {{- else if $page.HasMenuCurrent .Menu .}} - {{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }} - {{- end }} - {{- $name := .Name }} - {{- with .Identifier }} - {{- with T . }} - {{- $name = . }} - {{- end }} - {{- end }} -
  • - {{ $name }} - {{- with .Children }} - - {{- end }} -
  • - {{- end }} +{{- $page := .page }} +{{- range .menuEntries }} +{{- $attrs := dict "href" .URL }} +{{- if $page.IsMenuCurrent .Menu . }} +{{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }} +{{- else if $page.HasMenuCurrent .Menu .}} +{{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }} +{{- end }} +{{- $name := .Name }} +{{- with .Identifier }} +{{- with T . }} +{{- $name = . }} +{{- end }} +{{- end }} + +{{- end }} {{- end }}