Skip to content

Commit 9a2c62d

Browse files
committed
Add locale-aware link helper for consistent URLs
Ensures locale links include the full host (production or localhost) and trailing slash, fixing broken links in different environments.
1 parent fea1505 commit 9a2c62d

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

config.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@
3737
def current_page?(path)
3838
current_page.url.chomp('/') == path.chomp('/')
3939
end
40+
41+
def locale_link_to(text, path, options = {})
42+
path = "#{path}/" unless path.end_with?('/')
43+
host = build? ? data.site.host : "http://localhost:#{config[:port]}"
44+
link_to(text, "#{host}#{path}", options)
45+
end
4046
end

source/_footer.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<footer class="w-full pt-32 pb-4">
22
<ul class="flex justify-center items-center tracking-tight gap-2 text-lg">
33
<li>
4-
<%= link_to "EN", "/", class: "font-semibold p-1 #{"active" unless current_page?("/") }" %>
4+
<%= locale_link_to "EN", "/", class: "font-semibold p-1 #{"active" unless current_page?("/")}" %>
55
</li>
66
<li class="text-gray-400 font-extralight text-xs">
77
/
88
</li>
99
<li>
10-
<%= link_to "FR", '/acp/', class: "font-semibold p-1 #{"active" unless current_page?('/acp/') }" %>
10+
<%= locale_link_to "FR", "/acp", class: "font-semibold p-1 #{"active" unless current_page?("/acp/")}" %>
1111
</li>
1212
<li class="text-gray-400 font-extralight text-xs">
1313
/
1414
</li>
1515
<li>
16-
<%= link_to 'DE', '/solawi/', class: "font-semibold p-1 #{"active" unless current_page?('/solawi/') }" %>
16+
<%= locale_link_to "DE", "/solawi", class: "font-semibold p-1 #{"active" unless current_page?("/solawi/")}" %>
1717
</li>
1818
</ul>
1919

source/_header.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<%= inline_svg 'logo.svg', class: 'fill-current w-10 h-10 md:w-12 md:h-12', alt: t("logo_alt") %>
44
<nav class="text-logo-green ml-3 font-bold text-2xl tracking-tight flex items-center">
55
<span>
6-
<%= link_to "CSA", "/", class: "font-bold #{"no-underline" unless I18n.locale == :en} decoration-2 hover:underline" %>
6+
<%= locale_link_to "CSA", "/", class: "font-bold #{"no-underline" unless I18n.locale == :en} decoration-2 hover:underline" %>
77
</span>
88
<span class="font-extralight text-base px-1 md:px-2">
99
/
1010
</span>
1111
<span>
12-
<%= link_to "ACP", "/acp/", class: "font-bold #{"no-underline" unless I18n.locale == :fr} decoration-2 hover:underline" %>
12+
<%= locale_link_to "ACP", "/acp", class: "font-bold #{"no-underline" unless I18n.locale == :fr} decoration-2 hover:underline" %>
1313
</span>
1414
<span class="font-extralight text-base px-1 md:px-2">
1515
/
1616
</span>
1717
<span>
18-
<%= link_to "Solawi", "/solawi/", class: "font-bold #{"no-underline" unless I18n.locale == :de} decoration-2 hover:underline" %>
18+
<%= locale_link_to "Solawi", "/solawi", class: "font-bold #{"no-underline" unless I18n.locale == :de} decoration-2 hover:underline" %>
1919
</span>
2020
<span class="ml-3">
2121
Admin

0 commit comments

Comments
 (0)