From ca9a27eb6647701b783fb9d6c7b1366883a1cb65 Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Tue, 11 Mar 2025 13:57:18 +0100 Subject: [PATCH 1/2] opensearch: Add opensearch manifest OpenSearch is a standard that allows browsers to discover search engines. A special XML file with information about the search engine is linked from its webpage in a link tag. OpenSearch is supported by Firefox and (maybe) macOS Safari. It used to be supported by Chromium-based browsers, but that feature was deprecated. https://stackoverflow.com/questions/56400952/does-chrome-allow-auto-discovery-of-opensearch MDN Docs: https://developer.mozilla.org/en-US/docs/Web/XML/Guides/OpenSearch OpenSearch specification: https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md --- elixir/web.py | 23 +++++++++++++++++++++++ templates/layout.html | 1 + templates/search.xml | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 templates/search.xml diff --git a/elixir/web.py b/elixir/web.py index 1427136e..1649e60a 100755 --- a/elixir/web.py +++ b/elixir/web.py @@ -383,6 +383,27 @@ def on_get(self, req, resp, project: str, version: str, family: str = "", subcmd }) +class OpenSearchManifestResource: + def on_get(self, req, resp, project): + ctx = req.context + query = get_query(ctx.config.project_dir, project) + if not query: + resp.status = falcon.HTTP_NOT_FOUND + resp.content_type = falcon.MEDIA_TEXT + resp.text = f'invalid project name: {project}' + return + + template = ctx.jinja_env.get_template('search.xml') + + data = { + 'project_name': project, + } + + resp.status = falcon.HTTP_OK + resp.content_type = falcon.MEDIA_XML + resp.text = template.render(data) + + # File families available in the dropdown next to search input in the topbar TOPBAR_FAMILIES = { 'A': 'All symbols', @@ -830,6 +851,8 @@ def get_application(): app.add_route('/acp', AutocompleteResource()) app.add_route('/api/ident/{project:project}/{ident:ident}', ApiIdentGetterResource()) + app.add_route('/opensearch/{project:project}/search.xml', OpenSearchManifestResource()) + app.add_route('/{project}', IncompleteURLRedirectResource()) app.add_route('/{project}/{version}', IncompleteURLRedirectResource()) app.add_route('/{project}/{version}/', IncompleteURLRedirectResource()) diff --git a/templates/layout.html b/templates/layout.html index 8f9bcc34..d8df844a 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -16,6 +16,7 @@ {%- endblock %}"> + diff --git a/templates/search.xml b/templates/search.xml new file mode 100644 index 00000000..a1b8e60d --- /dev/null +++ b/templates/search.xml @@ -0,0 +1,11 @@ + + + Elixir ({{ project_name }}) + Elixir Cross Referencer - {{ project_name }} + UTF-8 + {{ project_name }} + https://elixir.bootlin.com/favicon.ico + + + + From e885aa7029adb3e899b11a30f47a04ade4c51643 Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Tue, 11 Mar 2025 14:01:47 +0100 Subject: [PATCH 2/2] opensearch: autocomplete: Add opensearch compatibility Add a parameter to autocomplete that enables opensearch-compatible response format. OpenSearch suggestions extension: https://github.com/dewitt/opensearch/blob/master/mediawiki/Specifications/OpenSearch/Extensions/Suggestions/1.1/Draft%201.wiki --- elixir/autocomplete.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/elixir/autocomplete.py b/elixir/autocomplete.py index 6ce34078..ba5adaee 100755 --- a/elixir/autocomplete.py +++ b/elixir/autocomplete.py @@ -33,6 +33,7 @@ def on_get(self, req, resp): ident_prefix = req.get_param('q') family = req.get_param('f') project = req.get_param('p') + opensearch_mode = req.get_param('opensearch') == 'true' ident_prefix = validate_ident(ident_prefix) if ident_prefix is None: @@ -83,7 +84,11 @@ def on_get(self, req, resp): resp.status = falcon.HTTP_200 resp.content_type = falcon.MEDIA_JSON - resp.media = response + + if not opensearch_mode: + resp.media = response + else: + resp.media = [ident_prefix, response] query.close()