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

navigation #5

Open
pekeler opened this issue Jun 30, 2015 · 1 comment
Open

navigation #5

pekeler opened this issue Jun 30, 2015 · 1 comment

Comments

@pekeler
Copy link
Contributor

pekeler commented Jun 30, 2015

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.

@pekeler
Copy link
Contributor Author

pekeler commented Jul 1, 2015

A small improvement that doesn't require the file in the frontmatter anymore:

<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="' + location.pathname.split('/').reverse()[0] + '"]').classList.add('active');
</script>

but still needs some JS...

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

1 participant