octopress-multilingual 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f88280a6ba9bc3da6a1d14232454780c116c1101
4
- data.tar.gz: 9a111ba706ab49eb94ee5fedb61dca7111e086eb
3
+ metadata.gz: 981b8a85ae89b0b5e014752f4a7aa40f91e7fb57
4
+ data.tar.gz: f072ab8273a2e0768b726c6fd842d67bd3df279d
5
5
  SHA512:
6
- metadata.gz: 6739a5a56c07b022fae9e1a5a37c3079376f604b1cef538acde7c40bd7fcb1c22b33181e3e053563d6c9cc320f8ef8c37dc6e7a29470d4838d5b90ba76b39a54
7
- data.tar.gz: 9c5e311e5e2499896d99eb496821d030b09f40f42ad468e2c54e71d6e3b51d9aa90076cc4c3a581ecc83cbde15d25b42f1ef40a664f430149cc261f99be31e06
6
+ metadata.gz: ca81dc779eca08eee26031d3a211916c13f8c0a4b5b7702abfc190c01215c9804b6e53e3fdb4ae70cd343bbd57d3ef89bae1c85f8465389517c69da112314404
7
+ data.tar.gz: 372f2fff3287ce3498303f0cc9af335d1638d43ea0c593cab5665e07a4b2fe44701284d671fb93c5ae3b42c41c0fa6e1e87849969629005da42834970f7015a9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.1.0 (2015-02-16)
4
+ - New: Tags and Categories are now also filtered by language.
5
+
3
6
  ### 1.0.2 (2015-02-10)
4
7
  - Fix: Page permalinks were getting set to by language names.
5
8
 
data/README.md CHANGED
@@ -7,6 +7,7 @@ Add multiple language features to your Jekyll site. This plugin makes it easy to
7
7
  - Use language in your permalinks.
8
8
  - Cross-post a single post to all languages.
9
9
  - Add translation dictionaries to simplify site templates.
10
+ - Tag and category indexes are automatically filtered by language.
10
11
 
11
12
  [![Build Status](http://img.shields.io/travis/octopress/multilingual.svg)](https://travis-ci.org/octopress/multilingual)
12
13
  [![Gem Version](http://img.shields.io/gem/v/octopress-multilingual.svg)](https://rubygems.org/gems/octopress-multilingual)
@@ -43,13 +44,20 @@ Note: First-party Octopress plugins are designed to support multilingual sites b
43
44
 
44
45
  Also, if you are using flags to represent languages on your site, you might like to read, [Why flags do not represent language](http://flagsarenotlanguages.com/blog/why-flags-do-not-represent-language/).
45
46
 
47
+ ## Helpful Plugins
48
+
49
+ These plugins automatically add multilingual features to your site when used with Octopress Multilingual.
50
+
51
+ - [Octopress Linkblog](https://github.com/octopress/linkblog) adds link-blogging indexes (articles-only, links-only) and feeds for each language.
52
+ - [Octopress Feeds](https://github.com/octopress/feeds) adds RSS feeds for each language.
53
+
46
54
  ## Setup
47
55
 
48
56
  When adding this plugin to your site, you will need to:
49
57
 
50
58
  1. Configure your site's main language, e.g. `lang: en`.
51
59
  2. Add a language to the YAML front-matter of your posts, e.g. `lang: de`.
52
- 3. Add new RSS feeds and post indexes for secondary languages.
60
+ 3. Add post indexes and RSS feeds for secondary languages.
53
61
 
54
62
  First, be sure to configure your Jekyll site's main language. An site written primarily in English would add this to its Jekyll configuration:
55
63
 
@@ -112,7 +120,8 @@ lang: en
112
120
  If your default post index is at `/index.html` you should create additional indexes for each secondary language. If you also write in German, you can create a posts index at `/de/index.html`. This approach will work for post archives and RSS feeds, though if you are using [octopress-feeds](https://github.com/octopress/feeds), RSS feeds for each language will be generated automatically.
113
121
 
114
122
  How does it work? First this plugin groups all of your posts by language. Then at build time, any page with a language defined will
115
- have its posts filtered to display only matching languages. If your site uses [octopress-linkblog](https://github.com/octopress/linkblog) to publish link-posts, your `site.articles` and `site.linkposts` will be filtered as well.
123
+ have its posts filtered to display only matching languages. This also works for `site.categories` and `site.tags`.
124
+ If your site uses [octopress-linkblog](https://github.com/octopress/linkblog) to publish link-posts, your `site.articles` and `site.linkposts` will be filtered as well.
116
125
 
117
126
  ## Site template language dictionaries
118
127
 
@@ -12,14 +12,12 @@ module Octopress
12
12
 
13
13
  # Add translation page data to each page or post.
14
14
  #
15
- [site.pages, site.posts].flatten.each do |item|
16
- if item.translated
17
- # Access array of translated items via (post/page).translations
18
- item.data.merge!({
19
- 'translations' => item.translations,
20
- 'translated' => item.translated
21
- })
22
- end
15
+ [site.pages, site.posts].flatten.select(&:translated).each do |item|
16
+ # Access array of translated items via (post/page).translations
17
+ item.data.merge!({
18
+ 'translations' => item.translations,
19
+ 'translated' => item.translated
20
+ })
23
21
  end
24
22
  end
25
23
 
@@ -45,6 +43,14 @@ module Octopress
45
43
  end
46
44
  end
47
45
 
46
+ # Override deep_merge to prevent categories and tags from being combined when they shouldn't
47
+ #
48
+ def deep_merge_payload(page_payload, hook_payload)
49
+ %w{site page}.each do |key|
50
+ hook_payload[key] = page_payload[key].merge(hook_payload[key] || {})
51
+ end
52
+ hook_payload
53
+ end
48
54
  end
49
55
  end
50
56
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Multilingual
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -134,12 +134,43 @@ module Octopress
134
134
  end
135
135
  end
136
136
 
137
+ def metadata_index_by_language(index)
138
+ # Get site categories or tags
139
+ site_indexes = site.send(index)
140
+
141
+ indexes = {}
142
+
143
+ # Filter indexes for each language
144
+ languages.each do |lang|
145
+ indexes[lang] = {}
146
+ site_indexes.each do |index, posts|
147
+ posts = posts.select do |p|
148
+ p.lang == lang || (lang == main_language && p.lang.nil?) || p.crosspost_languages
149
+ end
150
+
151
+ indexes[lang][index] = posts unless posts.empty?
152
+ end
153
+ end
154
+
155
+ indexes
156
+ end
157
+
158
+ def categories_by_language
159
+ @categories ||= metadata_index_by_language(:categories)
160
+ end
161
+
162
+ def tags_by_language
163
+ @tags ||= metadata_index_by_language(:tags)
164
+ end
165
+
137
166
  def page_payload(lang)
138
167
  payload = {
139
168
  'site' => {
140
- 'posts' => posts_by_language[lang],
141
- 'linkposts' => linkposts_by_language[lang],
142
- 'articles' => articles_by_language[lang]
169
+ 'posts' => posts_by_language[lang],
170
+ 'linkposts' => linkposts_by_language[lang],
171
+ 'articles' => articles_by_language[lang],
172
+ 'categories' => categories_by_language[lang],
173
+ 'tags' => tags_by_language[lang]
143
174
  },
144
175
  'lang' => lang_dict[lang]
145
176
  }
@@ -155,10 +186,12 @@ module Octopress
155
186
  if main_language
156
187
  @payload ||= {
157
188
  'site' => {
158
- 'posts_by_language' => posts_by_language,
159
- 'linkposts_by_language' => linkposts_by_language,
160
- 'articles_by_language' => articles_by_language,
161
- 'languages' => languages
189
+ 'posts_by_language' => posts_by_language,
190
+ 'linkposts_by_language' => linkposts_by_language,
191
+ 'articles_by_language' => articles_by_language,
192
+ 'categories_by_language' => categories_by_language,
193
+ 'tags_by_language' => tags_by_language,
194
+ 'languages' => languages
162
195
  },
163
196
  'lang' => lang_dict[main_language]
164
197
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-multilingual
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octopress-hooks