Hi, I would like to automatically add a nav item whenever a page is published. Right now, I have a page and config collection. In order to show a page in the navigation, I need to first create the page, and then go to config to create a navigation item with the same title and link. Is there a way, perhaps in the config.yml, to streamline this process?
Hi @a772bNsz!
Are you using a static site generator to build your site? If so you could read the _pages directory during the build process and generate the nav items dynamically, without needing an additional Config collection.
I’m actually not that familiar with Jekyll…You might have better results reaching out in one of the options here Support | Jekyll • Simple, blog-aware, static sites, or wait for a more experienced Jekyll user to respond.
The snippet is getting all the pages in the folder _pages with site.pages. Then looping through, creating each of the nav items, assigning the “active” class to the list item representing the active page.
What if you want to hide certain pages?
# _posts/about.md
---
layout: page
title: About
show: False
---
I added a custom Boolean variable in the front matter. Then I revised navigation.html to check if the show variable is set to true
# changed navigation.html
<ul>
{% assign _pages = site.pages | sort: "order" %}
{% for pg in _pages %}
{% if {{pg.show}} == true %} # <------Right Here
<li><a href="{{pg.url}}" {% if {{pg.url}} == {{page.url}} %} class="active" {% endif %}>{{ pg.title }}</a></li>
{% endif %}
{% endfor %}
</ul>