jekyll-locales 0.1.9 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +6 -0
- data/jekyll-locales.gemspec +1 -1
- data/lib/jekyll/locales/hooks/cleanup.rb +28 -0
- data/lib/jekyll/locales/hooks/post_render.rb +34 -0
- data/lib/jekyll/locales/site.rb +20 -17
- data/lib/jekyll/locales/version.rb +1 -1
- data/lib/jekyll/locales.rb +2 -0
- metadata +10 -9
- data/Gemfile.lock +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ea6328cebd340c5f8b48759962e5b45cb9fe2c0082834dd7e53fb00a614206
|
4
|
+
data.tar.gz: c66fa0b8ed57d3d1ccdeb12d03e59e2409df5e406a9337eaad49c673456ae41e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fdb870f42080d6002d55c415e538646f54456f99701cde27ca5cf15c70b78e1a76433e49bbfda2ba799b37f79ccf36057e1a6aa0bc815cba8790476ddc065b0
|
7
|
+
data.tar.gz: 3250eb037d0557c84a69714ed3b49740ae480f8c9719582be6af0fa624faffe96f268a44ded6981a6e3310cd20663e0d3226a0b27bb33b4952cad3fa02cb942f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.13
|
4
|
+
|
5
|
+
- Alternate URLs were adding the locale innecessarily!
|
6
|
+
|
7
|
+
## 0.1.12
|
8
|
+
|
9
|
+
- Reset and setup every site so generators like jekyll-archive are
|
10
|
+
reloaded. Otherwise we may have data copied over from the previous
|
11
|
+
locale.
|
12
|
+
|
13
|
+
## 0.1.11
|
14
|
+
|
15
|
+
- Add alternate URLs to link between languages when using
|
16
|
+
jekyll-linked-posts
|
17
|
+
|
18
|
+
## 0.1.10
|
19
|
+
|
20
|
+
- Prevent cleanup from removing other languages
|
21
|
+
|
3
22
|
## 0.1.9
|
4
23
|
|
5
24
|
- Loading locales as collection makes Jekyll render them even when
|
data/README.md
CHANGED
@@ -64,6 +64,12 @@ locales:
|
|
64
64
|
|
65
65
|
Then you can access them by using `page.locales` in your layout.
|
66
66
|
|
67
|
+
**Tip:** You can use
|
68
|
+
[jekyll-linked-posts](https://rubygems.org/gems/jekyll-linked-posts) to
|
69
|
+
make this process more resilient. It uses IDs instead of URLs and it
|
70
|
+
also allows you to access other data. From v0.1.11 it will also
|
71
|
+
generate alternate URLs so search engines can link between translations.
|
72
|
+
|
67
73
|
### Pages
|
68
74
|
|
69
75
|
You can translate the front matter by adding locale-specific variables
|
data/jekyll-locales.gemspec
CHANGED
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
|
36
36
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
37
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
38
|
-
spec.add_development_dependency 'rake', '~>
|
38
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
39
39
|
spec.add_development_dependency 'rubocop', '~> 0.74'
|
40
40
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# We keep a global variable with the site in it because we can't access
|
4
|
+
# it from the cleanup hook.
|
5
|
+
$site = nil
|
6
|
+
|
7
|
+
# Only run on the default locale since it's going to be in the root
|
8
|
+
# destination
|
9
|
+
Jekyll::Hooks.register :site, :post_render do |site|
|
10
|
+
next unless site.locales?
|
11
|
+
next unless site.default_locale?
|
12
|
+
|
13
|
+
$site = site
|
14
|
+
end
|
15
|
+
|
16
|
+
# Keep files in other locales since they're not generated by the default
|
17
|
+
# locale.
|
18
|
+
Jekyll::Hooks.register :clean, :on_obsolete do |obsolete|
|
19
|
+
next if $site.nil?
|
20
|
+
|
21
|
+
$site.locales.each do |locale|
|
22
|
+
next if locale == $site.locale
|
23
|
+
|
24
|
+
obsolete.delete_if do |x|
|
25
|
+
x.sub($site.dest + '/', '').start_with? locale
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Jekyll::Hooks.register :site, :post_render do |site|
|
4
|
+
unless site.config['plugins'].include? 'jekyll-linked-posts'
|
5
|
+
Jekyll.logger.warn 'Enable jekyll-linked-posts to generate metadata about alternate pages'
|
6
|
+
next
|
7
|
+
end
|
8
|
+
|
9
|
+
# URLs can be relative but Google asks for fully qualified URLs
|
10
|
+
# @see {https://support.google.com/webmasters/answer/189077?hl=en}
|
11
|
+
url = site.config['url']&.sub(%r{/\z}, '')
|
12
|
+
|
13
|
+
unless url
|
14
|
+
Jekyll.logger.warn 'Provide a `url` value in configuration to create fully qualified URLs'
|
15
|
+
next
|
16
|
+
end
|
17
|
+
|
18
|
+
site.documents.each do |doc|
|
19
|
+
next if doc.output.nil?
|
20
|
+
next unless doc&.data&.dig 'locales'
|
21
|
+
|
22
|
+
alternate = doc.data['locales'].map do |translation|
|
23
|
+
locale = translation.collection.label
|
24
|
+
# TODO: Every doc should know how to build their own URL
|
25
|
+
doc_url = [url, translation.url].join('/')
|
26
|
+
|
27
|
+
%(<link rel="alternate" hreflang="#{locale}" href="#{doc_url}" />)
|
28
|
+
end
|
29
|
+
|
30
|
+
next if alternate.empty?
|
31
|
+
|
32
|
+
doc.output.sub! '<head>', '<head>' + alternate.join
|
33
|
+
end
|
34
|
+
end
|
data/lib/jekyll/locales/site.rb
CHANGED
@@ -27,6 +27,8 @@ module Jekyll
|
|
27
27
|
Jekyll.logger.info 'Base URL:', config['baseurl']
|
28
28
|
|
29
29
|
symlink
|
30
|
+
reset
|
31
|
+
setup
|
30
32
|
process_single
|
31
33
|
# The default locale is placed at the root of the
|
32
34
|
# site and everything else is under a subdirectory, but we symlink
|
@@ -43,6 +45,23 @@ module Jekyll
|
|
43
45
|
copy_redirector if redirect?
|
44
46
|
end
|
45
47
|
|
48
|
+
def locales?
|
49
|
+
locales.length > 1
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get locales from configuration
|
53
|
+
def locales
|
54
|
+
@locales ||= config.fetch('locales', [])
|
55
|
+
end
|
56
|
+
|
57
|
+
def default_locale
|
58
|
+
@default_locale ||= locales.first
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_locale?
|
62
|
+
default_locale == locale
|
63
|
+
end
|
64
|
+
|
46
65
|
private
|
47
66
|
|
48
67
|
# Redefine #render_docs so it doesn't render the locale collections
|
@@ -60,10 +79,6 @@ module Jekyll
|
|
60
79
|
end
|
61
80
|
end
|
62
81
|
|
63
|
-
def locales?
|
64
|
-
locales.size > 1
|
65
|
-
end
|
66
|
-
|
67
82
|
def locale_config
|
68
83
|
# XXX: Retrocompatibility
|
69
84
|
config['locale'] = config['lang'] = locale
|
@@ -80,19 +95,6 @@ module Jekyll
|
|
80
95
|
config['baseurl'] = locale_baseurl
|
81
96
|
end
|
82
97
|
|
83
|
-
# Get locales from configuration
|
84
|
-
def locales
|
85
|
-
@locales ||= config.fetch('locales', [])
|
86
|
-
end
|
87
|
-
|
88
|
-
def default_locale
|
89
|
-
@default_locale ||= locales.first
|
90
|
-
end
|
91
|
-
|
92
|
-
def default_locale?
|
93
|
-
default_locale == locale
|
94
|
-
end
|
95
|
-
|
96
98
|
# Read the other locales as collections but don't render them, only
|
97
99
|
# make them available to templates.
|
98
100
|
#
|
@@ -173,6 +175,7 @@ module Jekyll
|
|
173
175
|
end
|
174
176
|
|
175
177
|
def self_symlink
|
178
|
+
FileUtils.rm_f(locale_destination)
|
176
179
|
FileUtils.ln_s('.', locale_destination)
|
177
180
|
end
|
178
181
|
end
|
data/lib/jekyll/locales.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-locales
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- ".travis.yml"
|
81
81
|
- CHANGELOG.md
|
82
82
|
- Gemfile
|
83
|
-
- Gemfile.lock
|
84
83
|
- LICENSE
|
85
84
|
- README.md
|
86
85
|
- Rakefile
|
@@ -90,7 +89,9 @@ files:
|
|
90
89
|
- jekyll-locales.gemspec
|
91
90
|
- lib/jekyll-locales.rb
|
92
91
|
- lib/jekyll/locales.rb
|
92
|
+
- lib/jekyll/locales/hooks/cleanup.rb
|
93
93
|
- lib/jekyll/locales/hooks/page_post_init.rb
|
94
|
+
- lib/jekyll/locales/hooks/post_render.rb
|
94
95
|
- lib/jekyll/locales/site.rb
|
95
96
|
- lib/jekyll/locales/site_drop.rb
|
96
97
|
- lib/jekyll/locales/version.rb
|
@@ -101,7 +102,7 @@ metadata:
|
|
101
102
|
homepage_uri: https://0xacab.org/sutty/jekyll/jekyll-locales
|
102
103
|
source_code_uri: https://0xacab.org/sutty/jekyll/jekyll-locales
|
103
104
|
changelog_uri: https://0xacab.org/sutty/jekyll/jekyll-locales/blob/master/CHANGELOG.md
|
104
|
-
post_install_message:
|
105
|
+
post_install_message:
|
105
106
|
rdoc_options: []
|
106
107
|
require_paths:
|
107
108
|
- lib
|
@@ -116,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
120
|
-
signing_key:
|
120
|
+
rubygems_version: 3.1.2
|
121
|
+
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: Jekyll plugin for localized sites
|
123
124
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
jekyll-locales (0.1.9)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.0)
|
10
|
-
jaro_winkler (1.5.3)
|
11
|
-
minitest (5.11.3)
|
12
|
-
parallel (1.17.0)
|
13
|
-
parser (2.6.4.1)
|
14
|
-
ast (~> 2.4.0)
|
15
|
-
rainbow (3.0.0)
|
16
|
-
rake (10.5.0)
|
17
|
-
rubocop (0.74.0)
|
18
|
-
jaro_winkler (~> 1.5.1)
|
19
|
-
parallel (~> 1.10)
|
20
|
-
parser (>= 2.6)
|
21
|
-
rainbow (>= 2.2.2, < 4.0)
|
22
|
-
ruby-progressbar (~> 1.7)
|
23
|
-
unicode-display_width (>= 1.4.0, < 1.7)
|
24
|
-
ruby-progressbar (1.10.1)
|
25
|
-
unicode-display_width (1.6.0)
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
bundler (~> 2.0)
|
32
|
-
jekyll-locales!
|
33
|
-
minitest (~> 5.0)
|
34
|
-
rake (~> 10.0)
|
35
|
-
rubocop (~> 0.74)
|
36
|
-
|
37
|
-
BUNDLED WITH
|
38
|
-
2.1.4
|