diff --git a/docs/conf.py b/docs/conf.py index 92646c97f0d..f079e5601c9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,7 +44,7 @@ extensions = [ 'cpplexer', 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', - 'sphinx_sitemap' + 'openvino_custom_sphinx_sitemap' ] html_baseurl = 'https://docs.openvino.ai/canonical/' @@ -54,6 +54,19 @@ html_baseurl = 'https://docs.openvino.ai/canonical/' sitemap_url_scheme = "{link}" site_url = f'https://docs.openvino.ai/{version_name}/' +ov_sitemap_urlset = [ + ("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"), + ("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"), + ("xmlns:coveo", "https://www.coveo.com/en/company/about-us"), + ("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd") +] + +ov_sitemap_meta = [ + ('coveo:metadata', { + 'ovversion': version_name, + }) +] + # ---------------------------------------------------- diff --git a/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/PKG-INFO b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/PKG-INFO new file mode 100644 index 00000000000..32657500683 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/PKG-INFO @@ -0,0 +1,5 @@ +Metadata-Version: 2.1 +Name: openvino-custom-sphinx-sitemap +Version: 0.0.1 +Summary: Extends sphinx-sitemap plugin with additional sitemap metadata +Requires-Python: >=3.9 diff --git a/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/SOURCES.txt b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/SOURCES.txt new file mode 100644 index 00000000000..f5881c03646 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/SOURCES.txt @@ -0,0 +1,7 @@ +pyproject.toml +openvino_custom_sphinx_sitemap/__init__.py +openvino_custom_sphinx_sitemap.egg-info/PKG-INFO +openvino_custom_sphinx_sitemap.egg-info/SOURCES.txt +openvino_custom_sphinx_sitemap.egg-info/dependency_links.txt +openvino_custom_sphinx_sitemap.egg-info/requires.txt +openvino_custom_sphinx_sitemap.egg-info/top_level.txt \ No newline at end of file diff --git a/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/dependency_links.txt b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/dependency_links.txt new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/requires.txt b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/requires.txt new file mode 100644 index 00000000000..45b3c172056 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/requires.txt @@ -0,0 +1,2 @@ +sphinx>=4.5.0 +sphinx-sitemap>=2.2.0 diff --git a/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/top_level.txt b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/top_level.txt new file mode 100644 index 00000000000..7430f802687 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap.egg-info/top_level.txt @@ -0,0 +1 @@ +openvino_custom_sphinx_sitemap diff --git a/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap/__init__.py b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap/__init__.py new file mode 100644 index 00000000000..98119c02fe0 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/openvino_custom_sphinx_sitemap/__init__.py @@ -0,0 +1,99 @@ +import xml.etree.ElementTree as ET +from sphinx_sitemap import setup as base_setup, get_locales, hreflang_formatter + + +def setup(app): + app.add_config_value( + 'ov_sitemap_urlset', + default=None, + rebuild='' + ) + + app.add_config_value( + 'ov_sitemap_meta', + default=None, + rebuild='' + ) + + setup = base_setup(app) + for listener in app.events.listeners['build-finished']: + if listener.handler.__name__ == 'create_sitemap': + app.disconnect(listener.id) + + app.connect('build-finished', create_sitemap) + return setup + + +def create_sitemap(app, exception): + """Generates the sitemap.xml from the collected HTML page links""" + + urlset = app.builder.config.ov_sitemap_urlset + meta = app.builder.config.ov_sitemap_meta + + site_url = app.builder.config.site_url or app.builder.config.html_baseurl + site_url = site_url.rstrip('/') + '/' + if not site_url: + print("sphinx-sitemap error: neither html_baseurl nor site_url " + "are set in conf.py. Sitemap not built.") + return + if (not app.sitemap_links): + print("sphinx-sitemap warning: No pages generated for %s" % + app.config.sitemap_filename) + return + + ET.register_namespace('xhtml', "http://www.w3.org/1999/xhtml") + + root = ET.Element("urlset") + + if not urlset: + root.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9") + else: + for item in urlset: + root.set(*item) + + get_locales(app, exception) + + if app.builder.config.version: + version = app.builder.config.version + '/' + else: + version = "" + + for link in app.sitemap_links: + url = ET.SubElement(root, "url") + scheme = app.config.sitemap_url_scheme + if app.builder.config.language: + lang = app.builder.config.language + '/' + else: + lang = "" + + ET.SubElement(url, "loc").text = site_url + scheme.format( + lang=lang, version=version, link=link + ) + + if meta: + for entry in meta: + namespace, values = entry + namespace_element = ET.SubElement(url, namespace) + for tag_name, tag_value in values.items(): + ET.SubElement(namespace_element, tag_name).text = tag_value + + if len(app.locales) > 0: + for lang in app.locales: + lang = lang + '/' + linktag = ET.SubElement( + url, + "{http://www.w3.org/1999/xhtml}link" + ) + linktag.set("rel", "alternate") + linktag.set("hreflang", hreflang_formatter(lang.rstrip('/'))) + linktag.set("href", site_url + scheme.format( + lang=lang, version=version, link=link + )) + + filename = app.outdir + "/" + app.config.sitemap_filename + ET.ElementTree(root).write(filename, + xml_declaration=True, + encoding='utf-8', + method="xml") + print("%s was generated for URL %s in %s" % (app.config.sitemap_filename, + site_url, filename)) diff --git a/docs/openvino_custom_sphinx_sitemap/pyproject.toml b/docs/openvino_custom_sphinx_sitemap/pyproject.toml new file mode 100644 index 00000000000..49735100978 --- /dev/null +++ b/docs/openvino_custom_sphinx_sitemap/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "openvino_custom_sphinx_sitemap" +version = "0.0.1" +description = "Extends sphinx-sitemap plugin with additional sitemap metadata" +dependencies = [ + "sphinx >= 4.5.0", + "sphinx-sitemap >= 2.2.0" +] +requires-python = ">=3.9" diff --git a/docs/requirements.txt b/docs/requirements.txt index 10f970b6268..e90da3b38be 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -45,3 +45,4 @@ sphinxcontrib-serializinghtml==1.1.5 toml==0.10.2 urllib3==1.26.5 zipp==3.4.1 +docs/openvino_custom_sphinx_sitemap