Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav link does not turn active for single pages. #148

Open
gwo0d opened this issue Jan 11, 2021 · 7 comments
Open

Nav link does not turn active for single pages. #148

gwo0d opened this issue Jan 11, 2021 · 7 comments

Comments

@gwo0d
Copy link

gwo0d commented Jan 11, 2021

The link in the nav bar does not become active when on single pages, only on list and blog pages.

Example: uni.gwood.dev - the About page.

@rbnis
Copy link
Contributor

rbnis commented Jan 11, 2021

Hi,

first thing that jumps to my head is, do you have set the identifier in the menu section of your config?
If not, this should be your problem. When using a .toml file, the manu entry should look something like this:

[[menu.main]]
  identifier = "about"
  name = "About"
  url = "/about"

If this shloudn't fix your problem, could you please paste your config?

@gwo0d
Copy link
Author

gwo0d commented Jan 11, 2021

Hi there, I don't think that's it - this is my current entry:

[[menu.main]]
  identifier = "about"
  name = "About"
  title = "About"
  url = "/about"
  weight = 20

Thanks!

@rbnis
Copy link
Contributor

rbnis commented Jan 11, 2021

Ahh I see the problem. I have played around with it a bit and found a low effort fix.

Under content you can create another directory called about and move your about.md there. But you have to rename it to _index.md. You don't even have to change your config.

It's not the best way to do things but it will get the job done.

I'll see if I can get a better fix for this.

@gwo0d
Copy link
Author

gwo0d commented Jan 11, 2021

That works absolutely perfectly.

Thanks!

@gwo0d
Copy link
Author

gwo0d commented Jan 11, 2021

Oh actually, now the menu is working but my about page is showing up like this...
image

@rbnis
Copy link
Contributor

rbnis commented Jan 11, 2021

I think I have found another solution.

Given your about page is at content/about.md you can add the following to the frontmatter of that page:

---
...
menu:
  main:
    identifier: about
---

The menu entrie can stay the same as above.

I hope this helps you out.

// Edit:
Ahh wait, you also need to overwrite the nav.htmlwith this:

<nav class="nav" id="navigation">
  <ul class="nav__list">
    {{ $currentPage := . }}
    {{ range .Site.Menus.main }}
      <li>
        <a {{ if or ($currentPage.IsMenuCurrent "main" .) ( and (eq $currentPage.Kind "section") (eq $currentPage.Section .Identifier)) }} class="active"
        {{end}} href="{{ .URL }}">{{ .Name }}</a>
      </li>
    {{ end }}
  </ul>
</nav>

@frauseo
Copy link

frauseo commented Jan 27, 2021

If i Follow your last post i get a WARNING message:
WARN 2021/01/27 10:52:39 "/home/fr/Workspace/homepage/r4o/content/about.md:1:1": duplicate menu entry with identifier "about" in menu "main"

is there a more elegant solution to this Problem?

lzlrd added a commit to lzlrd/hugo-theme-codex that referenced this issue Jul 7, 2022
This resolves jakewies#148 and
also supports multilingual sites.

Signed-off-by: Diab Neiroukh <[email protected]>
lzlrd added a commit to lzlrd/hugo-theme-codex that referenced this issue Jul 7, 2022
This resolves jakewies#148 and
also supports multilingual sites.

Signed-off-by: Diab Neiroukh <[email protected]>
lzlrd added a commit to lzlrd/hugo-theme-codex that referenced this issue Apr 10, 2024
This resolves jakewies#148 and
also supports multilingual sites.

Signed-off-by: Diab Neiroukh <[email protected]>
lzlrd added a commit to lzlrd/hugo-theme-codex that referenced this issue Apr 10, 2024
This resolves jakewies#148 and
also supports multilingual sites.

Signed-off-by: Diab Neiroukh <[email protected]>
lzlrd added a commit to lzlrd/hugo-theme-codex that referenced this issue Apr 10, 2024
This resolves jakewies#148 and
also supports multilingual sites.

Signed-off-by: Diab Neiroukh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants