mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
UX: Replace Google search with Discourse search on not found page
* UX: Replace Google search with Discourse search on not found page. * FIX: Update application_controller_spec.rb.
This commit is contained in:
@ -700,7 +700,7 @@ class ApplicationController < ActionController::Base
|
|||||||
@slug = params[:slug].class == String ? params[:slug] : ''
|
@slug = params[:slug].class == String ? params[:slug] : ''
|
||||||
@slug = (params[:id].class == String ? params[:id] : '') if @slug.blank?
|
@slug = (params[:id].class == String ? params[:id] : '') if @slug.blank?
|
||||||
@slug.tr!('-', ' ')
|
@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'
|
render_to_string status: status, layout: layout, formats: [:html], template: '/exceptions/not_found'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class ExceptionsController < ApplicationController
|
class ExceptionsController < ApplicationController
|
||||||
skip_before_action :check_xhr, :preload_json
|
skip_before_action :check_xhr, :preload_json
|
||||||
before_action :hide_google
|
before_action :hide_search
|
||||||
|
|
||||||
def not_found
|
def not_found
|
||||||
# centralize all rendering of 404 into app controller
|
# centralize all rendering of 404 into app controller
|
||||||
@ -14,8 +14,8 @@ class ExceptionsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def hide_google
|
def hide_search
|
||||||
@hide_google = true if SiteSetting.login_required
|
@hide_search = true if SiteSetting.login_required
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -25,15 +25,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%- unless @hide_google %>
|
<%- unless @hide_search%>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="page-not-found-search">
|
<div class="page-not-found-search">
|
||||||
<h2><%= t 'page_not_found.search_title' %></h2>
|
<h2><%= t 'page_not_found.search_title' %></h2>
|
||||||
<p>
|
<p>
|
||||||
<form action='//google.com/search' id='google-search'>
|
<form action='/search' id='discourse-search'>
|
||||||
<input type="text" name="q" value="<%= @slug %>">
|
<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_button' %></button>
|
||||||
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
|
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3165,7 +3165,7 @@ en:
|
|||||||
recent_topics: "Recent"
|
recent_topics: "Recent"
|
||||||
see_more: "More"
|
see_more: "More"
|
||||||
search_title: "Search this site"
|
search_title: "Search this site"
|
||||||
search_google: "Google"
|
search_button: "Search"
|
||||||
|
|
||||||
offline:
|
offline:
|
||||||
title: "Cannot load app"
|
title: "Cannot load app"
|
||||||
|
@ -68,7 +68,7 @@ RSpec.describe ApplicationController do
|
|||||||
it 'should return 404 and show Google search' do
|
it 'should return 404 and show Google search' do
|
||||||
get "/t/nope-nope/99999999"
|
get "/t/nope-nope/99999999"
|
||||||
expect(response.status).to eq(404)
|
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
|
end
|
||||||
|
|
||||||
it 'should not include Google search if login_required is enabled' do
|
it 'should not include Google search if login_required is enabled' do
|
||||||
|
Reference in New Issue
Block a user