picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

Ignoring subdirectories while listing blog posts #578

Closed notakoder closed 3 years ago

notakoder commented 3 years ago

I list my posts inside the folder 'folder' using the following snippet.

{% if (page.id starts with "folder/") and not (page.id starts with "folder/subfolder")and not page.hidden %}

I do not want posts from inside subfolder to appear, so I blacklisted it. The problem is that every time I create a subfolder, I'd have to blacklist it manually. Is there a way blacklist all the sub directories inside folder 'folder' instead of doing it manually?

PhrozenByte commented 3 years ago

The if clause page.id starts with "folder/" should already exclude all pages within folder/subfolder :thinking:

Anyway, there are some ways to implement something like this:

  1. Use Pico's built-in hidden YAML meta header (i.e. a exclude list approach). Add hidden: true to all pages which shouldn't be listed there.
  2. Use a nav meta header (i.e. a include list approach). Simply add nav: true to all pages which should appear in your nav bar and use a if clause like {{ if page.meta.nav }} in your Twig template.
  3. Use a different directory structure. Pico's default nav bar (https://github.com/picocms/pico-theme/blob/master/index.twig#L46-L50) includes pages of the first level (i.e. content/page.md and content/sub/index.md, but not content/sub/page.md) only. You can easily modify this to also include pages
  4. Add a exclude- or include-list to your config.yml (like nav_exclude: [ "folder/", "other_folder" ]) and use a appropriate if clause in your Twig templates, e.g. {{ if page.id in config.nav_include }} (include list) or {{ if page.id not in config.nav_exclude }} (exclude list)
notakoder commented 3 years ago

Thanks...