jekyll-polyglot 1.2.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/README.md +96 -14
- data/lib/jekyll/polyglot/hooks.rb +0 -1
- data/lib/jekyll/polyglot/hooks/coordinate.rb +13 -1
- data/lib/jekyll/polyglot/hooks/process.rb +4 -0
- data/lib/jekyll/polyglot/liquid.rb +2 -1
- data/lib/jekyll/polyglot/liquid/tags/{i18n-headers.rb → i18n_headers.rb} +8 -6
- data/lib/jekyll/polyglot/liquid/tags/static_href.rb +27 -0
- data/lib/jekyll/polyglot/patches/jekyll/site.rb +131 -25
- data/lib/jekyll/polyglot/version.rb +1 -1
- metadata +8 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 37bbf459ea94dd1edd9fbef3aeb136db17a68b78b58a1b983d8bbc2cbe24727b
|
4
|
+
data.tar.gz: 5148941f48e63247596579130b8dbd8c407be7e326a2cc59b98725291d9f564d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 303584c6688bf73fb8fc15a8c6bb160b0ae2b055744bdac4a3515455343a20dfbccff2d5713e74f2dca6235f0ed40e0b5d9a7f230a9a57f4b007ae2b0bd5fc8b
|
7
|
+
data.tar.gz: de6caa20d33315f63c8f7f6da8800e83aa2f77548a8d21ed8bf4e8c7529d16ee96813eaef4d46fc9885867c03ae3b48e9681af041fda8c21e645ed8fbf560aaa
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2015 -
|
1
|
+
Copyright (c) 2015 - 2020 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
|
|
@@ -27,15 +27,20 @@ In your `_config.yml` file, add the following preferences
|
|
27
27
|
```YAML
|
28
28
|
languages: ["en", "sv", "de", "fr"]
|
29
29
|
default_lang: "en"
|
30
|
-
exclude_from_localization: ["javascript", "images", "css"]
|
30
|
+
exclude_from_localization: ["javascript", "images", "css", "README.md"]
|
31
31
|
parallel_localization: true
|
32
32
|
```
|
33
33
|
These configuration preferences indicate
|
34
34
|
- what i18n languages you wish to support
|
35
35
|
- what is your default "fallback" language for your content
|
36
|
-
- what root level folders are
|
36
|
+
- what root level files/folders are excluded from localization, based
|
37
|
+
on if their paths start with any of the excluded regexp substrings
|
37
38
|
- whether to run language processing in parallel or serial
|
38
39
|
|
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.
|
43
|
+
|
39
44
|
## How To Use It
|
40
45
|
When adding new posts and pages, add to the YAML front matter:
|
41
46
|
```
|
@@ -89,8 +94,63 @@ becomes
|
|
89
94
|
```
|
90
95
|
Notice the link `<a href="/fr/menu/">...` directs to the french website.
|
91
96
|
|
92
|
-
Even if you are falling back to `default_lang` page, relative links built on the *french* site will
|
93
|
-
|
97
|
+
Even if you are falling back to `default_lang` page, relative links built on the *french* site will still link to *french* pages.
|
98
|
+
|
99
|
+
#### Relativized Absolute Urls
|
100
|
+
If you defined a site `url` in your `_config.yaml`, polyglot will automatically relativize absolute links pointing to your website directory:
|
101
|
+
|
102
|
+
```md
|
103
|
+
---
|
104
|
+
lang: fr
|
105
|
+
---
|
106
|
+
Cliquez [ici]({{site.url}}) pour aller à l'entrée du site.
|
107
|
+
```
|
108
|
+
becomes
|
109
|
+
```html
|
110
|
+
<p>Cliquez <a href="https://mywebsite.com/fr/">ici</a> pour aller à l'entrée du site.
|
111
|
+
```
|
112
|
+
|
113
|
+
#### Disabling Url Relativizing
|
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.
|
125
|
+
|
126
|
+
For example, the following urls will be relativized:
|
127
|
+
|
128
|
+
```html
|
129
|
+
href="http://mywebsite.com/about"
|
130
|
+
href="/about"
|
131
|
+
```
|
132
|
+
|
133
|
+
and the following urls will be left alone:
|
134
|
+
|
135
|
+
```html
|
136
|
+
href=" http://mywebsite.com/about"
|
137
|
+
href=" /about"
|
138
|
+
```
|
139
|
+
|
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
|
+
```
|
94
154
|
|
95
155
|
#### Localized site.data
|
96
156
|
|
@@ -109,25 +169,47 @@ This plugin stands out from other I18n Jekyll plugins.
|
|
109
169
|
- builds all versions of your website *simultaneously*, allowing big websites to scale efficiently.
|
110
170
|
- provides the liquid tag `{{ site.languages }}` to get an array of your I18n strings.
|
111
171
|
- 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.
|
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`.
|
113
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.
|
114
175
|
- provides `site.data` localization for efficient rich text replacement.
|
115
176
|
- a creator that will answer all of your questions and issues.
|
116
177
|
|
117
178
|
## SEO Recipes
|
118
179
|
Jekyll-polyglot has a few spectacular [Search Engine Optimization techniques](https://untra.github.io/polyglot/seo) to ensure your Jekyll blog gets the most out of it's multilingual audience. Check them out!
|
119
180
|
|
120
|
-
## Examples
|
121
|
-
Check out the example project website [here](https://untra.github.io/polyglot)
|
122
|
-
(Jekyll resources are on the project's [site](https://github.com/untra/polyglot/tree/master/site) directory)
|
123
|
-
|
124
181
|
### Other Websites Built with Polyglot
|
125
182
|
let us know if you make a multilingual blog you want to share:
|
126
|
-
* [
|
183
|
+
* [Polyglot project website](https://polyglot.untra.io)
|
184
|
+
* [LogRhythm Corporate Website](https://logrhythm.com)
|
185
|
+
* [All Over Earth](https://allover.earth/)
|
186
|
+
* [Hanare Cafe in Toshijima, Japan](https://hanarecafe.com)
|
187
|
+
* [F-Droid](https://f-droid.org)
|
188
|
+
* [Ubuntu MATE](https://ubuntu-mate.org)
|
127
189
|
|
128
190
|
## Compatibility
|
129
|
-
Currently supports Jekyll 3.0 .
|
130
|
-
|
191
|
+
Currently supports Jekyll 3.0 , and Jekyll 4.0
|
192
|
+
|
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:
|
195
|
+
```yaml
|
196
|
+
sass:
|
197
|
+
sourcemap: never
|
198
|
+
```
|
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
|
131
213
|
|
132
214
|
## Copyright
|
133
|
-
Copyright (c) Samuel Volin
|
215
|
+
Copyright (c) Samuel Volin 2021. License: MIT
|
@@ -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,15 @@ 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\"
|
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\" hreflang=\"#{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
|
-
|
22
|
-
"
|
21
|
+
|
22
|
+
i18n += "<link rel=\"alternate\" hreflang=\"#{lang}\" "\
|
23
|
+
"href=\"#{site_url}/#{lang}#{permalink}\"/>\n"
|
23
24
|
end
|
24
25
|
i18n
|
25
26
|
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)
|
@@ -1,41 +1,54 @@
|
|
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
|
-
|
13
|
-
@exclude_from_localization = config.fetch('exclude_from_localization', [])
|
11
|
+
@lang_from_path = config.fetch('lang_from_path', false)
|
12
|
+
@exclude_from_localization = config.fetch('exclude_from_localization', []).map do |e|
|
13
|
+
if File.directory?(e) && e[-1] != '/'
|
14
|
+
e + '/'
|
15
|
+
else
|
16
|
+
e
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def fetch_languages
|
22
|
+
@default_lang = config.fetch('default_lang', 'en')
|
23
|
+
@languages = config.fetch('languages', ['en']).uniq
|
24
|
+
@keep_files += (@languages - [@default_lang])
|
14
25
|
@active_lang = @default_lang
|
26
|
+
@lang_vars = config.fetch('lang_vars', [])
|
15
27
|
end
|
16
28
|
|
17
29
|
alias_method :process_orig, :process
|
18
30
|
def process
|
19
31
|
prepare
|
32
|
+
all_langs = (@languages + [@default_lang]).uniq
|
20
33
|
if @parallel_localization
|
21
34
|
pids = {}
|
22
|
-
|
35
|
+
all_langs.each do |lang|
|
23
36
|
pids[lang] = fork do
|
24
37
|
process_language lang
|
25
38
|
end
|
26
39
|
end
|
27
40
|
Signal.trap('INT') do
|
28
|
-
|
41
|
+
all_langs.each do |lang|
|
29
42
|
puts "Killing #{pids[lang]} : #{lang}"
|
30
43
|
kill('INT', pids[lang])
|
31
44
|
end
|
32
45
|
end
|
33
|
-
|
46
|
+
all_langs.each do |lang|
|
34
47
|
waitpid pids[lang]
|
35
48
|
detach pids[lang]
|
36
49
|
end
|
37
50
|
else
|
38
|
-
|
51
|
+
all_langs.each do |lang|
|
39
52
|
process_language lang
|
40
53
|
end
|
41
54
|
end
|
@@ -47,14 +60,28 @@ module Jekyll
|
|
47
60
|
payload['site']['default_lang'] = default_lang
|
48
61
|
payload['site']['languages'] = languages
|
49
62
|
payload['site']['active_lang'] = active_lang
|
63
|
+
lang_vars.each do |v|
|
64
|
+
payload['site'][v] = active_lang
|
65
|
+
end
|
50
66
|
payload
|
51
67
|
end
|
52
68
|
|
53
69
|
def process_language(lang)
|
54
70
|
@active_lang = lang
|
55
71
|
config['active_lang'] = @active_lang
|
56
|
-
|
57
|
-
|
72
|
+
lang_vars.each do |v|
|
73
|
+
config[v] = @active_lang
|
74
|
+
end
|
75
|
+
if @active_lang == @default_lang
|
76
|
+
then process_default_language
|
77
|
+
else process_active_language
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def process_default_language
|
82
|
+
old_include = @include
|
83
|
+
process_orig
|
84
|
+
@include = old_include
|
58
85
|
end
|
59
86
|
|
60
87
|
def process_active_language
|
@@ -68,17 +95,42 @@ module Jekyll
|
|
68
95
|
@exclude = old_exclude
|
69
96
|
end
|
70
97
|
|
98
|
+
def derive_lang_from_path(doc)
|
99
|
+
if !@lang_from_path
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
segments = doc.relative_path.split('/')
|
103
|
+
if doc.relative_path[0] == '_' \
|
104
|
+
&& segments.length > 2 \
|
105
|
+
&& segments[1] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
|
106
|
+
return segments[1]
|
107
|
+
elsif segments.length > 1 \
|
108
|
+
&& segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
|
109
|
+
return segments[0]
|
110
|
+
else
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
71
115
|
# assigns natural permalinks to documents and prioritizes documents with
|
72
|
-
# active_lang languages over others
|
116
|
+
# active_lang languages over others. If lang is not set in front matter,
|
117
|
+
# then this tries to derive from the path, if the lang_from_path is set.
|
118
|
+
# otherwise it will assign the document to the default_lang
|
73
119
|
def coordinate_documents(docs)
|
74
120
|
regex = document_url_regex
|
75
121
|
approved = {}
|
76
122
|
docs.each do |doc|
|
77
|
-
lang = doc.data['lang'] || @default_lang
|
123
|
+
lang = doc.data['lang'] || derive_lang_from_path(doc) || @default_lang
|
124
|
+
lang_exclusive = doc.data['lang-exclusive'] || []
|
78
125
|
url = doc.url.gsub(regex, '/')
|
79
126
|
doc.data['permalink'] = url
|
127
|
+
# skip this document if it has already been processed
|
80
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
|
81
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
|
+
|
82
134
|
approved[url] = doc
|
83
135
|
@file_langs[url] = lang
|
84
136
|
end
|
@@ -87,8 +139,20 @@ module Jekyll
|
|
87
139
|
|
88
140
|
# performs any necesarry operations on the documents before rendering them
|
89
141
|
def process_documents(docs)
|
142
|
+
# return if @active_lang == @default_lang
|
143
|
+
|
144
|
+
url = config.fetch('url', false)
|
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)
|
90
149
|
docs.each do |doc|
|
91
|
-
relativize_urls
|
150
|
+
unless @active_lang == @default_lang then relativize_urls(doc, rel_regex) end
|
151
|
+
correct_nonrelativized_urls(doc, non_rel_regex)
|
152
|
+
if 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)
|
155
|
+
end
|
92
156
|
end
|
93
157
|
end
|
94
158
|
|
@@ -105,21 +169,63 @@ module Jekyll
|
|
105
169
|
end
|
106
170
|
|
107
171
|
# a regex that matches relative urls in a html document
|
108
|
-
# matches href="baseurl/foo/bar-baz" and others like it
|
109
|
-
# avoids matching excluded files
|
110
|
-
|
172
|
+
# matches href="baseurl/foo/bar-baz" href="/foo/bar-baz" and others like it
|
173
|
+
# avoids matching excluded files. prepare makes sure
|
174
|
+
# that all @exclude dirs have a trailing slash.
|
175
|
+
def relative_url_regex(disabled = false)
|
176
|
+
regex = ''
|
177
|
+
unless disabled
|
178
|
+
@exclude.each do |x|
|
179
|
+
regex += "(?!#{x})"
|
180
|
+
end
|
181
|
+
@languages.each do |x|
|
182
|
+
regex += "(?!#{x}\/)"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
start = disabled ? 'ferh' : 'href'
|
186
|
+
%r{#{start}=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
187
|
+
end
|
188
|
+
|
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)
|
111
194
|
regex = ''
|
112
|
-
|
113
|
-
|
195
|
+
unless disabled
|
196
|
+
@exclude.each do |x|
|
197
|
+
regex += "(?!#{x})"
|
198
|
+
end
|
199
|
+
@languages.each do |x|
|
200
|
+
regex += "(?!#{x}\/)"
|
201
|
+
end
|
114
202
|
end
|
115
|
-
|
116
|
-
|
117
|
-
%r{href=\"(?:#{url_quoted})?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
203
|
+
start = disabled ? 'ferh' : 'href'
|
204
|
+
%r{#{start}=\"?#{url}#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
|
118
205
|
end
|
119
206
|
|
120
|
-
def relativize_urls(doc)
|
121
|
-
return if
|
122
|
-
|
207
|
+
def relativize_urls(doc, regex)
|
208
|
+
return if doc.output.nil?
|
209
|
+
|
210
|
+
doc.output.gsub!(regex, "href=\"#{@baseurl}/#{@active_lang}/" + '\1"')
|
211
|
+
end
|
212
|
+
|
213
|
+
def relativize_absolute_urls(doc, regex, url)
|
214
|
+
return if doc.output.nil?
|
215
|
+
|
216
|
+
doc.output.gsub!(regex, "href=\"#{url}#{@baseurl}/#{@active_lang}/" + '\1"')
|
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"')
|
123
229
|
end
|
124
230
|
end
|
125
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.
|
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:
|
11
|
+
date: 2021-02-07 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: []
|
@@ -45,12 +39,13 @@ files:
|
|
45
39
|
- lib/jekyll/polyglot/hooks/coordinate.rb
|
46
40
|
- lib/jekyll/polyglot/hooks/process.rb
|
47
41
|
- lib/jekyll/polyglot/liquid.rb
|
48
|
-
- lib/jekyll/polyglot/liquid/tags/
|
42
|
+
- lib/jekyll/polyglot/liquid/tags/i18n_headers.rb
|
43
|
+
- lib/jekyll/polyglot/liquid/tags/static_href.rb
|
49
44
|
- lib/jekyll/polyglot/patches.rb
|
50
45
|
- lib/jekyll/polyglot/patches/jekyll/site.rb
|
51
46
|
- lib/jekyll/polyglot/patches/jekyll/static_file.rb
|
52
47
|
- lib/jekyll/polyglot/version.rb
|
53
|
-
homepage:
|
48
|
+
homepage: https://polyglot.untra.io/
|
54
49
|
licenses:
|
55
50
|
- MIT
|
56
51
|
metadata: {}
|
@@ -62,15 +57,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
57
|
requirements:
|
63
58
|
- - ">="
|
64
59
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
60
|
+
version: 2.4.0
|
66
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
62
|
requirements:
|
68
63
|
- - ">="
|
69
64
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
65
|
+
version: 2.7.0
|
71
66
|
requirements: []
|
72
|
-
|
73
|
-
rubygems_version: 2.5.2
|
67
|
+
rubygems_version: 3.2.7
|
74
68
|
signing_key:
|
75
69
|
specification_version: 4
|
76
70
|
summary: I18n plugin for Jekyll Blogs
|