Skip to content

A platform for community discussion. Free, open, simple.

UX: Replace Google search with Discourse search on not found page

Misaka 0x4e21d4fd19d49a68
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 79371c9423a..e3f2c36a7f2 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -700,7 +700,7 @@ class ApplicationController < ActionController::Base
@slug = params[:slug].class == String ? params[:slug] : ''
@slug = (params[:id].class == String ? params[:id] : '') if @slug.blank?
@slug.tr!('-', ' ')
- @hide_google = true if SiteSetting.login_required
+ @hide_search = true if SiteSetting.login_required
render_to_string status: status, layout: layout, formats: [:html], template: '/exceptions/not_found'
end
diff --git a/app/controllers/exceptions_controller.rb b/app/controllers/exceptions_controller.rb
index 540add85c49..4c951e84b68 100644
--- a/app/controllers/exceptions_controller.rb
+++ b/app/controllers/exceptions_controller.rb
@@ -1,6 +1,6 @@
class ExceptionsController < ApplicationController
skip_before_action :check_xhr, :preload_json
- before_action :hide_google
+ before_action :hide_search
def not_found
# centralize all rendering of 404 into app controller
@@ -14,8 +14,8 @@ class ExceptionsController < ApplicationController
private
- def hide_google
- @hide_google = true if SiteSetting.login_required
+ def hide_search
+ @hide_search = true if SiteSetting.login_required
end
end
diff --git a/app/views/exceptions/not_found.html.erb b/app/views/exceptions/not_found.html.erb
index e06acfd0900..7949a1b5ab3 100644
--- a/app/views/exceptions/not_found.html.erb
+++ b/app/views/exceptions/not_found.html.erb
@@ -25,15 +25,14 @@
</div>
<% end %>
-<%- unless @hide_google %>
+<%- unless @hide_search%>
<div class="row">
<div class="page-not-found-search">
<h2><%= t 'page_not_found.search_title' %></h2>
<p>
- <form action='//google.com/search' id='google-search'>
+ <form action='/search' id='discourse-search'>
<input type="text" name="q" value="<%= @slug %>">
- <input type='hidden' name="as_sitesearch" value="<%= Discourse.base_url %>">
- <button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
+ <button class="btn btn-primary"><%= t 'page_not_found.search_button' %></button>
</form>
</p>
</div>
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 84d70adf625..08dcde4994c 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -3165,7 +3165,7 @@ en:
recent_topics: "Recent"
see_more: "More"
search_title: "Search this site"
- search_google: "Google"
+ search_button: "Search"
offline:
title: "Cannot load app"
diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb
index 957607236d5..dfb32ef47b4 100644
--- a/spec/requests/application_controller_spec.rb
+++ b/spec/requests/application_controller_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe ApplicationController do
it 'should return 404 and show Google search' do
get "/t/nope-nope/99999999"
expect(response.status).to eq(404)
- expect(response.body).to include(I18n.t('page_not_found.search_google'))
+ expect(response.body).to include(I18n.t('page_not_found.search_button'))
end
it 'should not include Google search if login_required is enabled' do