Skip to content

navigation #5

@pekeler

Description

@pekeler

In my <nav> section, I'd like to indicate the current page. Currently I'm doing this by specifying a file in my frontmatter:

{
  "title": "Foo",
  "file": "foo"
}

---

And using file with a bit of JavaScript in my layout:

<nav>
  <ul>
    <a href='foo.html'><li>Foo</li></a>
    <a href='bar.html'><li>Bar</li></a>
    <a href='baz.html'><li>Baz</li></a>
  </ul>
</nav>
<script>
  document.querySelector('nav a[href="{{file}}.html"]').classList.add('active');
</script>

I wonder if there could be an easier way to deal with this that doesn't require any JavaScript.

Maybe using mustache instead of hairlip and automatically setting fileNames and currentFileName would allow for an elegant solution. But perhaps that's not super-simple anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions