Remove directory from category structure

I have the following directory structure:

dir1
  --dir2
    --dir3
      --_posts

the blog.md page is in dir3, referencing posts in _posts.
If I display {{ post.categories }} in a post, I get dir1, dir2, dir3, as well as the posts’s categories.
I want only the explicitly given categories, i.e. to always exclude dir1, dir2, dir3, or at least dir2, in as generic a way as possible (i.e. without explicitly writing the directory name in).

Is this possible. If I do create subfolders, e.g dir4 in dir3, then I want dir4 to show.

Thanks in advance…

Currently, it is not possible to exclude super-directories of _posts from being considered as categories of the post.

1 Like

I did some testing now.

Using outer directory

foo/bar/bazz/_posts/2021-01-02.md

Results in the output path and categories including foo, bar, bazz.

But, if you use inner directory for path structure:

_posts/foo/bar/bazz/2021-01-02-abc.md

Then the output path is foo/bar/bazz/2021/01/02/abc.html but page.categories does not include anything set by the directory.

And you can of course put that entire thing in a directory to give it category or use

categories: fuzz

To set page.categories and the output to include fuzz.

Thanks for both replies. @MIchaelCurrin interesting idea, but not suitable for my particular use case. @ashmaroli oh, well. thanks for answering directly… I guess I’ll have to stick with tags.

2 Likes