Module: Jekyll::Helpers

Included in:
Jekyll.parent::Pagination, Filters
Defined in:
lib/jekyll/localization.rb

Instance Method Summary collapse

Instance Method Details

#localize_posts(site, page) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/jekyll/localization.rb', line 238

def localize_posts(site, page)
  s = site.respond_to?(:set_payload)

  o = s ? site.get_payload('posts') : site.posts.dup
  l = localized_posts(o, page, true)

  s ? site.set_payload('posts' => l) : site.posts.replace(l) if l

  yield
ensure
  s ? site.set_payload('posts' => o) : site.posts.replace(o) if l
end

#localized_posts(posts, page, only = false) ⇒ Object



233
234
235
236
# File 'lib/jekyll/localization.rb', line 233

def localized_posts(posts, page, only = false)
  lang = page.lang
  lang ? posts.select { |post| post.lang == lang } : only ? nil : posts
end