jekyll-polyglot 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +36 -2
- data/lib/jekyll/polyglot/hooks/coordinate.rb +13 -1
- data/lib/jekyll/polyglot/hooks/process.rb +4 -0
- data/lib/jekyll/polyglot/liquid/tags/i18n-headers.rb +6 -6
- data/lib/jekyll/polyglot/patches/jekyll/site.rb +54 -18
- data/lib/jekyll/polyglot/version.rb +1 -1
- metadata +3 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df6aaf664d7ec8f17ca2da2ae38232e4fe95fac
|
4
|
+
data.tar.gz: 223f820553ee68db46b6ef433d9c8298af737198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 617ed0583476e45cfd8ec9c41c745e2e02eaf8a52b760a767c5081c51d0d184254d6546ad585659b18c43dbdfa6a826758566f5ae7767b4472e924091494b933
|
7
|
+
data.tar.gz: 0ff23c46c41468bddd13a7b91622622aa47bb758f9ca07ed25763e8f4f852b8c7524823ed0dc5ba34d5b4089ce2dfa504f6fc8a70f832e0a352e155db81edd8c
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2015 -
|
1
|
+
Copyright (c) 2015 - 2017 Samuel Volin
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
Or install the gem manually by doing `gem install jekyll-polyglot` and specify the plugin using `_config.yml`:
|
20
20
|
```YAML
|
21
|
-
|
21
|
+
plugins:
|
22
22
|
- jekyll-polyglot
|
23
23
|
```
|
24
24
|
|
@@ -92,6 +92,39 @@ Notice the link `<a href="/fr/menu/">...` directs to the french website.
|
|
92
92
|
Even if you are falling back to `default_lang` page, relative links built on the *french* site will
|
93
93
|
still link to *french* pages.
|
94
94
|
|
95
|
+
#### Relativized Absolute Urls
|
96
|
+
If you defined a site `url` in your `_config.yaml`, polyglot will automatically relativize absolute links pointing to your website directory:
|
97
|
+
|
98
|
+
```md
|
99
|
+
---
|
100
|
+
lang: fr
|
101
|
+
---
|
102
|
+
Cliquez [ici]({{site.url}}) pour aller à l'entrée du site.
|
103
|
+
```
|
104
|
+
becomes
|
105
|
+
```html
|
106
|
+
<p>Cliquez <a href="https://mywebsite.com/fr/">ici</a> pour aller à l'entrée du site.
|
107
|
+
```
|
108
|
+
|
109
|
+
#### Disabling Url Relativizing
|
110
|
+
If you don't want a url to be relativized, you can add a space explicitly into the href to prevents a url from being relativized by polyglot.
|
111
|
+
|
112
|
+
For example, the following urls will be relativized:
|
113
|
+
|
114
|
+
```html
|
115
|
+
href="http://mywebsite.com/about"
|
116
|
+
href="/about"
|
117
|
+
```
|
118
|
+
|
119
|
+
and the following urls will be left alone:
|
120
|
+
|
121
|
+
```html
|
122
|
+
href=" http://mywebsite.com/about"
|
123
|
+
href=" /about"
|
124
|
+
```
|
125
|
+
|
126
|
+
combine with a [html minifier](https://github.com/digitalsparky/jekyll-minifier) for a polished and production ready website.
|
127
|
+
|
95
128
|
#### Localized site.data
|
96
129
|
|
97
130
|
There are cases when `site.data` localization is required.
|
@@ -109,7 +142,7 @@ This plugin stands out from other I18n Jekyll plugins.
|
|
109
142
|
- builds all versions of your website *simultaneously*, allowing big websites to scale efficiently.
|
110
143
|
- provides the liquid tag `{{ site.languages }}` to get an array of your I18n strings.
|
111
144
|
- provides the liquid tag `{{ site.default_lang }}` to get the default_lang I18n string.
|
112
|
-
- provides the liquid tag `{{ site.active_lang }}` to get the I18n language string the website was built for.
|
145
|
+
- provides the liquid tag `{{ site.active_lang }}` to get the I18n language string the website was built for. Alternative names for `active_lang` can be configured via `config.lang_vars`.
|
113
146
|
- provides the liquid tag `{{ I18n_Headers https://yourwebsite.com/ }}` to append SEO bonuses to your website.
|
114
147
|
- provides `site.data` localization for efficient rich text replacement.
|
115
148
|
- a creator that will answer all of your questions and issues.
|
@@ -124,6 +157,7 @@ Check out the example project website [here](https://untra.github.io/polyglot)
|
|
124
157
|
### Other Websites Built with Polyglot
|
125
158
|
let us know if you make a multilingual blog you want to share:
|
126
159
|
* [LogRhythm Corporate Website](http://logrhythm.com)
|
160
|
+
* [All Over Earth](https://allover.earth/)
|
127
161
|
|
128
162
|
## Compatibility
|
129
163
|
Currently supports Jekyll 3.0 .
|
@@ -1,9 +1,21 @@
|
|
1
1
|
# hook to coordinate blog posts and pages into distinct urls,
|
2
2
|
# and remove duplicate multilanguage posts and pages
|
3
3
|
Jekyll::Hooks.register :site, :post_read do |site|
|
4
|
+
hook_coordinate(site)
|
5
|
+
end
|
6
|
+
|
7
|
+
def hook_coordinate(site)
|
8
|
+
# Copy the language specific data, by recursively merging it with the default data.
|
9
|
+
# Favour active_lang first, then default_lang, then any non-language-specific data.
|
10
|
+
# See: https://www.ruby-forum.com/topic/142809
|
11
|
+
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
12
|
+
if site.data.include?(site.default_lang)
|
13
|
+
site.data = site.data.merge(site.data[site.default_lang], &merger)
|
14
|
+
end
|
4
15
|
if site.data.include?(site.active_lang)
|
5
|
-
site.data = site.data.merge(site.data[site.active_lang])
|
16
|
+
site.data = site.data.merge(site.data[site.active_lang], &merger)
|
6
17
|
end
|
18
|
+
|
7
19
|
site.collections.each do |_, collection|
|
8
20
|
collection.docs = site.coordinate_documents(collection.docs)
|
9
21
|
end
|
@@ -12,14 +12,14 @@ module Jekyll
|
|
12
12
|
def render(context)
|
13
13
|
site = context.registers[:site]
|
14
14
|
permalink = context.registers[:page]['permalink']
|
15
|
-
|
16
|
-
i18n = "<meta http-equiv=\"Content-Language\" content=\"#{site.active_lang}\"
|
17
|
-
i18n += "<link rel=\"alternate\" i18n=\"#{site.default_lang}\""\
|
18
|
-
"
|
15
|
+
site_url = @url.empty? ? site.config['url'] : @url
|
16
|
+
i18n = "<meta http-equiv=\"Content-Language\" content=\"#{site.active_lang}\">\n"
|
17
|
+
i18n += "<link rel=\"alternate\" i18n=\"#{site.default_lang}\" "\
|
18
|
+
"href=\" #{site_url}#{permalink}\"/>\n"
|
19
19
|
site.languages.each do |lang|
|
20
20
|
next if lang == site.default_lang
|
21
|
-
i18n += "<link rel=\"alternate\" i18n=\"#{lang}\""\
|
22
|
-
"
|
21
|
+
i18n += "<link rel=\"alternate\" i18n=\"#{lang}\" "\
|
22
|
+
"href=\"#{site_url}/#{lang}#{permalink}\"/>\n"
|
23
23
|
end
|
24
24
|
i18n
|
25
25
|
end
|
@@ -1,41 +1,47 @@
|
|
1
1
|
include Process
|
2
2
|
module Jekyll
|
3
3
|
class Site
|
4
|
-
attr_reader :default_lang, :languages, :exclude_from_localization
|
4
|
+
attr_reader :default_lang, :languages, :exclude_from_localization, :lang_vars
|
5
5
|
attr_accessor :file_langs, :active_lang
|
6
6
|
|
7
7
|
def prepare
|
8
8
|
@file_langs = {}
|
9
|
-
|
10
|
-
@languages = config.fetch('languages', ['en'])
|
9
|
+
fetch_languages
|
11
10
|
@parallel_localization = config.fetch('parallel_localization', true)
|
12
|
-
(@keep_files << @languages - [@default_lang]).flatten!
|
13
11
|
@exclude_from_localization = config.fetch('exclude_from_localization', [])
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch_languages
|
15
|
+
@default_lang = config.fetch('default_lang', 'en')
|
16
|
+
@languages = config.fetch('languages', ['en'])
|
17
|
+
@keep_files += (@languages - [@default_lang])
|
14
18
|
@active_lang = @default_lang
|
19
|
+
@lang_vars = config.fetch('lang_vars', [])
|
15
20
|
end
|
16
21
|
|
17
22
|
alias_method :process_orig, :process
|
18
23
|
def process
|
19
24
|
prepare
|
25
|
+
all_langs = (@languages + [@default_lang]).uniq
|
20
26
|
if @parallel_localization
|
21
27
|
pids = {}
|
22
|
-
|
28
|
+
all_langs.each do |lang|
|
23
29
|
pids[lang] = fork do
|
24
30
|
process_language lang
|
25
31
|
end
|
26
32
|
end
|
27
33
|
Signal.trap('INT') do
|
28
|
-
|
34
|
+
all_langs.each do |lang|
|
29
35
|
puts "Killing #{pids[lang]} : #{lang}"
|
30
36
|
kill('INT', pids[lang])
|
31
37
|
end
|
32
38
|
end
|
33
|
-
|
39
|
+
all_langs.each do |lang|
|
34
40
|
waitpid pids[lang]
|
35
41
|
detach pids[lang]
|
36
42
|
end
|
37
43
|
else
|
38
|
-
|
44
|
+
all_langs.each do |lang|
|
39
45
|
process_language lang
|
40
46
|
end
|
41
47
|
end
|
@@ -47,14 +53,28 @@ module Jekyll
|
|
47
53
|
payload['site']['default_lang'] = default_lang
|
48
54
|
payload['site']['languages'] = languages
|
49
55
|
payload['site']['active_lang'] = active_lang
|
56
|
+
lang_vars.each do |v|
|
57
|
+
payload['site'][v] = active_lang
|
58
|
+
end
|
50
59
|
payload
|
51
60
|
end
|
52
61
|
|
53
62
|
def process_language(lang)
|
54
63
|
@active_lang = lang
|
55
64
|
config['active_lang'] = @active_lang
|
56
|
-
|
57
|
-
|
65
|
+
lang_vars.each do |v|
|
66
|
+
config[v] = @active_lang
|
67
|
+
end
|
68
|
+
if @active_lang == @default_lang
|
69
|
+
then process_default_language
|
70
|
+
else process_active_language
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def process_default_language
|
75
|
+
old_include = @include
|
76
|
+
process_orig
|
77
|
+
@include = old_include
|
58
78
|
end
|
59
79
|
|
60
80
|
def process_active_language
|
@@ -87,8 +107,15 @@ module Jekyll
|
|
87
107
|
|
88
108
|
# performs any necesarry operations on the documents before rendering them
|
89
109
|
def process_documents(docs)
|
110
|
+
return if @active_lang == @default_lang
|
111
|
+
url = config.fetch('url', false)
|
112
|
+
rel_regex = relative_url_regex
|
113
|
+
abs_regex = absolute_url_regex(url)
|
90
114
|
docs.each do |doc|
|
91
|
-
relativize_urls
|
115
|
+
relativize_urls(doc, rel_regex)
|
116
|
+
if url
|
117
|
+
then relativize_absolute_urls(doc, abs_regex, url)
|
118
|
+
end
|
92
119
|
end
|
93
120
|
end
|
94
121
|
|
@@ -109,17 +136,26 @@ module Jekyll
|
|
109
136
|
# avoids matching excluded files
|
110
137
|
def relative_url_regex
|
111
138
|
regex = ''
|
112
|
-
@exclude.each do |x|
|
139
|
+
(@exclude + @languages).each do |x|
|
113
140
|
regex += "(?!#{x}\/)"
|
114
141
|
end
|
115
|
-
|
116
|
-
url_quoted = Regexp.quote(url_quoted) unless url_quoted.nil?
|
117
|
-
%r{href=\"(?:#{url_quoted})?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
142
|
+
%r{href=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
118
143
|
end
|
119
144
|
|
120
|
-
def
|
121
|
-
|
122
|
-
|
145
|
+
def absolute_url_regex(url)
|
146
|
+
regex = ''
|
147
|
+
(@exclude + @languages).each do |x|
|
148
|
+
regex += "(?!#{x}\/)"
|
149
|
+
end
|
150
|
+
%r{href=\"?#{url}#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
151
|
+
end
|
152
|
+
|
153
|
+
def relativize_urls(doc, regex)
|
154
|
+
doc.output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"')
|
155
|
+
end
|
156
|
+
|
157
|
+
def relativize_absolute_urls(doc, regex, url)
|
158
|
+
doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/" + '\1"')
|
123
159
|
end
|
124
160
|
end
|
125
161
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-polyglot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Volin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
- - "~>"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '3.1'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.0'
|
30
|
-
- - "~>"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3.1'
|
33
27
|
description: Fast open source i18n plugin for Jekyll blogs.
|
34
28
|
email: untra.sam@gmail.com
|
35
29
|
executables: []
|
@@ -70,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
64
|
version: '0'
|
71
65
|
requirements: []
|
72
66
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.5.
|
67
|
+
rubygems_version: 2.5.1
|
74
68
|
signing_key:
|
75
69
|
specification_version: 4
|
76
70
|
summary: I18n plugin for Jekyll Blogs
|