Skip to content

Commit

Permalink
Show 6 cards per ecosystem section and show how many more are remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Oct 23, 2023
1 parent 163ddc9 commit 46c4eaa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 12 additions & 2 deletions app/components/page/card_section_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<% if @title %>
<h2 class="text-2xl font-bold mt-12 mb-6">
<%= @title %>
<% if @all_url %>
<%= link_to @title, @all_url %>
<% else %>
<%= @title %>
<% end %>
</h2>
<% end %>

Expand All @@ -12,6 +16,12 @@

<% if @all_url %>
<%= link_to @all_url do %>
View all <span class="tracking-normal text-white ml-1">-&gt;</span>
View all

<% if @total && @total > @count %>
(<%= @total - @count %> more)
<% end %>

<span class="tracking-normal text-white ml-1">-&gt;</span>
<% end %>
<% end %>
9 changes: 7 additions & 2 deletions app/components/page/card_section_component.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# frozen_string_literal: true

class Page::CardSectionComponent < ViewComponent::Base
def initialize(resources:, title: nil, all_url: nil)
def initialize(resources:, title: nil, all_url: nil, count: nil)
@title = title
@resources = resources
@count = count
@all_url = all_url

resources = Array.wrap(resources)

@resources = @count ? resources.take(@count) : resources
@total = resources.count
end
end
5 changes: 4 additions & 1 deletion app/content/pages/ecosystem.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ title: Ecosystem
<% page.with_title(title: current_page.data.fetch("title")) %>

<% EcosystemModel.all.sort_by(&:order).each do |page| %>
<% subpages = site.resources.glob("#{page.page.request_path}/*.html.erb".delete_prefix("/")).sort_by { |site| site.data.fetch("title") } %>

<%= render Page::CardSectionComponent.new(
title: page.title,
resources: site.resources.glob("#{page.page.request_path}/*.html.erb".delete_prefix("/")).sort_by { |site| site.data.fetch("title") }.take(3),
resources: subpages,
count: 6,
all_url: page.request_path
) %>
<% end %>
Expand Down

0 comments on commit 46c4eaa

Please sign in to comment.