2017-09-07 52 views
0

我正在尝试使用最新的Jekyll整合octopress-multilingual和octopress-paginate。这不能正常工作。Octopress-multilingual with octopress-paginate与最新的jekyll不兼容

在这种情况下,不可能使用octopress-paginate分页翻译的jekyll页面。

我想要实现的是在_plugin文件夹中有一个.rb文件,以允许paginate,即基于_config.yml文件中定义的全局变量的帖子。这是使用ruby方法alias_method覆盖当前行为。

_config.yml(提取物)

lang: en 

_plugins/.yml(提取物)

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 

这是我的布局: _pages/news.html(提取物)

--- 
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--> 

在上面的示例中,我按语言过滤了帖子,但分页程序未按语言过滤。

这里的目标是能够基于_config.yml文件中的lang标记对帖子进行分页。

这可能吗?

+0

不幸的是,[Octopress](https://github.com/octopress/octopress)看起来像一个死了的项目。一年半以上没有发生任何事,最近的版本也没有完全酝酿。有很多小东西不能正常工作:-( – axiac

+0

是的,可能看起来如此,但至少应该是可以的,对吧? – ccamacho

回答