0

我正在尝试使用最新的 Jekyll 集成 octopress-multilingual 和 octopress-paginate。这不能正常工作。

在这种情况下,无法使用 octopress-paginate 对翻译后的 jekyll 页面进行分页。

我想要实现的是在 _plugin 文件夹中有一个 .rb 文件,以允许基于 _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 标签对帖子进行分页。

这可能吗?

4

1 回答 1

0

最后,使用此插件https://github.com/sverrirs/jekyll-paginate-v2很容易实现这一点。

而不是八爪鱼。只需使用名为“语言环境”的标记而不是名为“语言”的标记。

于 2017-09-08T18:10:50.873 回答