diff --git a/app/views/search/show.html.haml b/app/views/search/show.html.haml index 869890cdf3144ccc0eacaeba2ad44aaaa1ee7867..18eaccb46b27eead6b9276dec8bbecac35bdee28 100644 --- a/app/views/search/show.html.haml +++ b/app/views/search/show.html.haml @@ -2,6 +2,10 @@ - page_title @search_term - @hide_breadcrumbs = true +- if @search_results + - page_description(_("%{count} %{scope} for term '%{term}'") % { count: @search_results.formatted_count(@scope), scope: @scope, term: @search_term }) + - page_card_attributes("Namespace" => @group&.full_path, "Project" => @project&.full_path) + .page-title-holder.d-sm-flex.align-items-sm-center %h1.page-title< = _('Search') diff --git a/changelogs/unreleased/225213-unfurl-search-page.yml b/changelogs/unreleased/225213-unfurl-search-page.yml new file mode 100644 index 0000000000000000000000000000000000000000..0ff459879cc3cb3b5b3ef5bb838b32cb7b9d5e3c --- /dev/null +++ b/changelogs/unreleased/225213-unfurl-search-page.yml @@ -0,0 +1,5 @@ +--- +title: Improve unfurling support for /search +merge_request: 38699 +author: +type: other diff --git a/locale/gitlab.pot b/locale/gitlab.pot index f3ef4943d80a819c1c1916772250eb1471500b4f..576515c5b18cab0261f6b4ffdde43c3c93bb5a26 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -333,6 +333,9 @@ msgstr "" msgid "%{cores} cores" msgstr "" +msgid "%{count} %{scope} for term '%{term}'" +msgstr "" + msgid "%{count} LOC/commit" msgstr "" diff --git a/spec/views/search/show.html.haml_spec.rb b/spec/views/search/show.html.haml_spec.rb index 9ddfe08c8f3c0dee9cad603e4f49a0b1920588d5..eb763d424d38155fd5db1b0c10a7cfd8291da596 100644 --- a/spec/views/search/show.html.haml_spec.rb +++ b/spec/views/search/show.html.haml_spec.rb @@ -33,5 +33,37 @@ expect(rendered).to render_template('search/_category') expect(rendered).to render_template('search/_results') end + + context 'unfurling support' do + let(:group) { build(:group) } + let(:search_results) do + instance_double(Gitlab::GroupSearchResults).tap do |double| + allow(double).to receive(:formatted_count).and_return(0) + end + end + + before do + assign(:search_results, search_results) + assign(:scope, 'issues') + assign(:group, group) + end + + it 'renders meta tags for a group' do + render + + expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path) + end + + it 'renders meta tags for both group and project' do + project = build(:project, group: group) + assign(:project, project) + + render + + expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/) + expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path) + end + end end end