jekyll-polyglot 1.2.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/jekyll/polyglot/patches/jekyll/site.rb +10 -5
- data/lib/jekyll/polyglot/version.rb +1 -1
- metadata +9 -10
- data/lib/polyglot.rb +0 -158
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b617e95642f5c0337a8b7dd35416aad11a5dee21
|
4
|
+
data.tar.gz: 83af2f5194ba33e22e9a8f77f7996af6f79fd07d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a3f519eb89584149730065114d513f06829964d7b0a01debf42599c586250a04a8b26352e4ab099a696bc5e66bc365abaf110ae9bb411f738181fcaee07409d
|
7
|
+
data.tar.gz: 5844c839e5c9731782afd0323179c513d7c057d428e51d086b5bfda889ac0bf14fa2421bb3615075eabbb89d157eddfc95f4a6cc730ed443e339ce0b58d89903
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
:abc: Polyglot
|
2
2
|
---
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/jekyll-polyglot.svg)](https://badge.fury.io/rb/jekyll-polyglot)
|
4
|
+
[![Build Status](https://travis-ci.org/untra/polyglot.svg?branch=master)](https://travis-ci.org/untra/polyglot)
|
4
5
|
|
5
6
|
__Polyglot__ is a fast, painless, open-source internationalization plugin for [Jekyll](http://jekyllrb.com) blogs. Polyglot is easy to setup and use with any Jekyll project, and it scales to the languages you want to support. With fallback support for missing content, automatic url relativization, and powerful SEO tools, Polyglot allows any multi-language jekyll blog to focus on content without the cruft.
|
6
7
|
|
@@ -11,7 +12,7 @@ Jekyll doesn't provide native support for multi-language blogs. This plugin was
|
|
11
12
|
`gem install jekyll-polyglot` and add jekyll-polyglot to your `_config.yml` like the following:
|
12
13
|
```yml
|
13
14
|
gems:
|
14
|
-
- jekyll-
|
15
|
+
- jekyll-polyglot
|
15
16
|
```
|
16
17
|
|
17
18
|
## Configuration
|
@@ -96,7 +97,7 @@ This plugin stands out from other I18n Jekyll plugins.
|
|
96
97
|
- provides the liquid tag `{{ site.languages }}` to get an array of your I18n strings.
|
97
98
|
- provides the liquid tag `{{ site.default_lang }}` to get the default_lang I18n string.
|
98
99
|
- provides the liquid tag `{{ site.active_lang }}` to get the I18n language string the website was built for.
|
99
|
-
- provides the liquid tag `{{
|
100
|
+
- provides the liquid tag `{{ I18n_Headers https://yourwebsite.com/ }}` to append SEO bonuses to your website.
|
100
101
|
- A creator that will answer all of your questions and issues.
|
101
102
|
|
102
103
|
## SEO Recipes
|
@@ -6,11 +6,11 @@ module Jekyll
|
|
6
6
|
|
7
7
|
def prepare
|
8
8
|
@file_langs = {}
|
9
|
-
@default_lang = config
|
10
|
-
@languages = config
|
11
|
-
@parallel_localization = config
|
9
|
+
@default_lang = config.fetch('default_lang', 'en')
|
10
|
+
@languages = config.fetch('languages', ['en'])
|
11
|
+
@parallel_localization = config.fetch('parallel_localization', true)
|
12
12
|
(@keep_files << @languages - [@default_lang]).flatten!
|
13
|
-
@exclude_from_localization = config
|
13
|
+
@exclude_from_localization = config.fetch('exclude_from_localization', [])
|
14
14
|
@active_lang = @default_lang
|
15
15
|
end
|
16
16
|
|
@@ -58,9 +58,14 @@ module Jekyll
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def process_active_language
|
61
|
+
old_dest = @dest
|
62
|
+
old_exclude = @exclude
|
63
|
+
@file_langs = {}
|
61
64
|
@dest = @dest + '/' + @active_lang
|
62
65
|
@exclude += @exclude_from_localization
|
63
66
|
process_orig
|
67
|
+
@dest = old_dest
|
68
|
+
@exclude = old_exclude
|
64
69
|
end
|
65
70
|
|
66
71
|
# assigns natural permalinks to documents and prioritizes documents with
|
@@ -107,7 +112,7 @@ module Jekyll
|
|
107
112
|
@exclude.each do |x|
|
108
113
|
regex += "(?!#{x}\/)"
|
109
114
|
end
|
110
|
-
%r{href=\"#{@baseurl}\/((?:#{regex}[^,'\"\s
|
115
|
+
%r{href=\"#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
111
116
|
end
|
112
117
|
|
113
118
|
def relativize_urls(doc)
|
metadata
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-polyglot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Volin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
- -
|
20
|
+
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '3.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
|
-
- -
|
30
|
+
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.1'
|
33
33
|
description: Fast open source i18n plugin for Jekyll blogs.
|
@@ -50,7 +50,6 @@ files:
|
|
50
50
|
- lib/jekyll/polyglot/patches/jekyll/site.rb
|
51
51
|
- lib/jekyll/polyglot/patches/jekyll/static_file.rb
|
52
52
|
- lib/jekyll/polyglot/version.rb
|
53
|
-
- lib/polyglot.rb
|
54
53
|
homepage: http://untra.github.io/polyglot
|
55
54
|
licenses:
|
56
55
|
- MIT
|
@@ -61,17 +60,17 @@ require_paths:
|
|
61
60
|
- lib
|
62
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
62
|
requirements:
|
64
|
-
- -
|
63
|
+
- - '>='
|
65
64
|
- !ruby/object:Gem::Version
|
66
65
|
version: '0'
|
67
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
67
|
requirements:
|
69
|
-
- -
|
68
|
+
- - '>='
|
70
69
|
- !ruby/object:Gem::Version
|
71
70
|
version: '0'
|
72
71
|
requirements: []
|
73
72
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.6.6
|
75
74
|
signing_key:
|
76
75
|
specification_version: 4
|
77
76
|
summary: I18n plugin for Jekyll Blogs
|
data/lib/polyglot.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
# Jekyll Polyglot v1.2.0
|
2
|
-
# Fast, painless, open source i18n plugin for Jekyll 3.0 Blogs.
|
3
|
-
# author: Samuel Volin (@untra)
|
4
|
-
# github: https://github.com/untra/polyglot
|
5
|
-
# license: MIT
|
6
|
-
include Process
|
7
|
-
module Jekyll
|
8
|
-
# Alteration to Jekyll Site class
|
9
|
-
# provides aliased methods to direct site.write to output into seperate
|
10
|
-
# language folders
|
11
|
-
class Site
|
12
|
-
attr_reader :default_lang, :languages, :exclude_from_localization
|
13
|
-
attr_accessor :file_langs, :active_lang
|
14
|
-
|
15
|
-
def prepare
|
16
|
-
@file_langs = {}
|
17
|
-
@default_lang = config['default_lang'] || 'en'
|
18
|
-
@languages = config['languages'] || ['en']
|
19
|
-
@parallel_localization = config['parallel_localization'] || true
|
20
|
-
(@keep_files << @languages - [@default_lang]).flatten!
|
21
|
-
@exclude_from_localization = config['exclude_from_localization'] || []
|
22
|
-
@active_lang = @default_lang
|
23
|
-
end
|
24
|
-
|
25
|
-
alias_method :process_orig, :process
|
26
|
-
def process
|
27
|
-
prepare
|
28
|
-
if @parallel_localization
|
29
|
-
pids = {}
|
30
|
-
languages.each do |lang|
|
31
|
-
pids[lang] = fork do
|
32
|
-
process_language lang
|
33
|
-
end
|
34
|
-
end
|
35
|
-
Signal.trap('INT') do
|
36
|
-
languages.each do |lang|
|
37
|
-
puts "Killing #{pids[lang]} : #{lang}"
|
38
|
-
kill('INT', pids[lang])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
languages.each do |lang|
|
42
|
-
waitpid pids[lang]
|
43
|
-
detach pids[lang]
|
44
|
-
end
|
45
|
-
else
|
46
|
-
languages.each do |lang|
|
47
|
-
process_language lang
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
alias_method :site_payload_orig, :site_payload
|
53
|
-
def site_payload
|
54
|
-
payload = site_payload_orig
|
55
|
-
payload['site']['default_lang'] = default_lang
|
56
|
-
payload['site']['languages'] = languages
|
57
|
-
payload['site']['active_lang'] = active_lang
|
58
|
-
payload
|
59
|
-
end
|
60
|
-
|
61
|
-
def process_language(lang)
|
62
|
-
@active_lang = lang
|
63
|
-
config['active_lang'] = @active_lang
|
64
|
-
return process_orig if @active_lang == @default_lang
|
65
|
-
process_active_language
|
66
|
-
end
|
67
|
-
|
68
|
-
def process_active_language
|
69
|
-
@dest = @dest + '/' + @active_lang
|
70
|
-
@exclude += @exclude_from_localization
|
71
|
-
process_orig
|
72
|
-
end
|
73
|
-
|
74
|
-
# assigns natural permalinks to documents and prioritizes documents with
|
75
|
-
# active_lang languages over others
|
76
|
-
def coordinate_documents(docs)
|
77
|
-
regex = document_url_regex
|
78
|
-
approved = {}
|
79
|
-
docs.each do |doc|
|
80
|
-
lang = doc.data['lang'] || @default_lang
|
81
|
-
url = doc.url.gsub(regex, '/')
|
82
|
-
doc.data['permalink'] = url
|
83
|
-
next if @file_langs[url] == @active_lang
|
84
|
-
next if @file_langs[url] == @default_lang && lang != @active_lang
|
85
|
-
approved[url] = doc
|
86
|
-
@file_langs[url] = lang
|
87
|
-
end
|
88
|
-
approved.values
|
89
|
-
end
|
90
|
-
|
91
|
-
# performs any necesarry operations on the documents before rendering them
|
92
|
-
def process_documents(docs)
|
93
|
-
docs.each do |doc|
|
94
|
-
relativize_urls doc
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# a regex that matches urls or permalinks with i18n prefixes or suffixes
|
99
|
-
# matches /en/foo , .en/foo , foo.en/ and other simmilar default urls
|
100
|
-
# made by jekyll when parsing documents without explicitly set permalinks
|
101
|
-
def document_url_regex
|
102
|
-
regex = ''
|
103
|
-
@languages.each do |lang|
|
104
|
-
regex += "([\/\.]#{lang}[\/\.])|"
|
105
|
-
end
|
106
|
-
regex.chomp! '|'
|
107
|
-
%r{#{regex}}
|
108
|
-
end
|
109
|
-
|
110
|
-
# a regex that matches relative urls in a html document
|
111
|
-
# matches href="baseurl/foo/bar-baz" and others like it
|
112
|
-
def relative_url_regex
|
113
|
-
regex = ''
|
114
|
-
@exclude.each do |x|
|
115
|
-
regex += "(?!#{x}\/)"
|
116
|
-
end
|
117
|
-
# regex that looks for all relative urls except for excluded files
|
118
|
-
%r{href=\"#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#-]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
119
|
-
end
|
120
|
-
|
121
|
-
def relativize_urls(doc)
|
122
|
-
return if @active_lang == @default_lang
|
123
|
-
doc.output.gsub!(relative_url_regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"')
|
124
|
-
end
|
125
|
-
|
126
|
-
# hook to coordinate blog posts and pages into distinct urls,
|
127
|
-
# and remove duplicate multilanguage posts and pages
|
128
|
-
Jekyll::Hooks.register :site, :post_read do |site|
|
129
|
-
site.posts.docs = site.coordinate_documents(site.posts.docs)
|
130
|
-
site.pages = site.coordinate_documents(site.pages)
|
131
|
-
end
|
132
|
-
|
133
|
-
# hook to make a call to process rendered documents,
|
134
|
-
Jekyll::Hooks.register :site, :post_render do |site|
|
135
|
-
site.process_documents(site.posts.docs)
|
136
|
-
site.process_documents(site.pages)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Alteration to Jekyll StaticFile
|
141
|
-
# provides aliased methods to direct write to skip files
|
142
|
-
# excluded from localization
|
143
|
-
class StaticFile
|
144
|
-
alias_method :write_orig, :write
|
145
|
-
def write(dest)
|
146
|
-
return false if exclude_from_localization?
|
147
|
-
write_orig(dest)
|
148
|
-
end
|
149
|
-
|
150
|
-
def exclude_from_localization?
|
151
|
-
return false if @site.active_lang == @site.default_lang
|
152
|
-
@site.exclude_from_localization.each do |e|
|
153
|
-
return true if relative_path[1..-1].start_with?(e)
|
154
|
-
end
|
155
|
-
false
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|