jekyll-polyglot 1.3.1 → 1.3.2

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
- SHA1:
3
- metadata.gz: 2ef2e09c9f5884d0093bef2c8d97b756297a4842
4
- data.tar.gz: 7813f910f0ac8679f1c64e6b3c65130d8a9a9beb
2
+ SHA256:
3
+ metadata.gz: e3f7773339c45333233f02e73f7e7c96e87a6609ebdb6e6c1082b3adebf679d0
4
+ data.tar.gz: 5d8bdce1424b3be47d4e1dc07d1dba638436c2c65674e00845c354352b118387
5
5
  SHA512:
6
- metadata.gz: a828887248c4bd3673429193223ac91ccdb046cd0369df470ba1a973382e88a9e9a98a53407bc67a6ac8975719a0a4bc1eb85df84a4bc94ba8c6a3cd78adfe57
7
- data.tar.gz: 9195927833fd833472aaa04671ad48ee812d2e8febb27e421deddd87a8a19c9cd9d93657df95a5259fcf6df657d8cc17ad620ce02264fa3fe6a1990436b64de4
6
+ metadata.gz: 154f29a20360f6db96f4be7c8584158c9d71c723ae306ad4093ab306eb6b52877bf75ebd5cf222251ebbadfada6c075d1dda06b65f0108b0eddbc8621e05b016
7
+ data.tar.gz: 240fdec79c5f4188d46a3ec160b17b8fc57fd5341564e105464bf877aa0d8bfe7b69d1f1bbc51c56d03c2a85499f33143ed77eb9131e62891e2c7f76147065c1
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 - 2017 Samuel Volin
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
@@ -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 you excluding from localization
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
  ```
@@ -152,13 +157,21 @@ Jekyll-polyglot has a few spectacular [Search Engine Optimization techniques](ht
152
157
 
153
158
  ### Other Websites Built with Polyglot
154
159
  let us know if you make a multilingual blog you want to share:
155
- * [Polyglot example project website](http://polyglot.untra.io)
160
+ * [Polyglot project website](http://polyglot.untra.io)
156
161
  * [LogRhythm Corporate Website](http://logrhythm.com)
157
162
  * [All Over Earth](https://allover.earth/)
163
+ * [Hanare Cafe in Toshijima, Japan](https://hanarecafe.com)
164
+ * [F-Droid](https://f-droid.org)
158
165
 
159
166
  ## Compatibility
160
- Currently supports Jekyll 3.0 .
161
- Windows users will need to disable parallel_localization on their machines by setting `parallel_localization: false` in the `_config.yml`
167
+ Currently supports Jekyll 3.0 , and Jekyll 4.0 (for the most part)
168
+
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:
171
+ ```yaml
172
+ sass:
173
+ sourcemap: never
174
+ ```
162
175
 
163
176
  ## Copyright
164
- Copyright (c) Samuel Volin 2017. License: MIT
177
+ Copyright (c) Samuel Volin 2020. License: MIT
@@ -8,7 +8,15 @@ module Jekyll
8
8
  @file_langs = {}
9
9
  fetch_languages
10
10
  @parallel_localization = config.fetch('parallel_localization', true)
11
- @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) and e[-1] != '/'
14
+ e + '/'
15
+ else
16
+ e
17
+ end
18
+ end
19
+
12
20
  end
13
21
 
14
22
  def fetch_languages
@@ -88,13 +96,32 @@ module Jekyll
88
96
  @exclude = old_exclude
89
97
  end
90
98
 
99
+ def derive_lang_from_path(doc)
100
+ if !@lang_from_path
101
+ return nil
102
+ end
103
+ segments = doc.relative_path.split('/')
104
+ 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}$/
107
+ return segments[1]
108
+ elsif segments.length > 1 \
109
+ and segments[0] =~ /^[a-z]{2,3}(:?[_-](:?[A-Za-z]{2}){1,2}){0,2}$/
110
+ return segments[0]
111
+ else
112
+ return nil
113
+ end
114
+ end
115
+
91
116
  # assigns natural permalinks to documents and prioritizes documents with
92
- # active_lang languages over others
117
+ # active_lang languages over others. If lang is not set in front matter,
118
+ # then this tries to derive from the path, if the lang_from_path is set.
119
+ # otherwise it will assign the document to the default_lang
93
120
  def coordinate_documents(docs)
94
121
  regex = document_url_regex
95
122
  approved = {}
96
123
  docs.each do |doc|
97
- lang = doc.data['lang'] || @default_lang
124
+ lang = doc.data['lang'] || derive_lang_from_path(doc) || @default_lang
98
125
  url = doc.url.gsub(regex, '/')
99
126
  doc.data['permalink'] = url
100
127
  next if @file_langs[url] == @active_lang
@@ -133,10 +160,14 @@ module Jekyll
133
160
 
134
161
  # a regex that matches relative urls in a html document
135
162
  # matches href="baseurl/foo/bar-baz" and others like it
136
- # avoids matching excluded files
163
+ # avoids matching excluded files. prepare makes sure
164
+ # that all @exclude dirs have a trailing slash.
137
165
  def relative_url_regex
138
166
  regex = ''
139
- (@exclude + @languages).each do |x|
167
+ (@exclude).each do |x|
168
+ regex += "(?!#{x})"
169
+ end
170
+ (@languages).each do |x|
140
171
  regex += "(?!#{x}\/)"
141
172
  end
142
173
  %r{href=\"?#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
@@ -144,7 +175,10 @@ module Jekyll
144
175
 
145
176
  def absolute_url_regex(url)
146
177
  regex = ''
147
- (@exclude + @languages).each do |x|
178
+ (@exclude).each do |x|
179
+ regex += "(?!#{x})"
180
+ end
181
+ (@languages).each do |x|
148
182
  regex += "(?!#{x}\/)"
149
183
  end
150
184
  %r{href=\"?#{url}#{@baseurl}\/((?:#{regex}[^,'\"\s\/?\.#]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Polyglot
3
- VERSION = '1.3.1'.freeze
3
+ VERSION = '1.3.2'.freeze
4
4
  end
5
5
  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.1
4
+ version: 1.3.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: 2017-09-02 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -63,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 2.5.1
66
+ rubygems_version: 3.1.2
68
67
  signing_key:
69
68
  specification_version: 4
70
69
  summary: I18n plugin for Jekyll Blogs