jekyll-polyglot 1.5.1 → 1.7.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
  SHA256:
3
- metadata.gz: 575ea909b15958d5cddafc881fb4342326f205bf9fafbce8a79981133c4a15e5
4
- data.tar.gz: 1e881bdd502d11c0b3c171b7a4db7670d314f32ea0fe192a9a3fffbd47b1e1c2
3
+ metadata.gz: ab5c70c038d85dbe9936e2a3bd021d75f860a01c272c2650eb6f77e8b386d141
4
+ data.tar.gz: 8d4e4656cbd532277bf708f71fabc3c2b63ee042110862c3aea64ea570434b78
5
5
  SHA512:
6
- metadata.gz: 15cd5d7b397550143957d9ebf7404c35c241bf4357f75f6fa7f44bde56034d631a3ea6ee0e7e3d80a53a9f8abcb99a5ee5b8685d125b63e08369db9cae28c1d7
7
- data.tar.gz: f837a8c341809322d210a90098d9016d6303865a665a832abf38443912f61c969a1e5c08dc4b2206f0ef47712ce24e208202b6c46e2d34ceaa1066c6ff19aeef
6
+ metadata.gz: 508f349097b516f5d4d7f5e794e1e367ba1a64035191793b184314da8f3b35708047df73bc469a740a6042571b97d91802149f259e81581d741ff88a44bcd389
7
+ data.tar.gz: e88b634466df95b6b11c7cc04c8a3b5e1b157bfa1740094e1f2bfae14f1797c1e6d1d40cf80d787a5c8070874f6bf929aa3b86c0607a10811cc09017cd424908
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 - 2022 Samuel Volin
1
+ Copyright (c) 2015 - 2023 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
@@ -50,6 +50,8 @@ or whatever appropriate [I18n language code](https://developer.chrome.com/websto
50
50
  the page should build for. And you're done. Ideally, when designing your site, you should
51
51
  organize files by their relative urls.
52
52
 
53
+ You can see how the live polyglot website [configures and supports multiple languages](https://github.com/untra/polyglot/blob/master/site/_config.yml#L28-L37), and examples of [community](https://github.com/untra/polyglot/pull/155) [language](https://github.com/untra/polyglot/pull/167) [contributions](https://github.com/untra/polyglot/pull/177).
54
+
53
55
  Polyglot works by associating documents with similar permalinks to the `lang` specified in their frontmatter. Files that correspond to similar routes should have identical permalinks. If you don't provide a permalink for a post, ___make sure you are consistent___ with how you place and name corresponding files:
54
56
  ```
55
57
  _posts/2010-03-01-salad-recipes-en.md
@@ -66,6 +68,37 @@ In short:
66
68
  * Don't overthink it, :wink:
67
69
 
68
70
 
71
+ #### Using different permalinks per language
72
+ _New in 1.7.0_
73
+
74
+ Optionally, for those who may want different URLs on different languages, translations may be identified by specifying a `page_id` in the frontmatter.
75
+
76
+ If available, polyglot will use `page_id` to identify the page, and will default to the `permalink` otherwise.
77
+
78
+ As an example, you may have an about page located in `/about/` while being in `/acerca-de/` in Spanish just by changing the permalink and specifying a `page_id` that will link the files as translations:
79
+ ```md
80
+ ---
81
+ title: About
82
+ permalink: /about
83
+ lang: en
84
+ page_id: about
85
+ ---
86
+ This is us!
87
+ ```
88
+
89
+ ```md
90
+ ---
91
+ title: Acerca de
92
+ permalink: /acerca-de
93
+ lang: es
94
+ page_id: about
95
+ ---
96
+ Estos somos nosotros!
97
+ ```
98
+
99
+ Additionally, if you are also using the `jekyll-redirect-from` plugin, pages coordinated this way will automatically have redirects created between pages.
100
+ So `/es/about` will automatically redirect to `/es/acerca-de` and `/acerca-de` can redirect to `/about`. If you use this approach, be sure to also employ a customized [redirect.html](https://github.com/untra/polyglot/blob/master/site/_layouts/redirect.html).
101
+
69
102
  #### Fallback Language Support
70
103
  Lets say you are building your website. You have an `/about/` page written in *english*, *german* and
71
104
  *swedish*. You are also supporting a *french* website, but you never designed a *french* version of your `/about/` page!
@@ -142,7 +175,7 @@ lang-exclusive: ['en', 'fr']
142
175
  #### Machine-aware site building
143
176
  _New in 1.5.0_
144
177
 
145
- Polyglot will only start builds after it confirms there is a cpu core ready to accept the build thread. This ensures that jekyll will build large sites efficiently streamlining build processes instead of overloading machines with process thrash.
178
+ Polyglot will only start builds after it confirms there is a cpu core ready to accept the build thread. This ensures that jekyll will build large sites efficiently, streamlining build processes instead of overloading machines with process thrash.
146
179
 
147
180
  #### Localized site.data
148
181
 
@@ -155,6 +188,13 @@ This plugin makes modifications to existing Jekyll classes and modules, namely `
155
188
 
156
189
  `Jekyll::Site.process` is the entry point for the Jekyll build process. Take care whatever other plugins you use do not also attempt to overwrite this method. You may have problems.
157
190
 
191
+
192
+ ### Writing Tests and Debugging
193
+ _:wave: I need assistance with modern ruby best practices for test maintenance with rake and rspec. If you got the advice I have the ears._
194
+
195
+ Tests are run with `bundle exec rake`. Tests are in the `/spec` directory, and test failure output detail can be examined in the `rspec.xml` file.
196
+
197
+
158
198
  ## Features
159
199
  This plugin stands out from other I18n Jekyll plugins.
160
200
  - automatically corrects your relative links, keeping your *french* visitors on your *french* website, even when content has to fallback to the `default_lang`.
@@ -180,10 +220,11 @@ Feel free to open a PR and list your multilingual blog here you may want to shar
180
220
  * [F-Droid](https://f-droid.org)
181
221
  * [Ubuntu MATE](https://ubuntu-mate.org)
182
222
  * [Leo3418 blog](https://leo3418.github.io/)
223
+ * [Gaphor](https://gaphor.org)
224
+ * [Yi Yunseok's personal blog website](https://Yi-Yunseok.GitHub.io)
183
225
 
184
226
  ## Compatibility
185
227
  Currently supports Jekyll 3.0 , and Jekyll 4.0
186
-
187
228
  * Windows users will need to disable parallel_localization on their machines by setting `parallel_localization: false` in the `_config.yml`
188
229
  * 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:
189
230
  ```yaml
@@ -194,20 +235,23 @@ sass:
194
235
  ## Contributions
195
236
  Please! I need all the support I can get! 🙏
196
237
 
197
- 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!
238
+ But for real I would appreciate any code contributions and support. This started as an open-source side-project and has gotten bigger than I'd ever imagine!
198
239
  If you have something you'd like to contribute to jekyll-polyglot, please open a PR!
199
240
 
200
241
 
201
242
  ## 2.0 Roadmap
202
- * [ ] - **site language**: portuguese `pt_BR` `pt_PT`
243
+ * [ ] - **site language**: portuguese Brazil `pt-BR` `pt-PT`
244
+ * [ ] - **site language**: portuguese Portugal `pt-BR` `pt-PT`
203
245
  * [ ] - **site language**: arabic `ar`
204
246
  * [ ] - **site language**: japanese `ja`
205
247
  * [x] - **site language**: russian `ru`
206
248
  * [x] - **site language**: dutch `nl`
207
- * [ ] - **site language**: korean `ko`
249
+ * [x] - **site language**: korean `ko`
208
250
  * [x] - **site language**: hebrew `he`
251
+ * [x] - **site language**: chinese China `zh-CN`
252
+ * [ ] - **site language**: chinese Taiwan `zh_TW`
209
253
  * [ ] - get whitelisted as an official github-pages jekyll plugin
210
254
  * [x] - update CI provider
211
255
 
212
256
  ## Copyright
213
- Copyright (c) Samuel Volin 2022. License: MIT
257
+ Copyright (c) Samuel Volin 2023. License: MIT
@@ -13,7 +13,7 @@ module Jekyll
13
13
  @lang_from_path = config.fetch('lang_from_path', false)
14
14
  @exclude_from_localization = config.fetch('exclude_from_localization', []).map do |e|
15
15
  if File.directory?(e) && e[-1] != '/'
16
- e + '/'
16
+ "#{e}/"
17
17
  else
18
18
  e
19
19
  end
@@ -28,7 +28,7 @@ module Jekyll
28
28
  @lang_vars = config.fetch('lang_vars', [])
29
29
  end
30
30
 
31
- alias_method :process_orig, :process
31
+ alias process_orig process
32
32
  def process
33
33
  prepare
34
34
  all_langs = (@languages + [@default_lang]).uniq
@@ -50,6 +50,7 @@ module Jekyll
50
50
  rescue Interrupt
51
51
  all_langs.each do |lang|
52
52
  next unless pids.key? lang
53
+
53
54
  puts "Killing #{pids[lang]} : #{lang}"
54
55
  kill('INT', pids[lang])
55
56
  end
@@ -61,7 +62,7 @@ module Jekyll
61
62
  end
62
63
  end
63
64
 
64
- alias_method :site_payload_orig, :site_payload
65
+ alias site_payload_orig site_payload
65
66
  def site_payload
66
67
  payload = site_payload_orig
67
68
  payload['site']['default_lang'] = default_lang
@@ -81,7 +82,8 @@ module Jekyll
81
82
  end
82
83
  if @active_lang == @default_lang
83
84
  then process_default_language
84
- else process_active_language
85
+ else
86
+ process_active_language
85
87
  end
86
88
  end
87
89
 
@@ -95,7 +97,7 @@ module Jekyll
95
97
  old_dest = @dest
96
98
  old_exclude = @exclude
97
99
  @file_langs = {}
98
- @dest = @dest + '/' + @active_lang
100
+ @dest = "#{@dest}/#{@active_lang}"
99
101
  @exclude += @exclude_from_localization
100
102
  process_orig
101
103
  @dest = old_dest
@@ -103,9 +105,10 @@ module Jekyll
103
105
  end
104
106
 
105
107
  def derive_lang_from_path(doc)
106
- if !@lang_from_path
108
+ unless @lang_from_path
107
109
  return nil
108
110
  end
111
+
109
112
  segments = doc.relative_path.split('/')
110
113
  if doc.relative_path[0] == '_' \
111
114
  && segments.length > 2 \
@@ -114,9 +117,9 @@ module Jekyll
114
117
  elsif segments.length > 1 \
115
118
  && segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
116
119
  return segments[0]
117
- else
118
- return nil
119
120
  end
121
+
122
+ nil
120
123
  end
121
124
 
122
125
  # assigns natural permalinks to documents and prioritizes documents with
@@ -130,20 +133,39 @@ module Jekyll
130
133
  lang = doc.data['lang'] || derive_lang_from_path(doc) || @default_lang
131
134
  lang_exclusive = doc.data['lang-exclusive'] || []
132
135
  url = doc.url.gsub(regex, '/')
133
- doc.data['permalink'] = url
136
+ page_id = doc.data['page_id'] || url
137
+ doc.data['permalink'] = url unless defined?(doc.data['permalink'])
138
+
139
+ # skip entirely if nothing to check
140
+ next if @file_langs.nil?
134
141
  # skip this document if it has already been processed
135
- next if @file_langs[url] == @active_lang
142
+ next if @file_langs[page_id] == @active_lang
136
143
  # skip this document if it has a fallback and it isn't assigned to the active language
137
- next if @file_langs[url] == @default_lang && lang != @active_lang
144
+ next if @file_langs[page_id] == @default_lang && lang != @active_lang
138
145
  # skip this document if it has lang-exclusive defined and the active_lang is not included
139
146
  next if !lang_exclusive.empty? && !lang_exclusive.include?(@active_lang)
140
147
 
141
- approved[url] = doc
142
- @file_langs[url] = lang
148
+ approved[page_id] = doc
149
+ @file_langs[page_id] = lang
143
150
  end
151
+ approved.values.each {|doc| assignPageRedirects(doc, docs) }
144
152
  approved.values
145
153
  end
146
154
 
155
+ def assignPageRedirects(doc, docs)
156
+ pageId = doc.data['page_id']
157
+ if !pageId.nil? && !pageId.empty?
158
+ lang = doc.data['lang'] || derive_lang_from_path(doc) || @default_lang
159
+ langPrefix = lang === @default_lang ? '' : "#{lang}/"
160
+ redirectDocs = docs.select do |dd|
161
+ doclang = dd.data['lang'] || derive_lang_from_path(dd) || @default_lang
162
+ dd.data['page_id'] == pageId && doclang != lang && dd.data['permalink'] != doc.data['permalink']
163
+ end
164
+ redirects = redirectDocs.map { |dd| dd.data['permalink'] }
165
+ doc.data['redirect_from'] = redirects
166
+ end
167
+ end
168
+
147
169
  # performs any necesarry operations on the documents before rendering them
148
170
  def process_documents(docs)
149
171
  # return if @active_lang == @default_lang
@@ -168,11 +190,11 @@ module Jekyll
168
190
  # made by jekyll when parsing documents without explicitly set permalinks
169
191
  def document_url_regex
170
192
  regex = ''
171
- @languages.each do |lang|
193
+ (@languages || []).each do |lang|
172
194
  regex += "([\/\.]#{lang}[\/\.])|"
173
195
  end
174
196
  regex.chomp! '|'
175
- %r{#{regex}}
197
+ /#{regex}/
176
198
  end
177
199
 
178
200
  # a regex that matches relative urls in a html document
@@ -190,7 +212,7 @@ module Jekyll
190
212
  end
191
213
  end
192
214
  start = disabled ? 'ferh' : 'href'
193
- %r{#{start}=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
215
+ %r{#{start}="?#{@baseurl}/((?:#{regex}[^,'"\s/?.]+\.?)*(?:/[^\]\[)("'\s]*)?)"}
194
216
  end
195
217
 
196
218
  # a regex that matches absolute urls in a html document
@@ -208,31 +230,39 @@ module Jekyll
208
230
  end
209
231
  end
210
232
  start = disabled ? 'ferh' : 'href'
211
- %r{(?<!hreflang="#{@default_lang}" )#{start}=\"?#{url}#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
233
+ %r{(?<!hreflang="#{@default_lang}" )#{start}="?#{url}#{@baseurl}/((?:#{regex}[^,'"\s/?.]+\.?)*(?:/[^\]\[)("'\s]*)?)"}
212
234
  end
213
235
 
214
236
  def relativize_urls(doc, regex)
215
237
  return if doc.output.nil?
216
238
 
217
- doc.output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"')
239
+ modified_output = doc.output.dup
240
+ modified_output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"')
241
+ doc.output = modified_output
218
242
  end
219
243
 
220
244
  def relativize_absolute_urls(doc, regex, url)
221
245
  return if doc.output.nil?
222
246
 
223
- doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/" + '\1"')
247
+ modified_output = doc.output.dup
248
+ modified_output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/" + '\1"')
249
+ doc.output = modified_output
224
250
  end
225
251
 
226
252
  def correct_nonrelativized_absolute_urls(doc, regex, url)
227
253
  return if doc.output.nil?
228
254
 
229
- doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/" + '\1"')
255
+ modified_output = doc.output.dup
256
+ modified_output.gsub!(regex, "href=\"#{url}#{@baseurl}/" + '\1"')
257
+ doc.output = modified_output
230
258
  end
231
259
 
232
260
  def correct_nonrelativized_urls(doc, regex)
233
261
  return if doc.output.nil?
234
262
 
235
- doc.output.gsub!(regex, "href=\"#{@baseurl}/" + '\1"')
263
+ modified_output = doc.output.dup
264
+ modified_output.gsub!(regex, "href=\"#{@baseurl}/" + '\1"')
265
+ doc.output = modified_output
236
266
  end
237
267
  end
238
268
  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.5.1
4
+ version: 1.7.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: 2022-10-01 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
27
33
  description: Fast open source i18n plugin for Jekyll blogs.
28
34
  email: untra.sam@gmail.com
29
35
  executables: []