Skip to content

Commit

Permalink
Docs Add Category to Coveo search engine (#26932)
Browse files Browse the repository at this point in the history
### Details:
 - *item1*
 - *...*

### Tickets:
 - *ticket-id*
  • Loading branch information
akopytko authored Oct 7, 2024
1 parent 0aa76e7 commit fc97aaa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def create_sitemap(app, exception):
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 = app.builder.config.site_url

if site_url:
site_url.rstrip("/") + "/"
else:
Expand Down Expand Up @@ -71,29 +72,28 @@ def create_sitemap(app, exception):
else:
version = ""

url = ET.SubElement(root, "url")
scheme = app.config.sitemap_url_scheme
unique_links = set()
while True:
try:
link = app.env.app.sitemap_links.get_nowait() # type: ignore
if link in unique_links:
continue
unique_links.add(link)
except queue.Empty:
break

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
process_coveo_meta(meta, url, link)

for lang in locales:
lang = lang + "/"
Expand All @@ -111,4 +111,23 @@ def create_sitemap(app, exception):
encoding='utf-8',
method="xml")
print("%s was generated for URL %s in %s" % (app.config.sitemap_filename,
site_url, filename))
site_url, filename))

def process_coveo_meta(meta, url, link):
if not meta:
return

for namespace, values in meta:
namespace_element = ET.SubElement(url, namespace)

for tag_name, tag_value in values.items():
if tag_name == 'ovcategory':
processed_link = process_link(link)
ET.SubElement(namespace_element, tag_name).text = processed_link
else:
ET.SubElement(namespace_element, tag_name).text = tag_value

def process_link(link):
if '/' in link:
return link.split('/')[0]
return link.split('.html')[0]
4 changes: 2 additions & 2 deletions docs/sphinx_setup/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'.md': 'markdown',
}

html_baseurl = 'https://docs.openvino.ai/canonical/'
# html_baseurl = 'https://docs.openvino.ai/canonical/'

# -- Sitemap configuration ---------------------------------------------------

Expand All @@ -72,10 +72,10 @@
ov_sitemap_meta = [
('coveo:metadata', {
'ovversion': version_name,
'ovcategory': 'null'
})
]


# ----------------------------------------------------

html_favicon = '_static/favicon.ico'
Expand Down

0 comments on commit fc97aaa

Please sign in to comment.