jekyll-l10n 1.2.7 → 1.2.8
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 +4 -4
- data/lib/jekyll-l10n/utils/url_transformer.rb +42 -14
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c5a4a4261253d5efb8103b3d8896bff9960249f4d6ed69266c0016729b38da43
|
|
4
|
+
data.tar.gz: 582bb044c024621b3bee6407f0ef6f2c6d3f3de8cbca9df14c2449702aaeb446
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb0212b0e62d331499629fe94eb3983dbaba9d4414804be1f1846873619935acbecf8f26d405b5c10cdc4400bdd246c23f35697ab67bc58deae24b506280f516
|
|
7
|
+
data.tar.gz: dde77b84bb811f0e08fb3bf4cf613cc8cef18bb39e907c7b0bf53a6c0993e33c399bf8b089cab60cbbe5e597725616aae1575b2c21fc9372c299759430c393ba
|
|
@@ -84,11 +84,11 @@ module Jekyll
|
|
|
84
84
|
false
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
def should_transform_href?(href, locale,
|
|
87
|
+
def should_transform_href?(href, locale, baseurl)
|
|
88
88
|
return false if invalid_href?(href)
|
|
89
89
|
return false if external_or_special_link?(href)
|
|
90
90
|
return false if relative_path?(href)
|
|
91
|
-
return false if already_localized?(href, locale)
|
|
91
|
+
return false if already_localized?(href, locale, baseurl)
|
|
92
92
|
|
|
93
93
|
true
|
|
94
94
|
end
|
|
@@ -105,8 +105,14 @@ module Jekyll
|
|
|
105
105
|
href.start_with?(".")
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
def already_localized?(href, locale)
|
|
109
|
-
|
|
108
|
+
def already_localized?(href, locale, baseurl = "")
|
|
109
|
+
# Normalize the path by stripping the baseurl if present
|
|
110
|
+
normalized_path = normalize_path(href, baseurl)
|
|
111
|
+
|
|
112
|
+
# Skip transformation if:
|
|
113
|
+
# 1. Path starts with the target locale: /es/page (prevent /es/es/page duplication)
|
|
114
|
+
# 2. Path contains any locale code: /fr/page (preserve language dropdown links)
|
|
115
|
+
normalized_path.start_with?("/#{locale}/") || locale_prefix?(normalized_path)
|
|
110
116
|
end
|
|
111
117
|
|
|
112
118
|
def language_dropdown_link?(link)
|
|
@@ -114,24 +120,46 @@ module Jekyll
|
|
|
114
120
|
link_classes.split.any? { |c| c == "dropdown-item" }
|
|
115
121
|
end
|
|
116
122
|
|
|
117
|
-
def
|
|
118
|
-
|
|
119
|
-
return
|
|
123
|
+
def normalize_path(href, baseurl)
|
|
124
|
+
# Strip the baseurl prefix if it's present, to get the actual path we're checking
|
|
125
|
+
return href if baseurl.nil? || baseurl.empty?
|
|
126
|
+
|
|
127
|
+
# SECURITY: Only strip if baseurl is followed by "/" (path component boundary)
|
|
128
|
+
# This prevents "/api" from matching "/api2/page" or "/apiurl/page"
|
|
129
|
+
if href == baseurl
|
|
130
|
+
# Exact match: return root path
|
|
131
|
+
"/"
|
|
132
|
+
elsif href.start_with?("#{baseurl}/")
|
|
133
|
+
# Proper path component: strip the baseurl but preserve leading slash
|
|
134
|
+
# href is "/base/es/page", baseurl is "/base"
|
|
135
|
+
# We want to return "/es/page"
|
|
136
|
+
href[baseurl.length..] # Returns "/es/page"
|
|
120
137
|
|
|
121
|
-
|
|
122
|
-
|
|
138
|
+
else
|
|
139
|
+
# Not a match: return as-is
|
|
140
|
+
href
|
|
141
|
+
end
|
|
142
|
+
end
|
|
123
143
|
|
|
124
|
-
|
|
125
|
-
|
|
144
|
+
def locale_prefix?(path)
|
|
145
|
+
# Check if the path contains a locale code
|
|
146
|
+
# After stripping baseurl, this detects: /es/, /fr/, /pt_BR/, /zh-CN/, etc.
|
|
147
|
+
path.match?(%r!/[a-z]{2}(?:[_-][A-Z]{2})?(?:/|$)!)
|
|
126
148
|
end
|
|
127
149
|
|
|
128
150
|
def add_locale_prefix(href, locale, baseurl)
|
|
129
151
|
return "/#{locale}#{href}" unless baseurl && !baseurl.empty?
|
|
130
152
|
|
|
131
|
-
if
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
# SECURITY: Only strip if baseurl is followed by "/" (path component boundary)
|
|
154
|
+
if href == baseurl
|
|
155
|
+
# Exact match: add locale after baseurl
|
|
156
|
+
"#{baseurl}/#{locale}"
|
|
157
|
+
elsif href.start_with?("#{baseurl}/")
|
|
158
|
+
# Proper path component: insert locale after baseurl
|
|
159
|
+
relative_path = href[(baseurl.length + 1)..]
|
|
160
|
+
"#{baseurl}/#{locale}/#{relative_path}"
|
|
134
161
|
else
|
|
162
|
+
# Not a match: add locale before href
|
|
135
163
|
"#{baseurl}/#{locale}#{href}"
|
|
136
164
|
end
|
|
137
165
|
end
|