Building a navigation / menu #718
sagikazarmark
started this conversation in
General
Replies: 3 comments 6 replies
-
|
For the record: I tried comparing URLs, but that's not 100% accurate solution (eg. trailing slashes can cause trouble). |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Okay, here is the latest version: menu:
- page: now
- title: Slides
url: https://slides.sagikazarmark.hu {{- for entry of menu }}
{{- if entry.page }}
{{ set page = search.page("basename="+entry.page) }}
<a href="{{ page.url |> url(true) }}" class="text-gray-600 hover:text-gray-900 {{ if page.url == url }} font-semibold{{ else }} font-medium{{ /if }}" {{ if page.url == url }} aria-current="page"{{ /if }}>
{{ entry.title || page.title }}
</a>
{{ else }}
<a href="{{ entry.url }}" class="text-gray-600 hover:text-gray-900 font-medium">
{{ entry.title }}
</a>
{{ /if }}
{{ /for }}Basically, I can search pages based on basename and compare those URLs to the current URL. |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
@oscarotero any ideas how I could make this work for paginated pages? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to replicate something similar to Hugo's menu feature.
I got started by writing a menu in shared data:
I'm having trouble figuring out the current page. I know I can hack around with the
urlvariable, but that's kinda hacky.I also tried using the search plugin, but I can't seem to find a way to search a page by a URL.
Are there any examples out there?
Beta Was this translation helpful? Give feedback.
All reactions