jekyll-locales 0.1.10 → 0.1.11

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: 6b8cd80411bc24509a21502d5972966dd9cb990ec1716aacc19724855e8c957b
4
- data.tar.gz: 557fdfd91a846aa99f180076b186ddf21fad118cc0b01de438e66e0a7303c2bd
3
+ metadata.gz: 8064e214d9d871fab3a7d775064068f01acbf3194d8776601be47b245452b783
4
+ data.tar.gz: e00d19218061374a29e73baea210ad871535ff40c5bf3e775b5d1fa57ed04f5c
5
5
  SHA512:
6
- metadata.gz: 2d3826a63a1f0d581e4c9a0e516680fe012f99c88d6ad62a761e61140a3a25f1c71ca9ea08853155c7a817d3919f32715c0b20dd9d87c1383e052984c55832a5
7
- data.tar.gz: 5471c147d18a8bd76445857b4251902c454d09f123e4e64e177fd7df02c0d4b1789b465c465e590ca8f590f9539af9fc35602623579137d8b8acabb161cb2b5f
6
+ metadata.gz: 5b14589c075687b8f9c498b9b670339b37901690b4b51aebcd6b994d68d4b53d12ed47f42579df9abf8afd46a6585d7d3888eff420b22b79c742759b1325934e
7
+ data.tar.gz: 59d3a80ac8136b4b5e15343b4f25598c1468cde8797b6efae816f1303995d92c4559b9d26e73a460cea269965017e34dcf664d67eb2765b26534d385c043e612
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.11
4
+
5
+ - Add alternate URLs to link between languages when using
6
+ jekyll-linked-posts
7
+
8
+ ## 0.1.10
9
+
10
+ - Prevent cleanup from removing other languages
11
+
3
12
  ## 0.1.9
4
13
 
5
14
  - 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
@@ -4,4 +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'
7
8
  require 'jekyll/locales/hooks/cleanup'
@@ -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
@@ -173,6 +173,7 @@ module Jekyll
173
173
  end
174
174
 
175
175
  def self_symlink
176
+ FileUtils.rm_f(locale_destination)
176
177
  FileUtils.ln_s('.', locale_destination)
177
178
  end
178
179
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Locales
5
- VERSION = '0.1.10'
5
+ VERSION = '0.1.11'
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.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - lib/jekyll/locales.rb
92
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
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubygems_version: 3.0.3
120
- signing_key:
121
+ signing_key:
121
122
  specification_version: 4
122
123
  summary: Jekyll plugin for localized sites
123
124
  test_files: []