2
votes

I am using Jekyll to generate a static website. I currently display posts by category on their own pages using some simple liquid syntax:

{%- for post in site.categories.whatever -%}
    {{ post.content }}
{%- endfor -%}

However, the posts are still generated independently (in /category/year/month/day/title.html per the Jekyll defaults), which I don't need.

How can I prevent each post from generating its own independent HTML page while still being able to loop over site.categories and include them in a page with multiple posts? Setting published: false unfortunately prevents the posts from being added to site.categories, which breaks the above for loop. permalink: none also has no apparent effect. Excluding the pages (via exclude: [xyzzy, plugh, ...] in _config.yml) does the same. A previous StackOverflow answer suggested setting the permalink to an existing page, but in Jekyll 3.6.2 this simply overwrites that page.

My current hack is to set the permalink for that category to /.trash which is then easy to ignore when uploading the published site, but it seems like there ought to be a better way.

1
You could use another collection with output false, or does that not work for you?JoostS
Unfortunately, I'd like to have some of the other benefits posts offer :/ But you're right, a collection would be one alternative.Kyle Barbour
Specifically, collections currently can't use Liquid, and it's easier to generate RSS from posts.Kyle Barbour
I have build dozens of Jekyll sites and not experienced these limitations.JoostS

1 Answers

0
votes

It seems that simply setting the permalink to the empty string (mostly) works! With

defaults:
  - scope:
        path:       category/_posts
    values:
        permalink:  ''

in your _config.yml, none of those posts will have a generated page.

Unfortunately, the pages are still included in site.documents and similar pages, but at least it suppresses the output. I sadly think that it's not possible to exclude these from site.documents, but it's easy enough to avoid them in Liquid.