diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb
index 8dff5678f..1dcc272be 100644
--- a/app/controllers/static_controller.rb
+++ b/app/controllers/static_controller.rb
@@ -13,6 +13,9 @@ class StaticController < ApplicationController
redirect_to wiki_page_path("help:dtext") unless request.format.js?
end
+ def opensearch
+ end
+
def site_map
end
diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb
index 6dcb21581..b8c7abe63 100644
--- a/app/views/layouts/default.html.erb
+++ b/app/views/layouts/default.html.erb
@@ -6,6 +6,7 @@
<%= render "meta_links", collection: @current_item %>
<%= tag.link rel: "canonical", href: canonical_url %>
+ <%= tag.link rel: "search", type: "application/opensearchdescription+xml", href: opensearch_url(format: :xml, version: 1), title: "Search posts" %>
<%= csrf_meta_tag %>
<% unless CurrentUser.enable_desktop_mode? %>
diff --git a/app/views/static/opensearch.xml.erb b/app/views/static/opensearch.xml.erb
new file mode 100644
index 000000000..3c67241f8
--- /dev/null
+++ b/app/views/static/opensearch.xml.erb
@@ -0,0 +1,7 @@
+
+
+ <%= Danbooru.config.app_name %>
+ <%= Danbooru.config.app_name %> search
+ <%= root_url %>favicon.ico
+
+
diff --git a/config/routes.rb b/config/routes.rb
index 9b8ff2e6e..afe0e3d3a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -69,6 +69,7 @@ Rails.application.routes.draw do
get :search
end
end
+ resources :autocomplete, only: [:index]
resources :bans
resources :bulk_update_requests do
member do
@@ -365,6 +366,7 @@ Rails.application.routes.draw do
get "/wiki/history/:title" => redirect("/wiki_page_versions?title=%{title}")
get "/sitemap" => "static#sitemap"
+ get "/opensearch" => "static#opensearch", :as => "opensearch"
get "/static/keyboard_shortcuts" => "static#keyboard_shortcuts", :as => "keyboard_shortcuts"
get "/static/bookmarklet" => "static#bookmarklet", :as => "bookmarklet"
get "/static/site_map" => "static#site_map", :as => "site_map"
diff --git a/test/functional/static_controller_test.rb b/test/functional/static_controller_test.rb
index ee8dca354..3ae5e5662 100644
--- a/test/functional/static_controller_test.rb
+++ b/test/functional/static_controller_test.rb
@@ -63,4 +63,11 @@ class StaticControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
end
+
+ context "opensearch action" do
+ should "work" do
+ get opensearch_path, as: :xml
+ assert_response :success
+ end
+ end
end