sverrirs / jekyll-paginate-v2

Pagination Generator for Jekyll 3 (enhanced replacement for the old built-in jekyll-paginate gem) ⛺
https://rubygems.org/gems/jekyll-paginate-v2
MIT License
524 stars 289 forks source link

Support real and natural custom collections in autopages #234

Open MolotovCherry opened 2 years ago

MolotovCherry commented 2 years ago

Hi, I updated the logic in autopages to properly support custom collections in a very natural way.

The way this works now with a config like this

# define all your collections as usual in jekyll
# collections_dir = "foobar" // you can do this too if you want
collections:
  posts:
    output: true
    permalink: /:categories/:title
  authors:
    # don't output them though, but you can set your permalink
    permalink: /author/:name/
  tags:
    permalink: /tag/:name/
  categories:
    permalink: /category/:name/

autopages:
  # autopage-wide enable/disable switch
  enabled: true

  # every collection you want to use you must make a key for and set it to enabled. Everything is disabled by default otherwise
  authors:
    # the layout file. This will ovveride the coll's layout; if not specified, it grabs the layout from the coll doc
    layout: author-page.html
    # you must enable it
    enabled: true
    # the key that is used by posts/whatever custom collection you want. Set this key in your collections frontmatter to filter the collection by this field
    indexkey: author
    # enable to filter collection by indexkey. default disabled
    filter_collection: true
    # obvious. Use the same key as indexkey for replacement. overrides all. If not specified, checks layout for title. If layout has no title, checks the collection doc for the title
    title: "Some title :author"
    # optional, but you can change the collection you're using
    collection: posts
    # obvious. will override docs permalink. If not specified, document's permalink will be used instead (from jekyll's collection config)
    permalink: /author/:author/
   # so in essence, all the above says, use the authors collection, and use the key 'author'
   # to return and filter collection 'posts' by the author key (authors collection's author field == posts.author)
   # so basically, it does the same thing that tags and categories does, except for custom collections

pagination:
  enabled: true
  # check to see debug of custom collection filter
  debug: true
  # this setting is honored. 
  collection: 'posts'
  # filters custom collection by this id specified in pagination
  filter_coll_by: author
  # I'll specify it here now
  author: Cherryleafroad
  # the two options above are mainly to be used for autopages for custom coll filtering, but you can use these in regular pagination frontmatter

The purpose of indexkey is this:

By thus doing, we have pagination for custom collections which filter out the posts with matching keys on custom collections

Please be gentle with me, I'm very new to Ruby and didn't even know it a week ago. Never used Ruby before

Edit: I accidentally left in a fix in here for #219. I'll just leave it there