octopress-multilingual 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 988ada1b8e7e3a6cd445a4c440476df940673fe0
4
+ data.tar.gz: 3c515dec3ace3c5aa14c8ee44bfd9315821ebf06
5
+ SHA512:
6
+ metadata.gz: a3e26bcc97084f9ad7c91ef0fe11f449adc7d6ffb224a70db8be66d141eba73e1874fddb753d0178a6832f8630f25beafa8dc2a85bf8082ba22ec1dba0c28dd2
7
+ data.tar.gz: 67599396585ab3d2b09b088274c07bb29027d23bc475a870d2275ede43ab73c8d0629bb2638ce95c20dfaaff4ad55be1dfbd1ac221282935c0056264cce56a43
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Octopress Multilingual
2
+
3
+ Add multiple language features to your Jekyll site.
4
+
5
+ [![Build Status](http://img.shields.io/travis/octopress/multilingual.svg)](https://travis-ci.org/octopress/multilingual)
6
+ [![Gem Version](http://img.shields.io/gem/v/octopress-multilingual.svg)](https://rubygems.org/gems/octopress-multilingual)
7
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://octopress.mit-license.org)
8
+
9
+ ## Installation
10
+
11
+ If you're using bundler add this gem to your site's Gemfile in the `:jekyll_plugins` group:
12
+
13
+ group :jekyll_plugins do
14
+ gem 'octopress-multilingual'
15
+ end
16
+
17
+ Then install the gem with Bundler
18
+
19
+ $ bundle
20
+
21
+ To install manually without bundler:
22
+
23
+ $ gem install octopress-multilingual
24
+
25
+ Then add the gem to your Jekyll configuration.
26
+
27
+ gems:
28
+ - octopress-multilingual
29
+
30
+
31
+ ## An important note
32
+
33
+ **There is not a Jekyll standard for multilingual sites** and many plugins will not work properly with this setup. Octopress and it's
34
+ plugins are being designed to support multilingual features, but without a standard, some use-cases may be overlooked. If you have a
35
+ problem with an Octopress plugin supporting your multilingual site, please file an issue and we'll do our best to address it.
36
+
37
+ ## Setting up a multilingual site
38
+
39
+ When adding this plugin to your site, you will need to:
40
+
41
+ 1. Configure your site's main language, e.g. `main_language: en`.
42
+ 2. Add a language to the YAML front-matter of your posts, e.g. `lang: de`.
43
+ 3. Add new RSS feeds and post indexes for secondary languages.
44
+
45
+ Read on and I'll try to walk you through setting up your multilingual site.
46
+
47
+ Note: This guide will only cover the steps listed above. Your site may still have some plugins which are not designed for multilingual sites. If you are using plugins (like a category index generator) which create pages from your site's posts, they may need to be modified or removed. Modifying plugins is beyond the scope of this guide.
48
+
49
+ ## Configuration
50
+
51
+ First, be sure to configure your Jekyll site's main language, for example:
52
+
53
+ ```yaml
54
+ main_language: en
55
+ ```
56
+
57
+ Here we are setting the default language to English. Posts without a defined language will be treated as English posts.
58
+
59
+ ## Defining a post's language
60
+
61
+ Posts should specify their language in the YAML front matter.
62
+
63
+ ```yaml
64
+ title: "Ein Nachdenklich Beitrag"
65
+ lang: de
66
+ ```
67
+
68
+ If you are using Octopress, you can easily create a new post with the language already site like this:
69
+
70
+ ```
71
+ $ octopress new post "Some title" --lang en
72
+ ```
73
+
74
+ ### Cross-posting languages
75
+
76
+ Occasionally you may wish to write a post in a single language and have it show up in other languages indexes and feeds. This can be done in your post's YAML front-matter:
77
+
78
+ ```
79
+ title: "Ein Nachdenklich Beitrag"
80
+ lang: de
81
+ crosspost_languages: true
82
+ ```
83
+
84
+ If your site has language-specific feeds or post indexes, a post with this setting will show up in all of them. However, it isn't duplicated. It will still have one canonical URL.
85
+
86
+ ### Language in permalinks
87
+
88
+ This plugin does not use categories to add language to URLs. Instead it adds the `:lang` key to Jekyll's permalink template.
89
+ Any post **with a defined language** will have its language in the URL. If this changes URLs for your site, you probably should [set up redirects](https://github.com/jekyll/jekyll-redirect-from).
90
+
91
+ If you define your own permalink style, you may use the `:lang` key like this:
92
+
93
+ ```yaml
94
+ permalink: /posts/:lang/:title/
95
+ ```
96
+
97
+ If you have not specified a permalink style, or if you are using one of Jekyll's default templates, your post URLs will change to include their language.
98
+ When using Jekyll's `pretty` url template, URLs will look like this:
99
+
100
+ ```
101
+ /site_updates/en/2015/01/17/moving-to-a-multilingual-site/index.html
102
+ /site_updates/de/2015/01/17/umzug-in-eine-mehrsprachige-website/index.html
103
+ ```
104
+
105
+ This plugin updates each of Jekyll's default permalink templates to include `:lang`.
106
+
107
+ ```ruby
108
+ pretty => /:lang/:categories/:year/:month/:day/:title/
109
+ none => /:lang/:categories/:title.html
110
+ date => /:lang/:categories/:year/:month/:day/:title.html
111
+ ordinal => /:lang/:categories/:year/:y_day/:title.html
112
+ ```
113
+
114
+ If you don't want language to appear in your URLs, you must configure your own permalinks without `:lang`.
115
+
116
+ ## Post Indexes and RSS Feeds
117
+
118
+ This plugin modifies your site's post list. The `site.posts` array **will not contain every post**, but only posts defined with your site's main language or with no language defined.
119
+ You may access secondary languages with `site.posts_by_language`.
120
+
121
+ For example, to loop through the posts written in your main language (or without a defined language) you would do this:
122
+
123
+ ```
124
+ {% for post in site.posts.reverse %}
125
+ ```
126
+
127
+ This is probably the way your posts index and RSS feeds are generated. If you want to loop through the posts from a secondary language — in this case, German — you would want to do this:
128
+
129
+ ```
130
+ {% for post in site.posts_by_language.de.reverse %}
131
+ ```
132
+
133
+ If your default post index is at `/index.html` you should create additional indexes for each secondary language. If you're also writing in German, you'd copy your posts index to `/de/index.html`.
134
+
135
+ This practice should work for RSS feeds and anything that works with the post loop.
136
+
137
+ ## Contributing
138
+
139
+ 1. Fork it ( https://github.com/[my-github-username]/octopress-multilingual/fork )
140
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
141
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
142
+ 4. Push to the branch (`git push origin my-new-feature`)
143
+ 5. Create a new Pull Request
@@ -0,0 +1,129 @@
1
+ require "octopress-multilingual/version"
2
+ require 'octopress-hooks'
3
+
4
+ module Octopress
5
+ module Multilingual
6
+ extend self
7
+ attr_accessor :site, :posts
8
+
9
+ def main_language
10
+ if @lang ||= site.config['main_language']
11
+ @lang.downcase
12
+ else
13
+ abort "Build canceled by Octopress Multilingual.\n".red \
14
+ << "Your Jekyll site configuration must have a main language. For example:\n\n" \
15
+ << " main_language: en\n\n"
16
+ end
17
+ end
18
+
19
+ def site
20
+ @site
21
+ end
22
+
23
+ def languages
24
+ posts_by_language.keys
25
+ end
26
+
27
+ def posts_by_language
28
+ @posts_by_language ||= begin
29
+ posts = site.posts.select(&:lang).group_by(&:lang) \
30
+ ## Add posts that crosspost to all languages
31
+ .each do |lang, posts|
32
+ if lang == main_language
33
+ posts.clear.concat(main_language_posts)
34
+ else
35
+ posts.concat(crossposts).sort_by(&:date)
36
+ end
37
+ end
38
+ posts
39
+ end
40
+ end
41
+
42
+ def main_language_posts
43
+ site.posts.reject do |post|
44
+ post.lang && post.lang != main_language
45
+ end
46
+ end
47
+
48
+ def crossposts
49
+ @cross_posts ||= begin
50
+ posts = site.posts.select do |post|
51
+ post.data['crosspost_languages']
52
+ end
53
+ end
54
+ end
55
+
56
+ def posts_without_lang
57
+ @posts_without_lang ||= site.reject(&:lang)
58
+ end
59
+
60
+ def site_payload(site)
61
+ @site = site
62
+
63
+ if main_language
64
+ {
65
+ 'posts' => main_language_posts,
66
+ 'posts_by_language' => posts_by_language,
67
+ 'languages' => languages
68
+ }
69
+ end
70
+ end
71
+
72
+
73
+ class SiteHook < Hooks::Site
74
+ priority :low
75
+
76
+ def merge_payload(payload, site)
77
+
78
+ # Group posts by language, { 'en_post' => [posts,..] }
79
+ #
80
+
81
+ # Ensure that posts without an assigned language
82
+ # appear in each language's feed
83
+ #
84
+
85
+ { 'site' => Octopress::Multilingual.site_payload(site) }
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ module Jekyll
92
+ class URL
93
+ def generate_url(template)
94
+ @placeholders.inject(template) do |result, token|
95
+ break result if result.index(':').nil?
96
+ if token.last.nil?
97
+ result.gsub(/\/:#{token.first}/, '')
98
+ else
99
+ result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ class Post
106
+ alias :template_orig :template
107
+ alias :url_placeholders_orig :url_placeholders
108
+
109
+ def template
110
+ template = template_orig
111
+
112
+ if [:pretty, :none, :date, :ordinal].include? site.permalink_style
113
+ template = File.join('/:lang', template)
114
+ end
115
+
116
+ template
117
+ end
118
+
119
+ def lang
120
+ data['lang'].downcase if data['lang']
121
+ end
122
+
123
+ def url_placeholders
124
+ url_placeholders_orig.merge({
125
+ :lang => lang
126
+ })
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ module Multilingual
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-multilingual
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octopress-hooks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: clash
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: octopress-debugger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - brandon@imathis.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/octopress-multilingual.rb
107
+ - lib/octopress-multilingual/version.rb
108
+ homepage: https://github.com/octopress/multilingual
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Add multiple language features to your Jekyll site.
132
+ test_files: []