Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding multilingual processing for Pages; mimicking process used for … #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 33 additions & 3 deletions lib/octopress-multilingual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def posts_by_language(lang=nil)
@posts_by_language ||= begin
posts = site.posts.reverse.select(&:lang).group_by(&:lang)
## Add posts that crosspost to all languages

posts.each do |lang, lang_posts|
if lang != main_language
lang_posts.concat(crossposts).sort_by!(&:date).reverse!
Expand All @@ -89,6 +89,24 @@ def posts_by_language(lang=nil)
@posts_by_language[lang] || []
end

def pages_by_language(lang=nil)
@pages_by_language ||= begin
pages = site.pages.reverse.select(&:lang).group_by(&:lang)
## Add pages that crosspost to all languages
## commenting out as this was causing compile error by Jekyll; (my) Pages do not have a :date
#pages.each do |lang, lang_pages|
# if lang != main_language
# lang_pages.concat(crossposts).sort_by!(&:date).reverse!
# end
#end

pages[main_language] = main_language_pages
pages
end

@pages_by_language[lang] || []
end

def crossposts
site.posts.select(&:crosspost_languages)
end
Expand All @@ -99,10 +117,20 @@ def main_language_posts
end
end

def main_language_pages
site.pages.reverse.select do |page|
page.lang.nil? || page.lang == main_language
end
end

def posts_without_lang
@posts_without_lang ||= site.reject(&:lang)
end

def pages_without_lang
@pages_without_lang ||= site.reject(&:lang)
end

def articles_by_language(lang=nil)
@articles_by_language ||= begin
articles = {}
Expand Down Expand Up @@ -149,7 +177,7 @@ def metadata_index_by_language(index)
languages.each do |lang|
indexes[lang] = {}
site_indexes.each do |index, posts|
posts = posts.select do |p|
posts = posts.select do |p|
p.lang == lang || (lang == main_language && p.lang.nil?) || p.crosspost_languages
end

Expand All @@ -172,8 +200,9 @@ def tags_by_language(lang=nil)

def page_payload(lang)
payload = {
'site' => {
'site' => {
'posts' => posts_by_language(lang),
'pages' => pages_by_language(lang),
'linkposts' => linkposts_by_language(lang),
'articles' => articles_by_language(lang),
'categories' => categories_by_language(lang),
Expand All @@ -194,6 +223,7 @@ def site_payload
@payload ||= {
'site' => {
'posts_by_language' => posts_by_language,
'pages_by_language' => pages_by_language,
'linkposts_by_language' => linkposts_by_language,
'articles_by_language' => articles_by_language,
'categories_by_language' => categories_by_language,
Expand Down
5 changes: 4 additions & 1 deletion lib/octopress-multilingual/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def posts_by_language(lang=nil)
Octopress::Multilingual.posts_by_language(lang)
end

def pages_by_language(lang=nil)
Octopress::Multilingual.pages_by_language(lang)
end

def articles_by_language(lang=nil)
Octopress::Multilingual.articles_by_language(lang)
end
Expand Down Expand Up @@ -148,4 +152,3 @@ def previous
end
end
end