@@ -39,7 +39,8 @@ def create_sitemap(app, exception):
39
39
urlset = app .builder .config .ov_sitemap_urlset
40
40
meta = app .builder .config .ov_sitemap_meta
41
41
42
- site_url = app .builder .config .site_url or app .builder .config .html_baseurl
42
+ site_url = app .builder .config .site_url
43
+
43
44
if site_url :
44
45
site_url .rstrip ("/" ) + "/"
45
46
else :
@@ -71,29 +72,28 @@ def create_sitemap(app, exception):
71
72
else :
72
73
version = ""
73
74
75
+ url = ET .SubElement (root , "url" )
76
+ scheme = app .config .sitemap_url_scheme
77
+ unique_links = set ()
74
78
while True :
75
79
try :
76
80
link = app .env .app .sitemap_links .get_nowait () # type: ignore
81
+ if link in unique_links :
82
+ continue
83
+ unique_links .add (link )
77
84
except queue .Empty :
78
85
break
79
86
80
- url = ET .SubElement (root , "url" )
81
- scheme = app .config .sitemap_url_scheme
82
87
if app .builder .config .language :
83
88
lang = app .builder .config .language + "/"
84
89
else :
85
90
lang = ""
86
-
91
+
87
92
ET .SubElement (url , "loc" ).text = site_url + scheme .format (
88
93
lang = lang , version = version , link = link
89
94
)
90
95
91
- if meta :
92
- for entry in meta :
93
- namespace , values = entry
94
- namespace_element = ET .SubElement (url , namespace )
95
- for tag_name , tag_value in values .items ():
96
- ET .SubElement (namespace_element , tag_name ).text = tag_value
96
+ process_coveo_meta (meta , url , link )
97
97
98
98
for lang in locales :
99
99
lang = lang + "/"
@@ -111,4 +111,23 @@ def create_sitemap(app, exception):
111
111
encoding = 'utf-8' ,
112
112
method = "xml" )
113
113
print ("%s was generated for URL %s in %s" % (app .config .sitemap_filename ,
114
- site_url , filename ))
114
+ site_url , filename ))
115
+
116
+ def process_coveo_meta (meta , url , link ):
117
+ if not meta :
118
+ return
119
+
120
+ for namespace , values in meta :
121
+ namespace_element = ET .SubElement (url , namespace )
122
+
123
+ for tag_name , tag_value in values .items ():
124
+ if tag_name == 'ovcategory' :
125
+ processed_link = process_link (link )
126
+ ET .SubElement (namespace_element , tag_name ).text = processed_link
127
+ else :
128
+ ET .SubElement (namespace_element , tag_name ).text = tag_value
129
+
130
+ def process_link (link ):
131
+ if '/' in link :
132
+ return link .split ('/' )[0 ]
133
+ return link .split ('.html' )[0 ]
0 commit comments