jekyll-locales 0.1.6 → 0.1.12

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: aa3a9eda7415b229d8e3e3a70c79a9b4df8ea967e3c5c24d71a98f41d5ffcecc
4
- data.tar.gz: a62f6a4b330051558a4b93f7aa87e00700eb10469fdfbe07349cd510f9507454
3
+ metadata.gz: 54c81880cbcc03380bb37dd51d45867e933eee78d3375f3cb4d3ad91e9112b99
4
+ data.tar.gz: 1711e490f86a58661a557ace3d3dd8235b32449a6a947044f46bdbe0979cdc8e
5
5
  SHA512:
6
- metadata.gz: c3b2d4214a63d1c7da7b472edb2c997b808749e759e308bdb5704862b3705fa3bee0bcc242c7ef296da6e64133ef6b995e01ec436cec4499cde78c41f3eb8edb
7
- data.tar.gz: faf5e2bf08714ae0c4b5c615f849600b747821238cb3c58d1020f85f4b17a28c3d61293d5b3b287ae5a0c40ebfa4c3b052377b52ac2c19ef0dbda6b87144f2c4
6
+ metadata.gz: 146340186cc3ce7e89cfcb1a516219d1ccbfa5209945350496eecfd7a28b4b58e3a04b81f42fae127ca0cff5e40065b06dbc0cb7b8e0bf78c56c321a77e8228a
7
+ data.tar.gz: f4f11f13796403ff68661f66925950909fc83967939c466c9878fed42da3e1f3d203b7b9f760f08c1d649a08602d391ca198824832f49ccf17d41500f3d99be6
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.12
4
+
5
+ - Reset and setup every site so generators like jekyll-archive are
6
+ reloaded. Otherwise we may have data copied over from the previous
7
+ locale.
8
+
9
+ ## 0.1.11
10
+
11
+ - Add alternate URLs to link between languages when using
12
+ jekyll-linked-posts
13
+
14
+ ## 0.1.10
15
+
16
+ - Prevent cleanup from removing other languages
17
+
18
+ ## 0.1.9
19
+
20
+ - Loading locales as collection makes Jekyll render them even when
21
+ they're not part of output. This version prevents that. A site with
22
+ three languages was taking 160 seconds before and 60 after patching!
23
+
24
+ ## 0.1.8
25
+
26
+ - Load other locales as collections to make them available in templates.
27
+ Compatible with
28
+ [jekyll-linked-posts](https://rubygems.org/gems/jekyll-linked-posts).
29
+
3
30
  ## 0.1.0
4
31
 
5
32
  - Localized Jekyll sites
data/README.md CHANGED
@@ -33,10 +33,13 @@ locales:
33
33
  - en
34
34
  - ahr
35
35
  - brasileiro
36
+ redirect: true
36
37
  ```
37
38
 
38
- **The first locale is going to be your default locale**. It doesn't do
39
- much, but still have it in mind.
39
+ **The first locale is going to be your default locale**. If you use
40
+ a redirector.html, it will be the locale it will redirector to. If you
41
+ don't use a redirector, the default locale will be at the root of the
42
+ site.
40
43
 
41
44
  ## Posts
42
45
 
@@ -61,6 +64,12 @@ locales:
61
64
 
62
65
  Then you can access them by using `page.locales` in your layout.
63
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
+
64
73
  ### Pages
65
74
 
66
75
  You can translate the front matter by adding locale-specific variables
@@ -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', '~> 10.0'
38
+ spec.add_development_dependency 'rake', '~> 12.0'
39
39
  spec.add_development_dependency 'rubocop', '~> 0.74'
40
40
  end
@@ -4,3 +4,5 @@ require 'jekyll/site'
4
4
  require 'jekyll/locales/site'
5
5
  require 'jekyll/locales/site_drop'
6
6
  require 'jekyll/locales/hooks/page_post_init'
7
+ require 'jekyll/locales/hooks/post_render'
8
+ require 'jekyll/locales/hooks/cleanup'
@@ -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,35 @@
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.each_site_file do |doc|
19
+ next unless doc.is_a? Jekyll::Document
20
+ next if doc.output.nil?
21
+ next unless doc&.data&.dig 'locales'
22
+
23
+ alternate = doc.data['locales'].map do |translation|
24
+ locale = translation.collection.label
25
+ # TODO: Every doc should know how to build their own URL
26
+ doc_url = [url, locale, translation.url].join('/')
27
+
28
+ %(<link rel="alternate" hreflang="#{locale}" href="#{doc_url}" />)
29
+ end
30
+
31
+ next if alternate.empty?
32
+
33
+ doc.output.sub! '<head>', '<head>' + alternate.join
34
+ end
35
+ end
@@ -27,22 +27,56 @@ module Jekyll
27
27
  Jekyll.logger.info 'Base URL:', config['baseurl']
28
28
 
29
29
  symlink
30
+ reset
31
+ setup
30
32
  process_single
33
+ # The default locale is placed at the root of the
34
+ # site and everything else is under a subdirectory, but we symlink
35
+ # root to default_locale for compatibility
36
+ self_symlink if default_locale? && !redirect?
31
37
  end
32
38
 
33
- if locales?
34
- copy_redirector
35
- default_delete
36
- default_symlink
37
- else
38
- self_symlink
39
- end
39
+ # XXX: Default is expected by Sutty so we always create it
40
+ default_delete
41
+ default_symlink
42
+
43
+ # If we enable the redirector, the root of the site will consist
44
+ # of an index.html that allows visitors to select their locale.
45
+ copy_redirector if redirect?
46
+ end
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
40
63
  end
41
64
 
42
65
  private
43
66
 
44
- def locales?
45
- locales.size > 1
67
+ # Redefine #render_docs so it doesn't render the locale collections
68
+ # for each independent locale.
69
+ #
70
+ # XXX: Jekyll should render on demand instead of rendering and
71
+ # writing separately.
72
+ def render_docs(payload)
73
+ collections.each do |name, collection|
74
+ next if locales.include? name
75
+
76
+ collection.docs.each do |document|
77
+ render_regenerated(document, payload)
78
+ end
79
+ end
46
80
  end
47
81
 
48
82
  def locale_config
@@ -50,19 +84,32 @@ module Jekyll
50
84
  config['locale'] = config['lang'] = locale
51
85
  config['default_locale'] = default_locale
52
86
 
87
+ # Don't touch the config unless there's more than one locale or we
88
+ # aren't using a redirector
53
89
  return unless locales?
54
90
 
91
+ other_locales_as_collections
92
+ return if default_locale? && !redirect?
93
+
55
94
  @dest = config['destination'] = locale_destination
56
95
  config['baseurl'] = locale_baseurl
57
96
  end
58
97
 
59
- # Get locales from configuration
60
- def locales
61
- @locales ||= config.fetch('locales', [])
62
- end
63
-
64
- def default_locale
65
- locales.first
98
+ # Read the other locales as collections but don't render them, only
99
+ # make them available to templates.
100
+ #
101
+ # The URL will be the permalink with the language prepended.
102
+ #
103
+ # {https://rubygems.org/gems/jekyll-linked-posts}
104
+ def other_locales_as_collections
105
+ locales.each do |l|
106
+ next if l == locale
107
+
108
+ config['collections'][l] = {
109
+ 'output' => false,
110
+ 'permalink' => [nil, l, config['permalink']].join('/')
111
+ }
112
+ end
66
113
  end
67
114
 
68
115
  # Cache original destination
@@ -92,6 +139,10 @@ module Jekyll
92
139
  FileUtils.ln_s("_#{locale}", '_posts')
93
140
  end
94
141
 
142
+ def redirect?
143
+ config.fetch('redirect', false)
144
+ end
145
+
95
146
  # TODO: Make configurable
96
147
  def redirector
97
148
  @redirector ||= File.join(locale_destination, 'redirector.html')
@@ -124,6 +175,7 @@ module Jekyll
124
175
  end
125
176
 
126
177
  def self_symlink
178
+ FileUtils.rm_f(locale_destination)
127
179
  FileUtils.ln_s('.', locale_destination)
128
180
  end
129
181
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Locales
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.12'
6
6
  end
7
7
  end
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.6
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2020-07-28 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: '10.0'
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: '10.0'
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,9 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.6.2
121
- signing_key:
120
+ rubygems_version: 3.0.3
121
+ signing_key:
122
122
  specification_version: 4
123
123
  summary: Jekyll plugin for localized sites
124
124
  test_files: []
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll-locales (0.1.6)
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.0.2