jekyll-polyglot 1.8.1 → 1.10.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 +4 -4
- data/README.md +30 -19
- data/lib/jekyll/polyglot/hooks/coordinate.rb +2 -2
- data/lib/jekyll/polyglot/hooks/process.rb +1 -1
- data/lib/jekyll/polyglot/liquid/tags/i18n_headers.rb +32 -10
- data/lib/jekyll/polyglot/liquid/tags/static_href.rb +4 -8
- data/lib/jekyll/polyglot/patches/jekyll/site.rb +42 -29
- data/lib/jekyll/polyglot/patches/jekyll/static_file.rb +4 -3
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0459aa05cc1025bea0ca2aef71ad7e3e4a0c33726b1f32e4d5f2e19d521a06aa'
|
4
|
+
data.tar.gz: 245aa4b72aa80fac516b0cc9b04c396ef0ec55366aadefbb73ba8fa9ca47df93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8f4162ee486ebf72f6c5be6714bb5aed0a60f5ca0798480efbc8a68f84cd94c40b9db9efbb6160317ca974f600cbe82ac82c0934a833d162135b873a3b000da
|
7
|
+
data.tar.gz: c5367a20ee1ea4983e5cc8485204f11da88d4a3914ccfc5aa62d76d78cd364fd15c223e99a4bbec5f27d306c7be4226232faa3c17b38951dd9102ead2e5e02c7
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
🔤 Polyglot
|
2
2
|
---
|
3
3
|
[](https://badge.fury.io/rb/jekyll-polyglot)
|
4
|
-
[](https://circleci.com/gh/untra/polyglot/?branch=main)
|
5
|
+
[](https://codecov.io/gh/untra/polyglot)
|
5
6
|
|
6
7
|
__Polyglot__ is a fast, painless, open-source internationalization plugin for [Jekyll](http://jekyllrb.com) blogs. Polyglot is easy to set up 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.
|
7
8
|
|
@@ -27,30 +28,29 @@ In your `_config.yml` file, add the following preferences
|
|
27
28
|
```YAML
|
28
29
|
languages: ["en", "sv", "de", "fr"]
|
29
30
|
default_lang: "en"
|
30
|
-
exclude_from_localization: ["javascript", "images", "css", "public"]
|
31
|
+
exclude_from_localization: ["javascript", "images", "css", "public", "sitemap"]
|
31
32
|
parallel_localization: true
|
33
|
+
url: https://polyglot.untra.io
|
32
34
|
```
|
33
35
|
These configuration preferences indicate
|
34
36
|
- what i18n languages you wish to support
|
35
37
|
- what is your default "fallback" language for your content
|
36
|
-
- what root level files/folders are excluded from localization, based
|
37
|
-
|
38
|
-
-
|
38
|
+
- what root level files/folders are excluded from localization, based on if their paths start with any of the excluded regexp substrings. (this is different from the jekyll `exclude: [ .gitignore ]` ; you should `exclude` files and directories in your repo you dont want in your built site at all, and `exclude_from_localization` files and directories you want to see in your built site, but not in your sublanguage sites.)
|
39
|
+
- whether to run language processing in parallel or serial. Set to `false` if building on Windows hosts, or if Polyglot collides with other Jekyll plugins.
|
40
|
+
- your jekyll website production url. Make sure this value is set; Polyglot requires this to relative site urls correctly, and to make functioning language switchers.
|
39
41
|
|
40
|
-
The optional `lang_from_path: true` option enables getting page
|
41
|
-
language from the first or second path segment, e.g `de/first-one.md`, or
|
42
|
-
`_posts/zh_Hans_HK/use-second-segment.md` , if the lang frontmatter isn't defined.
|
42
|
+
The optional `lang_from_path: true` option enables getting the page language from a filepath segment seperated by `/` or `.`, e.g `de/first-one.md`, or `_posts/zh_HK/use-second-segment.md` , if the lang frontmatter isn't defined.
|
43
43
|
|
44
44
|
## How To Use It
|
45
45
|
When adding new posts and pages, add to the YAML front matter:
|
46
46
|
```
|
47
47
|
lang: sv
|
48
48
|
```
|
49
|
-
or whatever appropriate [I18n language code](https://developer.chrome.com/
|
49
|
+
or whatever appropriate [I18n language code](https://developer.chrome.com/docs/extensions/reference/api/i18n#locales)
|
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/
|
53
|
+
You can see how the live Polyglot website [configures and supports multiple languages](https://github.com/untra/polyglot/blob/main/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
54
|
|
55
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:
|
56
56
|
```
|
@@ -112,7 +112,7 @@ Estos somos nosotros!
|
|
112
112
|
```
|
113
113
|
|
114
114
|
Additionally, if you are also using the `jekyll-redirect-from` plugin, pages coordinated this way will automatically have redirects created between pages.
|
115
|
-
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/
|
115
|
+
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/main/site/_layouts/redirect.html).
|
116
116
|
|
117
117
|
#### Fallback Language Support
|
118
118
|
Lets say you are building your website. You have an `/about/` page written in *english*, *german* and
|
@@ -160,7 +160,7 @@ becomes
|
|
160
160
|
|
161
161
|
### Disabling Url Relativizing
|
162
162
|
_New in 1.4.0_
|
163
|
-
If you dont want a href attribute to be relativized (such as for making [a language switcher](https://github.com/untra/polyglot/blob/
|
163
|
+
If you dont want a href attribute to be relativized (such as for making [a language switcher](https://github.com/untra/polyglot/blob/main/site/_includes/sidebar.html#L40)), you can use the block tag:
|
164
164
|
|
165
165
|
```html
|
166
166
|
{% static_href %}href="..."{% endstatic_href %}
|
@@ -251,7 +251,7 @@ Polyglot will only start builds after it confirms there is a cpu core ready to a
|
|
251
251
|
### Writing Tests and Debugging
|
252
252
|
_: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._
|
253
253
|
|
254
|
-
Tests are run with `
|
254
|
+
Tests are run with `test.sh`. Tests are in the `/spec` directory, and test failure output detail can be examined in the `rspec.json` file. Code Coverage details are in the the `coverage` directory.
|
255
255
|
|
256
256
|
## Features
|
257
257
|
This plugin stands out from other I18n Jekyll plugins.
|
@@ -260,7 +260,7 @@ This plugin stands out from other I18n Jekyll plugins.
|
|
260
260
|
- provides the liquid tag `{{ site.languages }}` to get an array of your I18n strings.
|
261
261
|
- provides the liquid tag `{{ site.default_lang }}` to get the default_lang I18n string.
|
262
262
|
- 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`.
|
263
|
-
- provides the liquid tag `{{ I18n_Headers
|
263
|
+
- provides the liquid tag `{{ I18n_Headers }}` to append SEO bonuses to your website.
|
264
264
|
- provides the liquid tag `{{ Unrelativized_Link href="/hello" }}` to make urls that do not get influenced by url correction regexes.
|
265
265
|
- provides `site.data` localization for efficient rich text replacement.
|
266
266
|
- a creator that will answer all of your questions and issues.
|
@@ -272,6 +272,13 @@ Jekyll-polyglot has a few spectacular [Search Engine Optimization techniques](ht
|
|
272
272
|
|
273
273
|
See the example [sitemap.xml](/site/sitemap.xml) and [robots.txt](/site/robots.txt) for how to automatically generate a multi-language sitemap for your page and turn it in for the SEO i18n credit.
|
274
274
|
|
275
|
+
The [official Sitemap protocol documentation](https://www.sitemaps.org/protocol.html#location) states:
|
276
|
+
> "The location of a Sitemap file determines the set of URLs that can be included in that Sitemap. A Sitemap file located at http://example.com/catalog/sitemap.xml can include any URLs starting with http://example.com/catalog/ but can not include URLs starting with http://example.com/images/."
|
277
|
+
|
278
|
+
> "It is strongly recommended that you place your Sitemap at the root directory of your web server."
|
279
|
+
|
280
|
+
To comply with this, 'sitemap.xml' should be added to the 'exclude_from_localization' list to ensure that only one `sitemap.xml` file exists in the root directory, rather than creating separate ones for each language.
|
281
|
+
|
275
282
|
## Compatibility
|
276
283
|
Currently supports Jekyll 3.0 , and Jekyll 4.0
|
277
284
|
* Windows users will need to disable parallel_localization on their machines by setting `parallel_localization: false` in the `_config.yml`
|
@@ -291,17 +298,18 @@ If you have something you'd like to contribute to jekyll-polyglot, please open a
|
|
291
298
|
These are talented and considerate software developers across the world that have lent their support to this project.
|
292
299
|
**Thank You! ¡Gracias! Merci! Danke! 감사합니다! תודה רבה! Спасибо! Dankjewel! 谢谢!Obrigado!**
|
293
300
|
|
301
|
+
* [@yunseo-kim](https://github.com/yunseo-kim) [improved i18n sitemaps]((https://polyglot.untra.io/2025/01/18/polyglot-1.9.0/))
|
294
302
|
* [@blackpill](https://github.com/blackpill) [1.8.1](https://polyglot.untra.io/2024/08/18/polyglot-1.8.1/)
|
295
303
|
* [@hacketiwack](https://github.com/hacketiwack) [1.8.1](https://polyglot.untra.io/2024/08/18/polyglot-1.8.1/)
|
296
304
|
* [@jerturowetz](https://github.com/jerturowetz) [sitemap generation](https://polyglot.untra.io/2024/03/17/polyglot-1.8.0/)
|
297
305
|
* [@antoniovazquezblanco](https://github.com/antoniovazquezblanco) [1.7.0](https://polyglot.untra.io/2023/10/29/polyglot-1.7.0/)
|
298
|
-
* [@salinatedcoffee](https://github.com/SalinatedCoffee) [ko support](https://polyglot.untra.io/2023/02/27/korean-support/)
|
299
|
-
* [@aturret](https://github.com/aturret) [zh-CN support](https://polyglot.untra.io/2023/06/08/polyglot-1.6.0-chinese-support/)
|
306
|
+
* [@salinatedcoffee](https://github.com/SalinatedCoffee) [ko support](https://polyglot.untra.io/ko/2023/02/27/korean-support/)
|
307
|
+
* [@aturret](https://github.com/aturret) [zh-CN support](https://polyglot.untra.io/zh-CN/2023/06/08/polyglot-1.6.0-chinese-support/)
|
300
308
|
* [@dougieh](https://github.com/dougieh) [1.5.1](https://polyglot.untra.io/2022/10/01/polyglot-1.5.1/)
|
301
|
-
* [@pandermusubi](https://github.com/PanderMusubi) [nl support](https://polyglot.untra.io/2022/01/15/dutch-site-support/)
|
309
|
+
* [@pandermusubi](https://github.com/PanderMusubi) [nl support](https://polyglot.untra.io/nl/2022/01/15/dutch-site-support/)
|
302
310
|
* [@obfusk](https://github.com/obfusk) [1.5.0](https://polyglot.untra.io/2021/07/17/polyglot-1.5.0/)
|
303
311
|
* [@eighthave](https://github.com/eighthave) [1.5.0](https://polyglot.untra.io/2021/07/17/polyglot-1.5.0/)
|
304
|
-
* [@george-gca](https://github.com/george-gca) [
|
312
|
+
* [@george-gca](https://github.com/george-gca) [pt-BR support](https://polyglot.untra.io/pt-BR/2024/02/29/localized-variables.md)
|
305
313
|
|
306
314
|
### Other Websites Built with Polyglot
|
307
315
|
Feel free to open a PR and list your multilingual blog here you may want to share:
|
@@ -317,6 +325,9 @@ Feel free to open a PR and list your multilingual blog here you may want to shar
|
|
317
325
|
* [Yi Yunseok's personal blog website](https://Yi-Yunseok.GitHub.io)
|
318
326
|
* [Tarlogic Cybersecurity](https://www.tarlogic.com/)
|
319
327
|
* [A beautiful, simple, clean, and responsive Jekyll theme for academics](https://github.com/george-gca/multi-language-al-folio)
|
328
|
+
* [AnotherTurret just another study note blog](https://aturret.space/)
|
329
|
+
* [Diciotech is a collaborative online tech dictionary](https://diciotech.netlify.app/)
|
330
|
+
* [Yunseo Kim's Study Notes](https://www.yunseo.kim/)
|
320
331
|
|
321
332
|
## 2.0 Roadmap
|
322
333
|
* [x] - **site language**: portuguese Brazil `pt-BR`
|
@@ -333,4 +344,4 @@ Feel free to open a PR and list your multilingual blog here you may want to shar
|
|
333
344
|
* [x] - update CI provider
|
334
345
|
|
335
346
|
## Copyright
|
336
|
-
Copyright (c) Samuel Volin
|
347
|
+
Copyright (c) Samuel Volin 2025. License: MIT
|
@@ -8,7 +8,7 @@ def hook_coordinate(site)
|
|
8
8
|
# Copy the language specific data, by recursively merging it with the default data.
|
9
9
|
# Favour active_lang first, then default_lang, then any non-language-specific data.
|
10
10
|
# See: https://www.ruby-forum.com/topic/142809
|
11
|
-
merger = proc { |
|
11
|
+
merger = proc { |_key, v1, v2| v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2 }
|
12
12
|
if site.data.include?(site.default_lang)
|
13
13
|
site.data = site.data.merge(site.data[site.default_lang], &merger)
|
14
14
|
end
|
@@ -16,7 +16,7 @@ def hook_coordinate(site)
|
|
16
16
|
site.data = site.data.merge(site.data[site.active_lang], &merger)
|
17
17
|
end
|
18
18
|
|
19
|
-
site.collections.
|
19
|
+
site.collections.each_value do |collection|
|
20
20
|
collection.docs = site.coordinate_documents(collection.docs)
|
21
21
|
end
|
22
22
|
site.pages = site.coordinate_documents(site.pages)
|
@@ -11,18 +11,40 @@ module Jekyll
|
|
11
11
|
|
12
12
|
def render(context)
|
13
13
|
site = context.registers[:site]
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
page = context.registers[:page]
|
15
|
+
permalink = page['permalink'] || page['url'] || ''
|
16
|
+
permalink = "/#{permalink}" unless permalink.start_with?("/")
|
17
|
+
page_id = page['page_id']
|
18
|
+
permalink_lang = page['permalink_lang']
|
19
|
+
baseurl = site.config['baseurl'] || ''
|
20
|
+
site_url = @url.empty? ? site.config['url'] + baseurl : @url
|
17
21
|
i18n = "<meta http-equiv=\"Content-Language\" content=\"#{site.active_lang}\">\n"
|
18
|
-
i18n += "<link rel=\"alternate\" hreflang=\"#{site.default_lang}\" "\
|
19
|
-
"href=\"#{site_url}/#{permalink}\"/>\n"
|
20
|
-
site.languages.each do |lang|
|
21
|
-
next if lang == site.default_lang
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# Find all documents with the same page_id
|
24
|
+
docs_with_same_id = site.collections.values
|
25
|
+
.flat_map(&:docs)
|
26
|
+
.filter { |doc| !doc.data['page_id'].nil? }
|
27
|
+
.select { |doc| doc.data['page_id'] == page_id }
|
28
|
+
|
29
|
+
# Build a hash of lang => permalink for all matching docs
|
30
|
+
lang_to_permalink = docs_with_same_id.to_h { |doc| [doc.data['lang'], doc.data['permalink']] }
|
31
|
+
|
32
|
+
# Canonical should always point to the current page's permalink (active_lang)
|
33
|
+
current_lang = site.active_lang
|
34
|
+
current_permalink = lang_to_permalink[current_lang] || (permalink_lang && permalink_lang[current_lang]) || permalink
|
35
|
+
current_permalink = "/#{current_permalink}" unless current_permalink.start_with?("/")
|
36
|
+
current_lang_prefix = current_lang == site.default_lang ? '' : "/#{current_lang}"
|
37
|
+
i18n += "<link rel=\"canonical\" href=\"#{site_url}#{current_lang_prefix}#{current_permalink}\"/>\n"
|
38
|
+
|
39
|
+
site.languages.each do |lang|
|
40
|
+
alt_permalink = lang_to_permalink[lang] || (permalink_lang && permalink_lang[lang]) || permalink
|
41
|
+
alt_permalink = "/#{alt_permalink}" unless alt_permalink.start_with?("/")
|
42
|
+
i18n += if lang == site.default_lang
|
43
|
+
"<link rel=\"alternate\" hreflang=\"#{lang}\" href=\"#{site_url}#{alt_permalink}\"/>\n" \
|
44
|
+
"<link rel=\"alternate\" hreflang=\"x-default\" href=\"#{site_url}#{alt_permalink}\"/>\n"
|
45
|
+
else
|
46
|
+
"<link rel=\"alternate\" hreflang=\"#{lang}\" href=\"#{site_url}/#{lang}#{alt_permalink}\"/>\n"
|
47
|
+
end
|
26
48
|
end
|
27
49
|
i18n
|
28
50
|
end
|
@@ -1,21 +1,17 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module Polyglot
|
3
3
|
module Liquid
|
4
|
-
class StaticHrefTag < ::
|
5
|
-
def initialize(tag_name, params, tokens)
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
4
|
+
class StaticHrefTag < ::Liquid::Block
|
9
5
|
def render(context)
|
10
6
|
text = super
|
11
|
-
href_attrs = text.strip.split
|
7
|
+
href_attrs = text.strip.split('=', 2)
|
12
8
|
valid = (href_attrs.length == 2 && href_attrs[0] == 'href') && href_attrs[1].start_with?('"') && href_attrs[1].end_with?('"')
|
13
9
|
unless valid
|
14
|
-
raise Liquid::SyntaxError, "static_href parameters must include match href=\"...\" attribute param, eg. href=\"http://example.com
|
10
|
+
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
11
|
end
|
16
12
|
|
17
13
|
href_value = href_attrs[1]
|
18
|
-
# href writes out as ferh="..." explicitly wrong, to be
|
14
|
+
# href writes out as ferh="..." explicitly wrong, to be caught by separate processor for nonrelativized links
|
19
15
|
"ferh=#{href_value}"
|
20
16
|
end
|
21
17
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'English'
|
1
2
|
require 'etc'
|
2
3
|
|
3
4
|
include Process
|
4
5
|
module Jekyll
|
5
6
|
class Site
|
6
|
-
attr_reader :default_lang, :languages, :exclude_from_localization, :lang_vars
|
7
|
+
attr_reader :default_lang, :languages, :exclude_from_localization, :lang_vars, :lang_from_path
|
7
8
|
attr_accessor :file_langs, :active_lang
|
8
9
|
|
9
10
|
def prepare
|
@@ -31,7 +32,7 @@ module Jekyll
|
|
31
32
|
alias process_orig process
|
32
33
|
def process
|
33
34
|
prepare
|
34
|
-
all_langs = (@
|
35
|
+
all_langs = ([@default_lang] + @languages).uniq
|
35
36
|
if @parallel_localization
|
36
37
|
nproc = Etc.nprocessors
|
37
38
|
pids = {}
|
@@ -42,11 +43,11 @@ module Jekyll
|
|
42
43
|
end
|
43
44
|
while pids.length >= (lang == all_langs[-1] ? 1 : nproc)
|
44
45
|
sleep 0.1
|
45
|
-
pids.map do |
|
46
|
+
pids.map do |pid_lang, pid|
|
46
47
|
next unless waitpid pid, Process::WNOHANG
|
47
48
|
|
48
|
-
pids.delete
|
49
|
-
raise "Polyglot subprocess #{pid} (#{lang}) failed (#{
|
49
|
+
pids.delete pid_lang
|
50
|
+
raise "Polyglot subprocess #{pid} (#{lang}) failed (#{$CHILD_STATUS.exitstatus})" unless $CHILD_STATUS.success?
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -108,19 +109,23 @@ module Jekyll
|
|
108
109
|
@exclude = old_exclude
|
109
110
|
end
|
110
111
|
|
112
|
+
def split_on_multiple_delimiters(string)
|
113
|
+
delimiters = ['.', '/']
|
114
|
+
regex = Regexp.union(delimiters)
|
115
|
+
string.split(regex)
|
116
|
+
end
|
117
|
+
|
111
118
|
def derive_lang_from_path(doc)
|
112
119
|
unless @lang_from_path
|
113
120
|
return nil
|
114
121
|
end
|
115
122
|
|
116
|
-
segments = doc.
|
117
|
-
if
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
&& segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
|
123
|
-
return segments[0]
|
123
|
+
segments = split_on_multiple_delimiters(doc.path)
|
124
|
+
# loop through all segments and check if they match the language regex
|
125
|
+
segments.each do |segment|
|
126
|
+
if @languages.include?(segment)
|
127
|
+
return segment
|
128
|
+
end
|
124
129
|
end
|
125
130
|
|
126
131
|
nil
|
@@ -152,21 +157,28 @@ module Jekyll
|
|
152
157
|
approved[page_id] = doc
|
153
158
|
@file_langs[page_id] = lang
|
154
159
|
end
|
155
|
-
approved.
|
156
|
-
|
160
|
+
approved.each_value do |doc|
|
161
|
+
assignPageRedirects(doc, docs)
|
162
|
+
assignPageLanguagePermalinks(doc, docs)
|
163
|
+
end
|
157
164
|
approved.values
|
158
165
|
end
|
159
166
|
|
160
167
|
def assignPageRedirects(doc, docs)
|
161
168
|
pageId = doc.data['page_id']
|
162
169
|
if !pageId.nil? && !pageId.empty?
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
170
|
+
redirects = []
|
171
|
+
|
172
|
+
docs_with_same_id = docs.select { |dd| dd.data['page_id'] == pageId }
|
173
|
+
|
174
|
+
# For each document with the same page_id
|
175
|
+
docs_with_same_id.each do |dd|
|
176
|
+
# Add redirect if it's a different permalink
|
177
|
+
if dd.data['permalink'] != doc.data['permalink']
|
178
|
+
redirects << dd.data['permalink']
|
179
|
+
end
|
168
180
|
end
|
169
|
-
|
181
|
+
|
170
182
|
doc.data['redirect_from'] = redirects
|
171
183
|
end
|
172
184
|
end
|
@@ -210,7 +222,7 @@ module Jekyll
|
|
210
222
|
def document_url_regex
|
211
223
|
regex = ''
|
212
224
|
(@languages || []).each do |lang|
|
213
|
-
regex += "([
|
225
|
+
regex += "([/.]#{lang}[/.])|"
|
214
226
|
end
|
215
227
|
regex.chomp! '|'
|
216
228
|
/#{regex}/
|
@@ -227,7 +239,7 @@ module Jekyll
|
|
227
239
|
regex += "(?!#{x})"
|
228
240
|
end
|
229
241
|
@languages.each do |x|
|
230
|
-
regex += "(?!#{x}
|
242
|
+
regex += "(?!#{x}/)"
|
231
243
|
end
|
232
244
|
end
|
233
245
|
start = disabled ? 'ferh' : 'href'
|
@@ -245,18 +257,19 @@ module Jekyll
|
|
245
257
|
regex += "(?!#{x})"
|
246
258
|
end
|
247
259
|
@languages.each do |x|
|
248
|
-
regex += "(?!#{x}
|
260
|
+
regex += "(?!#{x}/)"
|
249
261
|
end
|
250
262
|
end
|
251
263
|
start = disabled ? 'ferh' : 'href'
|
252
|
-
|
264
|
+
neglookbehind = disabled ? "" : "(?<!hreflang=\"#{@default_lang}\" |rel=\"canonical\" )"
|
265
|
+
%r{#{neglookbehind}#{start}="?#{url}#{@baseurl}/((?:#{regex}[^,'"\s/?.]+\.?)*(?:/[^\]\[)("'\s]*)?)"}
|
253
266
|
end
|
254
267
|
|
255
268
|
def relativize_urls(doc, regex)
|
256
269
|
return if doc.output.nil?
|
257
270
|
|
258
271
|
modified_output = doc.output.dup
|
259
|
-
modified_output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}
|
272
|
+
modified_output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/\\1\"")
|
260
273
|
doc.output = modified_output
|
261
274
|
end
|
262
275
|
|
@@ -264,7 +277,7 @@ module Jekyll
|
|
264
277
|
return if doc.output.nil?
|
265
278
|
|
266
279
|
modified_output = doc.output.dup
|
267
|
-
modified_output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}
|
280
|
+
modified_output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/\\1\"")
|
268
281
|
doc.output = modified_output
|
269
282
|
end
|
270
283
|
|
@@ -272,7 +285,7 @@ module Jekyll
|
|
272
285
|
return if doc.output.nil?
|
273
286
|
|
274
287
|
modified_output = doc.output.dup
|
275
|
-
modified_output.gsub!(regex, "href=\"#{url}#{@baseurl}
|
288
|
+
modified_output.gsub!(regex, "href=\"#{url}#{@baseurl}/\\1\"")
|
276
289
|
doc.output = modified_output
|
277
290
|
end
|
278
291
|
|
@@ -280,7 +293,7 @@ module Jekyll
|
|
280
293
|
return if doc.output.nil?
|
281
294
|
|
282
295
|
modified_output = doc.output.dup
|
283
|
-
modified_output.gsub!(regex, "href=\"#{@baseurl}
|
296
|
+
modified_output.gsub!(regex, "href=\"#{@baseurl}/\\1\"")
|
284
297
|
doc.output = modified_output
|
285
298
|
end
|
286
299
|
end
|
@@ -1,19 +1,20 @@
|
|
1
|
-
|
2
1
|
module Jekyll
|
3
2
|
# Alteration to Jekyll StaticFile
|
4
3
|
# provides aliased methods to direct write to skip files
|
5
4
|
# excluded from localization
|
6
5
|
class StaticFile
|
7
|
-
|
6
|
+
alias write_orig write
|
8
7
|
def write(dest)
|
9
8
|
return false if exclude_from_localization?
|
9
|
+
|
10
10
|
write_orig(dest)
|
11
11
|
end
|
12
12
|
|
13
13
|
def exclude_from_localization?
|
14
14
|
return false if @site.active_lang == @site.default_lang
|
15
|
+
|
15
16
|
@site.exclude_from_localization.each do |e|
|
16
|
-
return true if relative_path[1
|
17
|
+
return true if relative_path[1..].start_with?(e)
|
17
18
|
end
|
18
19
|
false
|
19
20
|
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.10.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: 2025-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -54,7 +54,8 @@ files:
|
|
54
54
|
homepage: https://polyglot.untra.io/
|
55
55
|
licenses:
|
56
56
|
- MIT
|
57
|
-
metadata:
|
57
|
+
metadata:
|
58
|
+
rubygems_mfa_required: 'true'
|
58
59
|
post_install_message:
|
59
60
|
rdoc_options: []
|
60
61
|
require_paths:
|
@@ -63,12 +64,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
64
|
requirements:
|
64
65
|
- - ">="
|
65
66
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
+
version: 3.1.0
|
67
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
69
|
requirements:
|
69
70
|
- - ">="
|
70
71
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
72
|
+
version: 3.1.0
|
72
73
|
requirements: []
|
73
74
|
rubygems_version: 3.3.7
|
74
75
|
signing_key:
|