From aa1a21aece29acd19f653c83e4ab686340195707 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 4 Jul 2020 17:25:45 -0500 Subject: [PATCH] Add OpenSearch support (/opensearch.xml). Add https://danbooru.donmai.us/opensearch.xml. This file tells browsers how to perform searches on Danbooru. In Chrome, this lets you type "danb" in the address bar to perform a search on Danbooru. In Firefox, you have to click the "..." icon next to the address bar, then choose "Add Search Engine". After that, you can search Danbooru from the address bar. Ref: * http://dev.chromium.org/tab-to-search * https://developer.mozilla.org/en-US/docs/Web/OpenSearch * https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md * https://en.wikipedia.org/wiki/OpenSearch --- app/controllers/static_controller.rb | 3 +++ app/views/layouts/default.html.erb | 1 + app/views/static/opensearch.xml.erb | 7 +++++++ config/routes.rb | 2 ++ test/functional/static_controller_test.rb | 7 +++++++ 5 files changed, 20 insertions(+) create mode 100644 app/views/static/opensearch.xml.erb 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