Adds opensearch xml file

This commit is contained in:
Mouse Reeve 2021-09-10 16:47:59 -07:00
parent c1b50001e9
commit 7c3cf095f3
4 changed files with 22 additions and 1 deletions

View file

@ -10,6 +10,8 @@
<link rel="stylesheet" href="{% static "css/vendor/icons.css" %}"> <link rel="stylesheet" href="{% static "css/vendor/icons.css" %}">
<link rel="stylesheet" href="{% static "css/bookwyrm.css" %}"> <link rel="stylesheet" href="{% static "css/bookwyrm.css" %}">
<link rel="search" type="application/opensearchdescription+xml" href="{% url 'opensearch' %}" title="{% blocktrans with site_name=site.name %}{{ site_name }} search{% endblocktrans %}" />
<link rel="shortcut icon" type="image/x-icon" href="{% if site.favicon %}{% get_media_prefix %}{{ site.favicon }}{% else %}{% static "images/favicon.ico" %}{% endif %}"> <link rel="shortcut icon" type="image/x-icon" href="{% if site.favicon %}{% get_media_prefix %}{{ site.favicon }}{% else %}{% static "images/favicon.ico" %}{% endif %}">
{% if preview_images_enabled is True %} {% if preview_images_enabled is True %}
@ -34,7 +36,7 @@
<a class="navbar-item" href="/"> <a class="navbar-item" href="/">
<img class="image logo" src="{% if site.logo_small %}{% get_media_prefix %}{{ site.logo_small }}{% else %}{% static "images/logo-small.png" %}{% endif %}" alt="Home page"> <img class="image logo" src="{% if site.logo_small %}{% get_media_prefix %}{{ site.logo_small }}{% else %}{% static "images/logo-small.png" %}{% endif %}" alt="Home page">
</a> </a>
<form class="navbar-item column" action="/search/"> <form class="navbar-item column" action="{% url 'search' %}">
<div class="field has-addons"> <div class="field has-addons">
<div class="control"> <div class="control">
<input aria-label="{% trans 'Search for a book or user' %}" id="search_input" class="input" type="text" name="q" placeholder="{% trans 'Search for a book or user' %}" value="{{ query }}"> <input aria-label="{% trans 'Search for a book or user' %}" id="search_input" class="input" type="text" name="q" placeholder="{% trans 'Search for a book or user' %}" value="{{ query }}">

View file

@ -0,0 +1,13 @@
{% load i18n %}
{% load static %}
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>BW</ShortName>
<Description>{% blocktrans with site_name=site.name %}{{ site_name }} search{% endblocktrans %}</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">{% if site.favicon %}{% get_media_prefix %}{{ site.favicon }}{% else %}{% static "images/favicon.ico" %}{% endif %}</Image>
<Url type="text/html" template="{% url 'search' %}">
<Param name="q" value="{searchTerms}"/>
</Url>
<moz:SearchForm>{% url 'search' %}</moz:SearchForm>
</OpenSearchDescription>

View file

@ -41,6 +41,7 @@ urlpatterns = [
re_path(r"^nodeinfo/2\.0/?$", views.nodeinfo), re_path(r"^nodeinfo/2\.0/?$", views.nodeinfo),
re_path(r"^api/v1/instance/?$", views.instance_info), re_path(r"^api/v1/instance/?$", views.instance_info),
re_path(r"^api/v1/instance/peers/?$", views.peers), re_path(r"^api/v1/instance/peers/?$", views.peers),
re_path(r"^opensearch.xml$", views.opensearch, name="opensearch"),
# polling updates # polling updates
re_path("^api/updates/notifications/?$", views.get_notification_count), re_path("^api/updates/notifications/?$", views.get_notification_count),
re_path("^api/updates/stream/(?P<stream>[a-z]+)/?$", views.get_unread_status_count), re_path("^api/updates/stream/(?P<stream>[a-z]+)/?$", views.get_unread_status_count),

View file

@ -128,3 +128,8 @@ def peers(_):
def host_meta(request): def host_meta(request):
"""meta of the host""" """meta of the host"""
return TemplateResponse(request, "host_meta.xml", {"DOMAIN": DOMAIN}) return TemplateResponse(request, "host_meta.xml", {"DOMAIN": DOMAIN})
@require_GET
def opensearch(request):
"""Open Search xml spec"""
return TemplateResponse(request, "opensearch.xml")