diff --git a/app/components/spotlight/title_component.html.erb b/app/components/spotlight/title_component.html.erb new file mode 100644 index 000000000..956008dee --- /dev/null +++ b/app/components/spotlight/title_component.html.erb @@ -0,0 +1,6 @@ +
+
+ <%= title %> + <%= subtitle %> +
+
diff --git a/app/components/spotlight/title_component.rb b/app/components/spotlight/title_component.rb new file mode 100644 index 000000000..64f48299c --- /dev/null +++ b/app/components/spotlight/title_component.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Spotlight + # Draws the title in the masthead + class TitleComponent < ViewComponent::Base + def initialize(title:, subtitle:) + @title = title + @subtitle = subtitle + super + end + + def title + tag.h1 @title, class: 'site-title h2' + end + + def subtitle + return unless @subtitle + + tag.small(@subtitle, class: 'd-none d-md-block py-2 fs-4') + end + end +end diff --git a/app/views/shared/_masthead.html.erb b/app/views/shared/_masthead.html.erb index 35df0ba63..d3a4a0bd0 100644 --- a/app/views/shared/_masthead.html.erb +++ b/app/views/shared/_masthead.html.erb @@ -21,24 +21,7 @@ <% end %> <%= masthead_navbar if resource_masthead? %> - -
-
- <% if content_for? :masthead %> -

- <%= content_for :masthead %> -

- <% else %> -

- <%= masthead_heading_content %> -

- <% if masthead_subheading_content %> - <%= masthead_subheading_content %> - <% end %> - <% end %> -
-
- + <%= render Spotlight::Engine.config.spotlight.title_component.new(title: content_for(:masthead) || masthead_heading_content, subtitle: masthead_subheading_content) %> <%= masthead_navbar unless resource_masthead? %> diff --git a/lib/spotlight/engine.rb b/lib/spotlight/engine.rb index 8d11634f6..f4881a666 100644 --- a/lib/spotlight/engine.rb +++ b/lib/spotlight/engine.rb @@ -192,6 +192,7 @@ def self.blacklight_config ActiveSupport::Reloader.to_prepare do Spotlight::Engine.config.spotlight = OpenStruct.new Spotlight::Engine.config.spotlight.header_navigation_link_component = Spotlight::HeaderNavigationLinkComponent + Spotlight::Engine.config.spotlight.title_component = Spotlight::TitleComponent end end