octopress / paginate

A simple paginator for Jekyll sites.
MIT License
105 stars 37 forks source link

octopress-multilingual with octopress-paginate are not compatible with latest jekyll #42

Open ccamacho opened 7 years ago

ccamacho commented 7 years ago

I'm trying to integrate both octopress-multilingual and octopress-paginate using latest Jekyll. And this is not working properly.

In this case is not possible to paginate a translated jekyll page using octopress-paginate.

What I'm trying to achieve is to have a .rb file in the _plugin folder to allow paginate i.e. posts based on a global variable defined in the _config.yml file. This is using the ruby method alias_method to override the current behavior.

_config.yml (extract)

lang: en

_plugins/.yml (extract)

module Octopress
  module Paginate
    def paginate(page)
      defaults = DEFAULT.merge(page.site.config['pagination'] || {})
      if page.data['paginate'].is_a? Hash
        page.data['paginate'] = defaults.merge(page.data['paginate'])
      else
        page.data['paginate'] = defaults
      end
      if tag = Jekyll.configuration({})['lang']
        page.data['paginate']['tags'] = Array(tag)
      end
      if category = page.data['paginate']['category']
        page.data['paginate']['categories'] = Array(category)
      end
      old_paginate(page)
    end
    alias_method :old_paginate, :paginate
  end
end

This is my layout: _pages/news.html (extract)

---
layout: default
title: news
permalink: /latest/news/
paginate:
  collection:   posts
  per_page:     4                       # maximum number of items per page
  limit:        false
  permalink:    :num/  # pagination path (relative to template page)
---
<!-- Page code goes here-->
{% assign news = paginator.posts | where:'category', 'articles' | where:'lang', site.lang %}
{% for post in news %}
<!-- News code goes here-->
{% endfor %}
<!-- Page code goes here-->
{% for page in (1..paginator.total_pages) %}
<!-- Paginator code goes here-->
{% endfor %}
<!-- Page code goes here-->

In the above example, I'm filtering the posts by the language, but the paginator is not filtering by language.

The goal here would be to be able to paginate posts based on the lang tag in the _config.yml file.

Is this possible?