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<tab>" 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
This commit is contained in:
evazion
2020-07-04 17:25:45 -05:00
parent b6b0218e1d
commit aa1a21aece
5 changed files with 20 additions and 0 deletions

View File

@@ -13,6 +13,9 @@ class StaticController < ApplicationController
redirect_to wiki_page_path("help:dtext") unless request.format.js? redirect_to wiki_page_path("help:dtext") unless request.format.js?
end end
def opensearch
end
def site_map def site_map
end end

View File

@@ -6,6 +6,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<%= render "meta_links", collection: @current_item %> <%= render "meta_links", collection: @current_item %>
<%= tag.link rel: "canonical", href: canonical_url %> <%= 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 %> <%= csrf_meta_tag %>
<% unless CurrentUser.enable_desktop_mode? %> <% unless CurrentUser.enable_desktop_mode? %>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName><%= Danbooru.config.app_name %></ShortName>
<Description><%= Danbooru.config.app_name %> search</Description>
<Image height="16" width="16" type="image/x-icon"><%= root_url %>favicon.ico</Image>
<Url type="text/html" template="<%= posts_url %>?tags={searchTerms}&amp;utm_source=opensearch"/>
</OpenSearchDescription>

View File

@@ -69,6 +69,7 @@ Rails.application.routes.draw do
get :search get :search
end end
end end
resources :autocomplete, only: [:index]
resources :bans resources :bans
resources :bulk_update_requests do resources :bulk_update_requests do
member do member do
@@ -365,6 +366,7 @@ Rails.application.routes.draw do
get "/wiki/history/:title" => redirect("/wiki_page_versions?title=%{title}") get "/wiki/history/:title" => redirect("/wiki_page_versions?title=%{title}")
get "/sitemap" => "static#sitemap" get "/sitemap" => "static#sitemap"
get "/opensearch" => "static#opensearch", :as => "opensearch"
get "/static/keyboard_shortcuts" => "static#keyboard_shortcuts", :as => "keyboard_shortcuts" get "/static/keyboard_shortcuts" => "static#keyboard_shortcuts", :as => "keyboard_shortcuts"
get "/static/bookmarklet" => "static#bookmarklet", :as => "bookmarklet" get "/static/bookmarklet" => "static#bookmarklet", :as => "bookmarklet"
get "/static/site_map" => "static#site_map", :as => "site_map" get "/static/site_map" => "static#site_map", :as => "site_map"

View File

@@ -63,4 +63,11 @@ class StaticControllerTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
end end
end end
context "opensearch action" do
should "work" do
get opensearch_path, as: :xml
assert_response :success
end
end
end end