Skip to content

Commit

Permalink
Add collapsible top menu
Browse files Browse the repository at this point in the history
  • Loading branch information
yanirs committed Jan 16, 2024
1 parent c57d802 commit dfe1b55
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 16 deletions.
7 changes: 1 addition & 6 deletions assets/css/extended/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ header.header .logo a {

header.header .nav {
flex-wrap: unset;
line-height: 1;
line-height: 1.4;
text-align: center;
}

header.header #menu {
margin-left: 0;
overflow-x: unset;
}

header.header button#theme-toggle {
font-size: 22px;
margin: auto 12px;
Expand Down
66 changes: 66 additions & 0 deletions assets/css/extended/menu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Hamburger menu, adapted from
https://github.com/jesse-wei/jessewei.dev-PaperMod/commit/9d74c542e64699557cda562edacacccc700cd3c8
*/

#menu-trigger {
display: none;
}

.menu {
display: flex;
margin: auto var(--gap);
list-style: none;
word-break: keep-all;
overflow-x: auto;
white-space: nowrap;
}

.menu li+li {
margin-inline-start: var(--gap);
}

.menu a {
font-size: 16px;
}

.menu .active {
font-weight: 500;
border-bottom: 2px solid currentColor;
}

@media screen and (max-width: 768px) {
.menu {
list-style: none;
position: absolute;
right: 0;
z-index: 5;
padding: var(--gap);
background: var(--code-bg);
border-radius: var(--radius);
border: 2px solid var(--tertiary);
line-height: 2.5;
margin: calc(var(--header-height) - var(--gap)) var(--gap);
display: block;
}

.list .menu {
background: var(--entry);
}

.menu li+li {
margin-inline-start: 0;
}

#menu-trigger {
font-size: 30px;
position: relative;
display: block;
float: right;
margin: auto var(--gap);
}

.menu.hidden {
display: none;
}
}
9 changes: 6 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ menu:
- name: About
url: /about/
weight: 1
- name: Posts
url: /posts/
weight: 2
- name: Talks
url: /talks/
weight: 2
- name: Consult
url: /consult/
weight: 3
- name: Consulting
url: /consult/
weight: 4

params:
analytics:
Expand Down
24 changes: 19 additions & 5 deletions layouts/partials/extend_footer.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="mailing-list-container">
<form
class="mailing-list"
action="https://yanirseroussi.us17.list-manage.com/subscribe/post?u=3c08aa3ff27dd92978019febd&amp;id=bc3ab705af"
method="post"
target="_blank"
novalidate
class="mailing-list"
action="https://yanirseroussi.us17.list-manage.com/subscribe/post?u=3c08aa3ff27dd92978019febd&amp;id=bc3ab705af"
method="post"
target="_blank"
novalidate
>
<label for="mailing-list-email">Get new posts in your mailbox</label>
<input type="text" name="EMAIL" id="mailing-list-email" placeholder="Email address" />
Expand All @@ -27,3 +27,17 @@
</span>
</div>
</div>

<script>
const menuTrigger = document.querySelector("#menu-trigger");
const menuElem = document.querySelector(".menu");
menuTrigger.addEventListener("click", function () {
menuElem.classList.toggle("hidden");
});
// hide menu when clicked outside
document.body.addEventListener('click', function (event) {
if (!menuTrigger.contains(event.target)) {
menuElem.classList.add("hidden");
}
});
</script>
10 changes: 8 additions & 2 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@
</div>
</div>
{{- $currentPage := . }}
<ul id="menu">
<button id="menu-trigger" aria-haspopup="menu" aria-label="Menu Button">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</button>
<ul class="menu hidden">
{{- range site.Menus.main }}
{{- $menu_item_url := (cond (strings.HasSuffix .URL "/") .URL (printf "%s/" .URL) ) | absLangURL }}
{{- $page_url:= $currentPage.Permalink | absLangURL }}
Expand All @@ -144,7 +151,6 @@
</a>
</li>
{{- end }}
<!-- Hack to work around limitation with linking to #/ and opening in a new tab. -->
</ul>
</nav>
</header>

0 comments on commit dfe1b55

Please sign in to comment.