jekyll-polyglot 1.3.3 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d7425cddd591dc3592b0ff61562a3283e333b2239a56f27f1a031e3267f33b4
4
- data.tar.gz: 6de2896cab126733b10f137b0a04e09bc73b1deb14e847b73012533f555fc2d2
3
+ metadata.gz: 37bbf459ea94dd1edd9fbef3aeb136db17a68b78b58a1b983d8bbc2cbe24727b
4
+ data.tar.gz: 5148941f48e63247596579130b8dbd8c407be7e326a2cc59b98725291d9f564d
5
5
  SHA512:
6
- metadata.gz: b91c4e63e27ca6e7d86d0dd2fe378e976abe8b1f3b5914f52399f5f6548b3187f9fdf96fc03c3ef142949428f88b5c5d772b62d01eb62dd36ae3f1aab704bd30
7
- data.tar.gz: f54dfc40d3a06ecac353b0f5225532a917d49bb5a28aca75355472d463aa9fef510f79330f6f2bfca90f04d2af5b226e0f3fa3a8702747c8a2269c64f995161a
6
+ metadata.gz: 303584c6688bf73fb8fc15a8c6bb160b0ae2b055744bdac4a3515455343a20dfbccff2d5713e74f2dca6235f0ed40e0b5d9a7f230a9a57f4b007ae2b0bd5fc8b
7
+ data.tar.gz: de6caa20d33315f63c8f7f6da8800e83aa2f77548a8d21ed8bf4e8c7529d16ee96813eaef4d46fc9885867c03ae3b48e9681af041fda8c21e645ed8fbf560aaa
data/README.md CHANGED
@@ -94,8 +94,7 @@ becomes
94
94
  ```
95
95
  Notice the link `<a href="/fr/menu/">...` directs to the french website.
96
96
 
97
- Even if you are falling back to `default_lang` page, relative links built on the *french* site will
98
- still link to *french* pages.
97
+ Even if you are falling back to `default_lang` page, relative links built on the *french* site will still link to *french* pages.
99
98
 
100
99
  #### Relativized Absolute Urls
101
100
  If you defined a site `url` in your `_config.yaml`, polyglot will automatically relativize absolute links pointing to your website directory:
@@ -112,7 +111,17 @@ becomes
112
111
  ```
113
112
 
114
113
  #### Disabling Url Relativizing
115
- 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.
114
+ _New in 1.4.0_
115
+ If you dont want a href attribute to be relativized (such as for making [a language switcher](https://github.com/untra/polyglot/blob/master/site/_includes/sidebar.html#L40)), you can use the `{% static_href %}href="..."{% endstatic_href %}` block tag.
116
+
117
+ ```html
118
+ <a {% static_href %}href="/about"{% endstatic_href %}>click this static link</a>
119
+ ```
120
+
121
+ that will generate `<a href="/about">click this static link</a>` which is what you would normally use to create a url unmangled by invisible language relativization.
122
+
123
+ _Previous (no longer) Recommendation:_
124
+ If you don't want aa url to be relativized, you can add a space explicitly into the href to prevent a url from being relativized by polyglot.
116
125
 
117
126
  For example, the following urls will be relativized:
118
127
 
@@ -128,7 +137,20 @@ href=" http://mywebsite.com/about"
128
137
  href=" /about"
129
138
  ```
130
139
 
131
- combine with a [html minifier](https://github.com/digitalsparky/jekyll-minifier) for a polished and production ready website.
140
+ combine with a [html minifier](https://github.com/digitalsparky/jekyll-minifier) for a polished and production ready website. -->
141
+
142
+ #### Exclusive site language generation
143
+ _New in 1.4.0_
144
+
145
+ If you want to control which languages a document can be generated for, you can specify `lang-exclusive: [ ]` frontmatter.
146
+ If you include this frontmatter in your post, it will only generate for the specified site languages.
147
+
148
+ For Example, the following frontmatter will only generate in the `en` and `fr` site language builds:
149
+ ```
150
+ ---
151
+ lang-exclusive: ['en', 'fr']
152
+ ---
153
+ ```
132
154
 
133
155
  #### Localized site.data
134
156
 
@@ -149,6 +171,7 @@ This plugin stands out from other I18n Jekyll plugins.
149
171
  - provides the liquid tag `{{ site.default_lang }}` to get the default_lang I18n string.
150
172
  - 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`.
151
173
  - provides the liquid tag `{{ I18n_Headers https://yourwebsite.com/ }}` to append SEO bonuses to your website.
174
+ - provides the liquid tag `{{ Unrelativized_Link href="/hello" }}` to make urls that do not get influenced by url correction regexs.
152
175
  - provides `site.data` localization for efficient rich text replacement.
153
176
  - a creator that will answer all of your questions and issues.
154
177
 
@@ -157,21 +180,36 @@ Jekyll-polyglot has a few spectacular [Search Engine Optimization techniques](ht
157
180
 
158
181
  ### Other Websites Built with Polyglot
159
182
  let us know if you make a multilingual blog you want to share:
160
- * [Polyglot project website](http://polyglot.untra.io)
161
- * [LogRhythm Corporate Website](http://logrhythm.com)
183
+ * [Polyglot project website](https://polyglot.untra.io)
184
+ * [LogRhythm Corporate Website](https://logrhythm.com)
162
185
  * [All Over Earth](https://allover.earth/)
163
186
  * [Hanare Cafe in Toshijima, Japan](https://hanarecafe.com)
164
187
  * [F-Droid](https://f-droid.org)
188
+ * [Ubuntu MATE](https://ubuntu-mate.org)
165
189
 
166
190
  ## Compatibility
167
- Currently supports Jekyll 3.0 , and Jekyll 4.0 (for the most part)
191
+ Currently supports Jekyll 3.0 , and Jekyll 4.0
168
192
 
169
- * *Windows users will need to disable parallel_localization on their machines by setting `parallel_localization: false` in the `_config.yml`
170
- * In Jekyll 4.0 , SCSS source maps will generate improperly due to how Polyglot operates. The workaround is to disable the CSS sourcemaps. Adding rhe following to your `config.yml` will disable sourcemap generation:
193
+ * Windows users will need to disable parallel_localization on their machines by setting `parallel_localization: false` in the `_config.yml`
194
+ * In Jekyll 4.0 , SCSS source maps will generate improperly due to how Polyglot operates. The workaround is to disable the CSS sourcemaps. Adding the following to your `config.yml` will disable sourcemap generation:
171
195
  ```yaml
172
196
  sass:
173
197
  sourcemap: never
174
198
  ```
175
199
 
200
+ ## Contributions
201
+ Please! I need all the support I can get! 🙏
202
+ But for real I would appreciate any contributions and support. This started as an open-source side-project and has gotten bigger than I'd ever imagine!
203
+ If you have something you'd like to contribute to jekyll-polyglot, please open a PR!
204
+
205
+ ## Roadmap
206
+ [ ] - **site language**: portuguese `pt_BR` `pt_PT`
207
+ [ ] - **site language**: arabic `ar`
208
+ [ ] - **site language**: japanese `ja`
209
+ [ ] - **site language**: russian `ru`
210
+ [ ] - **site language**: korean `ko`
211
+ [ ] - **site language**: hebrew `he`
212
+ [ ] - get whitelisted as an official github-pages jekyll plugin
213
+
176
214
  ## Copyright
177
- Copyright (c) Samuel Volin 2020. License: MIT
215
+ Copyright (c) Samuel Volin 2021. License: MIT
@@ -1,3 +1,2 @@
1
- require_relative 'hooks/assets-toggle'
2
1
  require_relative 'hooks/coordinate'
3
2
  require_relative 'hooks/process'
@@ -1,7 +1,8 @@
1
1
  module Jekyll
2
2
  module Polyglot
3
3
  module Liquid
4
- require_relative 'liquid/tags/i18n-headers'
4
+ require_relative 'liquid/tags/i18n_headers'
5
+ require_relative 'liquid/tags/static_href'
5
6
  end
6
7
  end
7
8
  end
@@ -18,6 +18,7 @@ module Jekyll
18
18
  "href=\" #{site_url}#{permalink}\"/>\n"
19
19
  site.languages.each do |lang|
20
20
  next if lang == site.default_lang
21
+
21
22
  i18n += "<link rel=\"alternate\" hreflang=\"#{lang}\" "\
22
23
  "href=\"#{site_url}/#{lang}#{permalink}\"/>\n"
23
24
  end
@@ -29,3 +30,4 @@ module Jekyll
29
30
  end
30
31
 
31
32
  Liquid::Template.register_tag('I18n_Headers', Jekyll::Polyglot::Liquid::I18nHeadersTag)
33
+ Liquid::Template.register_tag('i18n_headers', Jekyll::Polyglot::Liquid::I18nHeadersTag)
@@ -0,0 +1,27 @@
1
+ module Jekyll
2
+ module Polyglot
3
+ module Liquid
4
+ class StaticHrefTag < :: Liquid::Block
5
+ def initialize(tag_name, params, tokens)
6
+ super
7
+ end
8
+
9
+ def render(context)
10
+ text = super
11
+ href_attrs = text.strip.split '='
12
+ valid = (href_attrs.length == 2 && href_attrs[0] == 'href') && href_attrs[1].start_with?('"') && href_attrs[1].end_with?('"')
13
+ unless valid
14
+ raise Liquid::SyntaxError, "static_href parameters must include match href=\"...\" attribute param, eg. href=\"http://example.com\, href=\"/about\", href=\"/\" , instead got:\n#{text}"
15
+ end
16
+
17
+ href_value = href_attrs[1]
18
+ # href writes out as ferh="..." explicitly wrong, to be cauaght by seperate processor for nonrelativized links
19
+ "ferh=#{href_value}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Liquid::Template.register_tag('Static_Href', Jekyll::Polyglot::Liquid::StaticHrefTag)
27
+ Liquid::Template.register_tag('static_href', Jekyll::Polyglot::Liquid::StaticHrefTag)
@@ -10,18 +10,17 @@ module Jekyll
10
10
  @parallel_localization = config.fetch('parallel_localization', true)
11
11
  @lang_from_path = config.fetch('lang_from_path', false)
12
12
  @exclude_from_localization = config.fetch('exclude_from_localization', []).map do |e|
13
- if File.directory?(e) and e[-1] != '/'
13
+ if File.directory?(e) && e[-1] != '/'
14
14
  e + '/'
15
15
  else
16
16
  e
17
17
  end
18
18
  end
19
-
20
19
  end
21
20
 
22
21
  def fetch_languages
23
22
  @default_lang = config.fetch('default_lang', 'en')
24
- @languages = config.fetch('languages', ['en'])
23
+ @languages = config.fetch('languages', ['en']).uniq
25
24
  @keep_files += (@languages - [@default_lang])
26
25
  @active_lang = @default_lang
27
26
  @lang_vars = config.fetch('lang_vars', [])
@@ -102,11 +101,11 @@ module Jekyll
102
101
  end
103
102
  segments = doc.relative_path.split('/')
104
103
  if doc.relative_path[0] == '_' \
105
- and segments.length > 2 \
106
- and segments[1] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
104
+ && segments.length > 2 \
105
+ && segments[1] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
107
106
  return segments[1]
108
107
  elsif segments.length > 1 \
109
- and segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
108
+ && segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
110
109
  return segments[0]
111
110
  else
112
111
  return nil
@@ -122,10 +121,16 @@ module Jekyll
122
121
  approved = {}
123
122
  docs.each do |doc|
124
123
  lang = doc.data['lang'] || derive_lang_from_path(doc) || @default_lang
124
+ lang_exclusive = doc.data['lang-exclusive'] || []
125
125
  url = doc.url.gsub(regex, '/')
126
126
  doc.data['permalink'] = url
127
+ # skip this document if it has already been processed
127
128
  next if @file_langs[url] == @active_lang
129
+ # skip this document if it has a fallback and it isn't assigned to the active language
128
130
  next if @file_langs[url] == @default_lang && lang != @active_lang
131
+ # skip this document if it has lang-exclusive defined and the active_lang is not included
132
+ next if !lang_exclusive.empty? && !lang_exclusive.include?(@active_lang)
133
+
129
134
  approved[url] = doc
130
135
  @file_langs[url] = lang
131
136
  end
@@ -134,14 +139,19 @@ module Jekyll
134
139
 
135
140
  # performs any necesarry operations on the documents before rendering them
136
141
  def process_documents(docs)
137
- return if @active_lang == @default_lang
142
+ # return if @active_lang == @default_lang
143
+
138
144
  url = config.fetch('url', false)
139
- rel_regex = relative_url_regex
140
- abs_regex = absolute_url_regex(url)
145
+ rel_regex = relative_url_regex(false)
146
+ abs_regex = absolute_url_regex(url, false)
147
+ non_rel_regex = relative_url_regex(true)
148
+ non_abs_regex = absolute_url_regex(url, true)
141
149
  docs.each do |doc|
142
- relativize_urls(doc, rel_regex)
150
+ unless @active_lang == @default_lang then relativize_urls(doc, rel_regex) end
151
+ correct_nonrelativized_urls(doc, non_rel_regex)
143
152
  if url
144
- then relativize_absolute_urls(doc, abs_regex, url)
153
+ unless @active_lang == @default_lang then relativize_absolute_urls(doc, abs_regex, url) end
154
+ correct_nonrelativized_absolute_urls(doc, non_abs_regex, url)
145
155
  end
146
156
  end
147
157
  end
@@ -159,29 +169,39 @@ module Jekyll
159
169
  end
160
170
 
161
171
  # a regex that matches relative urls in a html document
162
- # matches href="baseurl/foo/bar-baz" and others like it
172
+ # matches href="baseurl/foo/bar-baz" href="/foo/bar-baz" and others like it
163
173
  # avoids matching excluded files. prepare makes sure
164
174
  # that all @exclude dirs have a trailing slash.
165
- def relative_url_regex
175
+ def relative_url_regex(disabled = false)
166
176
  regex = ''
167
- (@exclude).each do |x|
168
- regex += "(?!#{x})"
169
- end
170
- (@languages).each do |x|
171
- regex += "(?!#{x}\/)"
177
+ unless disabled
178
+ @exclude.each do |x|
179
+ regex += "(?!#{x})"
180
+ end
181
+ @languages.each do |x|
182
+ regex += "(?!#{x}\/)"
183
+ end
172
184
  end
173
- %r{href=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
185
+ start = disabled ? 'ferh' : 'href'
186
+ %r{#{start}=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
174
187
  end
175
188
 
176
- def absolute_url_regex(url)
189
+ # a regex that matches absolute urls in a html document
190
+ # matches href="http://baseurl/foo/bar-baz" and others like it
191
+ # avoids matching excluded files. prepare makes sure
192
+ # that all @exclude dirs have a trailing slash.
193
+ def absolute_url_regex(url, disabled = false)
177
194
  regex = ''
178
- (@exclude).each do |x|
179
- regex += "(?!#{x})"
180
- end
181
- (@languages).each do |x|
182
- regex += "(?!#{x}\/)"
195
+ unless disabled
196
+ @exclude.each do |x|
197
+ regex += "(?!#{x})"
198
+ end
199
+ @languages.each do |x|
200
+ regex += "(?!#{x}\/)"
201
+ end
183
202
  end
184
- %r{href=\"?#{url}#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
203
+ start = disabled ? 'ferh' : 'href'
204
+ %r{#{start}=\"?#{url}#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
185
205
  end
186
206
 
187
207
  def relativize_urls(doc, regex)
@@ -195,5 +215,17 @@ module Jekyll
195
215
 
196
216
  doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/" + '\1"')
197
217
  end
218
+
219
+ def correct_nonrelativized_absolute_urls(doc, regex, url)
220
+ return if doc.output.nil?
221
+
222
+ doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/" + '\1"')
223
+ end
224
+
225
+ def correct_nonrelativized_urls(doc, regex)
226
+ return if doc.output.nil?
227
+
228
+ doc.output.gsub!(regex, "href=\"#{@baseurl}/" + '\1"')
229
+ end
198
230
  end
199
231
  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.3.3
4
+ version: 1.4.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: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2021-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -39,12 +39,13 @@ files:
39
39
  - lib/jekyll/polyglot/hooks/coordinate.rb
40
40
  - lib/jekyll/polyglot/hooks/process.rb
41
41
  - lib/jekyll/polyglot/liquid.rb
42
- - lib/jekyll/polyglot/liquid/tags/i18n-headers.rb
42
+ - lib/jekyll/polyglot/liquid/tags/i18n_headers.rb
43
+ - lib/jekyll/polyglot/liquid/tags/static_href.rb
43
44
  - lib/jekyll/polyglot/patches.rb
44
45
  - lib/jekyll/polyglot/patches/jekyll/site.rb
45
46
  - lib/jekyll/polyglot/patches/jekyll/static_file.rb
46
47
  - lib/jekyll/polyglot/version.rb
47
- homepage: http://untra.github.io/polyglot
48
+ homepage: https://polyglot.untra.io/
48
49
  licenses:
49
50
  - MIT
50
51
  metadata: {}
@@ -56,14 +57,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
57
  requirements:
57
58
  - - ">="
58
59
  - !ruby/object:Gem::Version
59
- version: '0'
60
+ version: 2.4.0
60
61
  required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  requirements:
62
63
  - - ">="
63
64
  - !ruby/object:Gem::Version
64
- version: '0'
65
+ version: 2.7.0
65
66
  requirements: []
66
- rubygems_version: 3.1.2
67
+ rubygems_version: 3.2.7
67
68
  signing_key:
68
69
  specification_version: 4
69
70
  summary: I18n plugin for Jekyll Blogs