Controlling what counts as a page/post

Hi everyone, I’m new to the Jekyll forum so please let me know if I’ve done something incorrectly with formatting/structure of my post : )

I’m getting started with my blog and have been working on setting up a top navigation bar for the site. I learnt how to use Liquid to iterate over the pages and posts on my site, and this works great for finding every page I would like to list! However, I’m finding that I also end up with links to things I don’t want to count, like the feed.xml file created for setting up the rss feed and a css file on my site.

Below is my code which is finding the pages:

I’ve been trying to find information on this elsewhere on the forum and I think this is happening because Jekyll treats these files as having empty frontmatter, so they are given the ‘post’ type. Is there a way I can prevent this from happening?

I would like a solution that doesn’t involve fiddling with my project heirarchy if possible, the .xml is created when building the site so I think having it be visible to Liquid code is expected behaviour. Rewriting my css file in sass would probably hide this particular file, but I can imagine running into this issue with future files and would like to be able to handle it then. If it’s just poor practice to iterate over pages/posts that would be an acceptable answer too.

How is this xml file created? Jekyll comes with sass support, so you should use it. For rss I use jekyll-feed, so I don’t have this kind of problem.

Now, it is weird for jekyll to list these files under site.pages or site.posts. Any file without front matter is listed via site.static_files. Are you using any front matter in these files?

One possible solution for your specific case (that shouldn’t be happening I think) is to check for if the file extension is not one that it shouldn’t. You can get the file extension with {% assign ext = page.path | split: "." | last %}.

Jekyll’s default theme Minima has an automatically populated <nav> element. It only displays pages from site.pages that have a title field – that presumably filters out untitled RSS, CSS, etc. pages. Here’s the code: minima/_includes/header.html at master · jekyll/minima · GitHub