Skip to content

Commit 46c4eaa

Browse files
committed
Show 6 cards per ecosystem section and show how many more are remaining
1 parent 163ddc9 commit 46c4eaa

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

app/components/page/card_section_component.html.erb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<% if @title %>
22
<h2 class="text-2xl font-bold mt-12 mb-6">
3-
<%= @title %>
3+
<% if @all_url %>
4+
<%= link_to @title, @all_url %>
5+
<% else %>
6+
<%= @title %>
7+
<% end %>
48
</h2>
59
<% end %>
610

@@ -12,6 +16,12 @@
1216

1317
<% if @all_url %>
1418
<%= link_to @all_url do %>
15-
View all <span class="tracking-normal text-white ml-1">-&gt;</span>
19+
View all
20+
21+
<% if @total && @total > @count %>
22+
(<%= @total - @count %> more)
23+
<% end %>
24+
25+
<span class="tracking-normal text-white ml-1">-&gt;</span>
1626
<% end %>
1727
<% end %>
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# frozen_string_literal: true
22

33
class Page::CardSectionComponent < ViewComponent::Base
4-
def initialize(resources:, title: nil, all_url: nil)
4+
def initialize(resources:, title: nil, all_url: nil, count: nil)
55
@title = title
6-
@resources = resources
6+
@count = count
77
@all_url = all_url
8+
9+
resources = Array.wrap(resources)
10+
11+
@resources = @count ? resources.take(@count) : resources
12+
@total = resources.count
813
end
914
end

app/content/pages/ecosystem.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ title: Ecosystem
66
<% page.with_title(title: current_page.data.fetch("title")) %>
77

88
<% EcosystemModel.all.sort_by(&:order).each do |page| %>
9+
<% subpages = site.resources.glob("#{page.page.request_path}/*.html.erb".delete_prefix("/")).sort_by { |site| site.data.fetch("title") } %>
10+
911
<%= render Page::CardSectionComponent.new(
1012
title: page.title,
11-
resources: site.resources.glob("#{page.page.request_path}/*.html.erb".delete_prefix("/")).sort_by { |site| site.data.fetch("title") }.take(3),
13+
resources: subpages,
14+
count: 6,
1215
all_url: page.request_path
1316
) %>
1417
<% end %>

0 commit comments

Comments
 (0)