arosa 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f09b3cdb8e69dcc529ac94d1f2ec7ebfaa847b72a24a394f5f07eb3175151b8a
4
- data.tar.gz: 12ef90466baf566e70e0eb6603f6bb216be2ce8e5905552266e918204a4bc3d9
3
+ metadata.gz: 7685471c75ede43f503a18f563da2f1374994f01ad3dffaea4a65c96faf9d6e9
4
+ data.tar.gz: 3e122ff6e1eac8bd6d0140bc3367329383538a7b9b7b6ee90ad4cbed37adbcea
5
5
  SHA512:
6
- metadata.gz: 0b2f45d647c9d76c7246202b3be8d1368ec2fe940f06d4992c7e0a27c2e32ef817504f269d852192a74ba726426f3a159c2014e48ad21e179f8297bff21a296c
7
- data.tar.gz: 16efd5e926b9990b09c3d1c4c68cd264e6e61d2c66138cfda25e233bb25c1f4ade06a93760d6d5e8aa1eaa09a01adc04c2146c5eca0fafe669cbab0cd8bc4a53
6
+ metadata.gz: 986b0ecdcd2d8e3fdb1f328b729276da2f7f370b30ff3261c2665d9c221ebd9ece4713e1303241cad61aad75829ad2c93b5e1e778ffb431420e9430d909ccf78
7
+ data.tar.gz: ef76f0213eabda3b4ef5a7ff760403cd3dc6e0f60fa2b08a3f68cc3bed36161e59ee7d14b083d81cf872b0b8136704b73a794b18e035f1a91aaacb4b0afd82e9
data/README.md CHANGED
@@ -50,6 +50,7 @@ Arosa.config.twitter_site = "@acme"
50
50
  | `hreflang_pattern` | Custom URL pattern. Use `:locale` and `:path` as placeholders. Default: `/:locale/path` |
51
51
  | `hreflang_opt_in` | Pages must opt in to hreflang instead of global. Default: `false` |
52
52
  | `hreflang_default` | Locale for `x-default`. Default: first in the `hreflang` array |
53
+ | `hreflang_prefix_default` | Prefix the default locale in URLs. Default: `false` |
53
54
  | `auto_og` | Auto-generate Open Graph tags from title/description. Default: `true` |
54
55
  | `auto_twitter` | Auto-generate Twitter Card tags from title/description. Default: `true` |
55
56
  | `twitter_site` | Your X/Twitter handle (e.g. `"@acme"`). Included in all Twitter Cards |
@@ -242,19 +243,23 @@ Output:
242
243
 
243
244
  Configure your locales in the initializer (see [Configuration](#configuration)). Hreflang tags are generated automatically on every page.
244
245
 
245
- Output (on `https://example.com/articles/1`):
246
+ The default locale (first in the array) is unprefixed. Other locales get a `/:locale` prefix.
247
+
248
+ Output (on `https://example.com/articles/1` with `hreflang: ["en", "de", "fr", "it"]`):
246
249
 
247
250
  ```html
248
- <link rel="alternate" hreflang="en" href="https://example.com/en/articles/1">
251
+ <link rel="alternate" hreflang="en" href="https://example.com/articles/1">
249
252
  <link rel="alternate" hreflang="de" href="https://example.com/de/articles/1">
250
253
  <link rel="alternate" hreflang="fr" href="https://example.com/fr/articles/1">
251
254
  <link rel="alternate" hreflang="it" href="https://example.com/it/articles/1">
252
- <link rel="alternate" hreflang="x-default" href="https://example.com/en/articles/1">
255
+ <link rel="alternate" hreflang="x-default" href="https://example.com/articles/1">
253
256
  ```
254
257
 
258
+ If all locales are prefixed (including the default), set `hreflang_prefix_default` to `true` in the config.
259
+
255
260
  An `x-default` tag is automatically included, pointing to the first locale in the array. Override with `hreflang_default` in the config.
256
261
 
257
- By default, URLs are built as `/:locale/path`. For other structures, set `hreflang_pattern` in the config.
262
+ For other URL structures, set `hreflang_pattern` in the config.
258
263
 
259
264
  URL parameters are also supported but [not recommended by Google](https://developers.google.com/search/docs/specialty/international/managing-multi-regional-sites):
260
265
 
data/lib/arosa/config.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  module Arosa
4
4
  class Config
5
5
  attr_accessor :separator, :hreflang, :hreflang_pattern,
6
- :hreflang_opt_in, :hreflang_default, :auto_canonical,
7
- :auto_og, :auto_twitter, :twitter_site
6
+ :hreflang_opt_in, :hreflang_default, :hreflang_prefix_default,
7
+ :auto_canonical, :auto_og, :auto_twitter, :twitter_site
8
8
 
9
9
  def to_h
10
10
  h = {}
@@ -13,6 +13,7 @@ module Arosa
13
13
  h[:hreflang_pattern] = hreflang_pattern if hreflang_pattern
14
14
  h[:hreflang_opt_in] = hreflang_opt_in unless hreflang_opt_in.nil?
15
15
  h[:hreflang_default] = hreflang_default if hreflang_default
16
+ h[:hreflang_prefix_default] = hreflang_prefix_default unless hreflang_prefix_default.nil?
16
17
  h[:auto_canonical] = auto_canonical unless auto_canonical.nil?
17
18
  h[:auto_og] = auto_og unless auto_og.nil?
18
19
  h[:auto_twitter] = auto_twitter unless auto_twitter.nil?
data/lib/arosa/meta.rb CHANGED
@@ -110,14 +110,16 @@ module Arosa
110
110
  origin = "#{request.scheme}://#{request.host}"
111
111
 
112
112
  x_default = merged[:hreflang_default] || default_locales&.first
113
+ prefix_default = merged[:hreflang_prefix_default]
113
114
 
114
115
  tags = locales.map do |locale|
115
- href = build_hreflang_href(locale, pattern, fullpath, origin)
116
+ skip = !prefix_default && locale.to_s == x_default.to_s
117
+ href = build_hreflang_href(locale, pattern, fullpath, origin, skip_prefix: skip)
116
118
  %(<link rel="alternate" hreflang="#{escape(locale)}" href="#{escape(href)}">)
117
119
  end
118
120
 
119
121
  if x_default
120
- href = build_hreflang_href(x_default, pattern, fullpath, origin)
122
+ href = build_hreflang_href(x_default, pattern, fullpath, origin, skip_prefix: !prefix_default)
121
123
  tags << %(<link rel="alternate" hreflang="x-default" href="#{escape(href)}">)
122
124
  end
123
125
 
@@ -166,8 +168,10 @@ module Arosa
166
168
  fullpath
167
169
  end
168
170
 
169
- def build_hreflang_href(locale, pattern, fullpath, origin)
170
- if pattern
171
+ def build_hreflang_href(locale, pattern, fullpath, origin, skip_prefix: false)
172
+ if skip_prefix
173
+ "#{origin}#{fullpath}"
174
+ elsif pattern
171
175
  pattern.gsub(":locale", locale.to_s).gsub(":path", fullpath)
172
176
  else
173
177
  "#{origin}/#{locale}#{fullpath}"
data/lib/arosa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arosa
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arosa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuenti