New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to paginate a collection? #58
Comments
Hi @johnlane, Here are some adjusted snippets from my collections:
stuff:
output: true
permalink: /stuff/:path/
autopages:
enabled: true
# ... etc.
collections:
permalink: /:coll/
enabled: true
pagination:
# ... etc. You could copy |
Thank you @ibrado that helps. I didn't make the connection between autopages and paginating collections. I thought paginating a collection would work like it does for I have my I have it partially working now. The collection's front page, However I would like to include some material on the index page of the collection - ideally on the first page but, at a worse case, it could appear on all pages. But this material needs to be collection-specific - I don't know how to do that without the Is it possible to make a paginated collection work the same way as |
@johnlane Do you mean a separate collection index (which may have additional content, then lists/links to other entries), or something like a pinned post that appears as the first entry in your paginated collection? |
I mean a page that has some content on it as well as the paginated index - so an
where the
What that gives me is whatever is in |
I'm afraid I don't have any direct solutions... @sverrirs..? I do have a couple sub-optimal solutions... The first is so hacky that I don't think it's the proper way to do it. I have a feeling I'll be laughing my head off for missing something basic. It can't handle front-matter in ---
layout: page
---
{% unless paginator.previous_page %}
{% assign collection = paginator.posts[0].collection %}
{% capture my_index_file %}_{{collection}}/index.md{% endcapture %}
{% if collection != "posts" %}
{% capture my_index %}{% include_relative {{my_index_file}} %}{% endcapture %}
{{ my_index | markdownify }}
{% endif %}
{% endunless %}
# ... Usual pagination stuff goes here... My other solution involves using my StickyPosts plugin. You'd set |
Currently if you want custom content on auto pages then you need to either have:
This actually sounds like a feature that is missing from the autopages at the moment (inclusion of some piece of text/html at the top of the pagination. If you feel up to making the feature I'll accept a PR. |
I seem to remember while trying this out that |
I actually have a partial solution to this... For collections, you'd just drop an "intro.md" (configurable) into the collection's folder, and it would get rendered at the top of the AutoPage (via |
Hi @ibrado that sounds good. So to get some text content on the index page of I'd like to try that... I presume I need some development branch for this? |
Yes, that's how you'd do it... it's also a full render (not just text) so you can use Liquid and Markdown. I just pushed it onto my fork for you; some feedback would be good... Gemfile (don't forget to run
You'd need to put something like the ff in your _config.yml: pagination:
intro: 'intro.md' Then in your autopage_collection.html, add a {{ paginator.intro }}
{% for post in paginator.posts %}
...
{% endfor %} Please note that I'm still not totally happy with the code, but it should work. |
@ibrado I wanted to do a quick test and turn it around for you quickly but it is late evening here and my test is therefore not very deep... I followed your instructions and it does display the intro but there is a problem whereby the layouts are nesting. What I mean is that the page content also contains a second copy of the header, footer and sidebar of the page. I guess this is to do with the layout in the front matter in In essence what I have is I think I mentioned it before, I'm using the minimal mistakes layouts. I can look at this again tomorrow - not sure where you are but it's gone 11pm here :) |
Hi @johnlane. I can't seem to replicate the issue if intro.md has no layout: Of course, my mockup is quite simple. I've attached it here; perhaps you can glean something from it. $ unzip demo-intro.zip
$ cd demo-intro
$ export GEM_HOME="./.gem"
$ bundle install
$ jekyll serve |
Thanks @ibrado . I've now worked out what the problem is and have a work-around, if not a solution. I used your example to reproduce the problem and found that it is caused by conflcting defaults. I have my site configured to display a side-bar with my author bio. The default display in the vanilla minimal mistakes does not include this. To get that I had added a default for
That sets the default layout parameters used by the collection index (i.e. To set default layout parameters for a collection's pages requires another defaults block specific to that collection:
Note that this block does not affect the collection's index, only its pages. But Trying to specify
and then specified that in
I think the fact that There may be a better way to achieve the effect of this workaround. I don't know if the code that includes the intro would be able to remove any implicit layout from it ? |
Actually I did have that code (set it to "none") but removed it in a second commit heheh.... I'll revert. I guess I did have a reason for putting that there. Give me a few mins. |
Try now. You may need to run |
BTW, I'm not sure if |
Did you push? last commit showing is #75e29b4 |
Was lazy and reset :D 75e29b4 is original code with the resetting of layout to |
Ok well that works without specifying a layout now :) Not sure what you're suggesting with minor point.... a |
I mean, if specifying OTOH, not having to specify a layout also is good for the end-user. Maybe I'll just make it |
Ok, I just pushed the "override inherited layout" idea. |
yes that's what I was thinking... support a layout if given but none otherwise. I'll try that push for you now :) Just a comment... while this is great, it still doesn't work like I don't understand why collections are so fundamentally different to posts that they can't work in the same way - probably some limitation to how Jekyll works I guess. I really wanted to be able to style collections in the same way as |
I guess @sverrirs would be the one to answer that properly. It does seem that you actually don't need AutoPages for what you want to do, come to think of it. You could probably just create index.html in the collections folder. I'll give it whirl... |
Hmm, my site now fails with
Reverting to #75e29b4 fixes it. The test site works. but the rendering issue is back unless you specify |
Oops. I'm an idiot. Wait... Fixed. |
That blocks out the first page of pagination; it was the first thing I tried :) |
Hmmm. I'm not seeing the "blocks out the first page" here. The pagination path for the next page is wrong (/page2 instead of /stuff/2) but I do see the 1st and 2nd pages (of 1 post each). The path could probably be fixed in the include or template. Will check some more. |
Ah I had index.html Not thinking clearly, will take a break... it's 8:30pm here. ;-) |
Well, well well... I've been able to do what I wanted. I created a directory called
This paginates the collection located at The If I want any content in
So I think it was possible to do what I wanted all along, without anything else; collections do paginate the same as posts. So one might question the need for the |
Actually, I just realized this (and your solution) is very similar to #60 which I answered before in that it involved creating a file in separate/parallel folder... no wonder it felt familiar. 😆 |
Re:
Commit #4b3dcfa fixes it. All good :) |
Thanks... Sorry for not remembering re #60 before, could have saved us a lot of time, hehe. |
Seems to be fixed, closing this issue. |
Would the "intro" code (saving an "intro.md' etc. file in the collections folder) still be useful? |
I am not using it at present but I do think it's a useful capability to have. I am now using the separate index page along with some liquid tags to limit output to first page, as I described previously. Given the feature is there now it might as well be integrated, no? |
Ok, I've submitted a PR. :-) Sverrir, kindly take a look and feel free to modify/decline as you see fit, as usual. Thanks! |
This could probably be closed since the original question/problem has been solved. For the intro feature, we could continue discussions in #75 for now... |
Hello @sverrirs I am trying to use your plugin on a site with a main
_pages
blog and some collections (one now, but ultimately several). I can paginate the blog posts and that works great, but it isn't clear to me from the documentation how to paginate a collection. I don't think your examples cover this sceario.I have
_collections/_stuff
containing a number posts and anindex.md
which has frontmatter:The index of
stuff
is published as/stuff/
as one would expect. It uses the same layout as the blog page.I have enabled pagination in
_config.yml
:but it only paginates the blog posts. If I add
collection: stuff
to_config.yml
then it only paginatesstuff
but onto the blog index page. I saw this done here but guess it's wrong so removed it again. So I am back to having blog posts paginated at/blog
and that looks good.When the generator runs I can see it work through the blog pages but it doesn't process the collection at all (there are no
page
directories under/_site/stuff/)
.So what is the right way to add pagination of
stuff
at/stuff/
?The text was updated successfully, but these errors were encountered: