[gi-docgen/tintou/opensearch] generate: Add support for OpenSearch
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gi-docgen/tintou/opensearch] generate: Add support for OpenSearch
- Date: Fri, 5 Nov 2021 09:54:49 +0000 (UTC)
commit 7bd03b979062b5b0719c73f9f170697e8eb44213
Author: Corentin Noël <corentin noel collabora com>
Date: Thu Nov 4 12:21:35 2021 +0100
generate: Add support for OpenSearch
If the `docs_url` key is used and the search is enabled, an OpenSearch
file is created to allow better integration with the browsers.
docs/project-configuration.rst | 2 ++
gidocgen/config.py | 4 ++++
gidocgen/gdgenerate.py | 27 +++++++++++++++++++++++++++
gidocgen/templates/basic/base.html | 5 +++++
4 files changed, 38 insertions(+)
---
diff --git a/docs/project-configuration.rst b/docs/project-configuration.rst
index 9da5c84..728a8d4 100644
--- a/docs/project-configuration.rst
+++ b/docs/project-configuration.rst
@@ -62,6 +62,8 @@ The following keys are used, if found:
``search_index`` = ``b``
Whether gi-docgen should generate a search index file for the namespace.
+``docs_url`` = ``s``
+ The website that will provide this documentation.
The ``theme`` section
~~~~~~~~~~~~~~~~~~~~~
diff --git a/gidocgen/config.py b/gidocgen/config.py
index 3da1709..58fdec8 100644
--- a/gidocgen/config.py
+++ b/gidocgen/config.py
@@ -73,6 +73,10 @@ class GIDocConfig:
def website_url(self):
return self.library.get('website_url', '')
+ @property
+ def docs_url(self):
+ return self.library.get('docs_url', '')
+
@property
def browse_url(self):
return self.library.get('browse_url', '')
diff --git a/gidocgen/gdgenerate.py b/gidocgen/gdgenerate.py
index 325c11a..7098229 100644
--- a/gidocgen/gdgenerate.py
+++ b/gidocgen/gdgenerate.py
@@ -2661,6 +2661,28 @@ def gen_types_hierarchy(config, theme_config, output_dir, jinja_env, repository)
}
+def gen_opensearch(config, repository, namespace, symbols, content_files):
+ desc = etree.Element('OpenSearchDescription')
+ desc.set("xmlns", "http://a9.com/-/spec/opensearch/1.1/")
+ desc.set("xmlns:moz", "http://www.mozilla.org/2006/browser/search/")
+ sub = etree.SubElement(desc, 'ShortName')
+ sub.text = f"{namespace.name}"
+ sub = etree.SubElement(desc, 'Description')
+ sub.text = f"{namespace.name}-{namespace.version} Reference Manual"
+ sub = etree.SubElement(desc, 'InputEncoding')
+ sub.text = "UTF-8"
+ if config.logo_url:
+ sub = etree.SubElement(desc, 'Image')
+ sub.text = config.logo_url
+ sub = etree.SubElement(desc, 'Url', type="text/html")
+ sub.set("type", "text/html")
+ sub.set("template", f"{config.docs_url}/?q={{searchTerms}}")
+ sub = etree.SubElement(desc, 'moz:SearchForm')
+ sub.text = f"{config.docs_url}"
+
+ return etree.ElementTree(desc)
+
+
def gen_devhelp(config, repository, namespace, symbols, content_files):
book = etree.Element('book')
book.set("xmlns", "http://www.devhelp.net/book")
@@ -2945,6 +2967,11 @@ def gen_reference(config, options, repository, templates_dir, theme_config, cont
res.write(devhelp_file, encoding="UTF-8")
if config.search_index:
+ if config.docs_url:
+ opensearch_file = os.path.join(ns_dir, "opensearch.xml")
+ log.info(f"Creating OpenSearch file for {namespace.name}-{namespace.version}: {opensearch_file}")
+ res = gen_opensearch(config, repository, namespace, template_symbols, content_files)
+ res.write(opensearch_file, encoding="UTF-8")
gdgenindices.gen_indices(config, repository, content_dirs, ns_dir)
copy_files = []
diff --git a/gidocgen/templates/basic/base.html b/gidocgen/templates/basic/base.html
index 963a73e..36598ba 100644
--- a/gidocgen/templates/basic/base.html
+++ b/gidocgen/templates/basic/base.html
@@ -34,6 +34,11 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
{% if CONFIG.site_url %}
<link rel="canonical" href="{{ CONFIG.site_url }}"/>
{% endif %}
+ {% if CONFIG.search_index %}
+ {% if CONFIG.docs_url %}
+ <link rel="search" type="application/opensearchdescription+xml" title="{{ namespace.name }}"
href="opensearch.xml">
+ {% endif %}
+ {% endif %}
<link rel="stylesheet" href="style.css" type="text/css" />
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]