Skip to content

Commit d0110da

Browse files
committed
Exclude hashed links (start with '#') from mailer header and footer nav items
1 parent 19d8b04 commit d0110da

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

app/helpers/better_together/navigation_items_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def platform_footer_nav_area
7575
@platform_footer_nav_area ||= ::BetterTogether::NavigationArea.find_by(identifier: 'platform-footer')
7676
end
7777

78+
# Retrieves navigation items for the mailer footer.
79+
def mailer_footer_nav_items
80+
# Preload navigation items and their translations in a single query
81+
Mobility.with_locale(current_locale) do
82+
@mailer_footer_nav_items ||= platform_footer_nav_area&.top_level_nav_items_includes_children.excluding_hashed || []
83+
end
84+
end
85+
7886
# Retrieves navigation items for the platform footer.
7987
def platform_footer_nav_items
8088
# Preload navigation items and their translations in a single query
@@ -101,6 +109,14 @@ def platform_header_nav_items
101109
end
102110
end
103111

112+
# Retrieves navigation items for the mailer header.
113+
def mailer_header_nav_items
114+
# Preload navigation items and their translations in a single query
115+
Mobility.with_locale(current_locale) do
116+
@mailer_header_nav_items ||= platform_header_nav_area.top_level_nav_items_includes_children.excluding_hashed || []
117+
end
118+
end
119+
104120
def render_platform_header_nav_items
105121
Rails.cache.fetch(cache_key_for_nav_area(platform_header_nav_area)) do
106122
render 'better_together/navigation_items/navigation_items', navigation_items: platform_header_nav_items

app/models/better_together/navigation_item.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def self.route_name_urls
100100
joins(join).where(combined_conditions)
101101
}
102102

103+
scope :excluding_hashed, -> { where.not('url ILIKE ?', '#%') }
104+
103105
def build_children(pages, navigation_area) # rubocop:todo Metrics/MethodLength
104106
pages.each_with_index do |page, index|
105107
children.build(

app/views/layouts/better_together/mailers/_footer.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<table id="footer-pages-nav" class="navbar" width="600" cellpadding="0" cellspacing="0" border="0" style="margin: 0 auto;">
77
<tr>
88
<td class="container-fluid text-center" align="center">
9-
<% platform_footer_nav_items.each_with_index do |nav_item, index| %>
10-
<%= link_to nav_item, nav_item.url, class: 'text-decoration-none' %><% if index < (platform_footer_nav_items.size - 1) %> | <% end %>
9+
<% mailer_footer_nav_items.each_with_index do |nav_item, index| %>
10+
<%= link_to nav_item, nav_item.url, class: 'text-decoration-none' %><% if index < (mailer_footer_nav_items.size - 1) %> | <% end %>
1111
<% end %>
1212
</td>
1313
</tr>

app/views/layouts/better_together/mailers/_header.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</tr>
1111
<tr>
1212
<td class="" style="margin-bottom: 24px;" align="center">
13-
<% platform_header_nav_items.each_with_index do |nav_item, index| %>
14-
<%= link_to nav_item, nav_item.url, class: 'text-decoration-none' %><% if index < (platform_header_nav_items.size - 1) %> | <% end %>
13+
<% mailer_header_nav_items.each_with_index do |nav_item, index| %>
14+
<%= link_to nav_item, nav_item.url, class: 'text-decoration-none' %><% if index < (mailer_header_nav_items.size - 1) %> | <% end %>
1515
<% end %>
1616
</td>
1717
</tr>

0 commit comments

Comments
 (0)