From 641f124c1564748d86e8fef9f0861161763d0c93 Mon Sep 17 00:00:00 2001 From: Marlo Longley Date: Fri, 25 Jul 2025 15:36:05 -0400 Subject: [PATCH] Use friendly library names in page title Fixes #5825 --- app/helpers/catalog_helper.rb | 10 ++++++++++ app/views/catalog/_search_results.html.erb | 2 +- spec/features/results_page_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb index f35196a8a..676d07ff7 100644 --- a/app/helpers/catalog_helper.rb +++ b/app/helpers/catalog_helper.rb @@ -10,6 +10,16 @@ def current_view document_index_view_type.to_s end + def format_constraints_page_title(search_state) + text = render_search_to_page_title(search_state) + return text unless text.present? && search_state.filter('library').present? + + library_code = search_state.filter('library').values.first + library_name = translate_library_code(library_code) + + text.sub(/Library:\s*.*/, "Library: #{library_name}") + end + # override upstream so we don't check the session for the last view type. def document_index_view_type(query_params = params || {}) view_param = query_params[:view] diff --git a/app/views/catalog/_search_results.html.erb b/app/views/catalog/_search_results.html.erb index eb3586d7d..62efe2246 100644 --- a/app/views/catalog/_search_results.html.erb +++ b/app/views/catalog/_search_results.html.erb @@ -8,7 +8,7 @@ <% @page_title = t 'blacklight.search.masthead_title', title: page_location.access_point.to_s.gsub(/_/, ' ').capitalize.pluralize, application_name: "#{I18n.t('blacklight.application_name')} catalog" %> <% end %> <% else %> - <% constraints_text = render_search_to_page_title(search_state) %> + <% constraints_text = format_constraints_page_title(search_state) %> <% if constraints_text.present? %> <% @page_title = t('blacklight.search.page_title.title', constraints: constraints_text, application_name: application_name) %> <% else %> diff --git a/spec/features/results_page_spec.rb b/spec/features/results_page_spec.rb index 2a9b0cba0..a99c7753a 100644 --- a/spec/features/results_page_spec.rb +++ b/spec/features/results_page_spec.rb @@ -46,6 +46,26 @@ end end + context 'with a library filter applied' do + before do + visit search_catalog_path f: { library: ['HILA'] } + end + + it 'uses the friendly library name rather than the code' do + expect(page).to have_title "SearchWorks catalog, Library: Hoover Institution Library & Archives" + end + end + + context 'with a library filter and search term applied' do + before do + visit search_catalog_path f: { library: ['HILA'] }, q: 'book' + end + + it 'uses the friendly library name rather than the code' do + expect(page).to have_title "SearchWorks catalog, book, Library: Hoover Institution Library & Archives" + end + end + context 'when clicking clear all' do it 'takes the user to a blank search' do visit search_catalog_path f: { access_facet: ['Online'] }, q: 'book'