summaryrefslogtreecommitdiffstats
path: root/debian/patches/support_old_search_indexes.diff
blob: 450e5e840fc7bc744f0cb0a7c55d8074ab0fa5e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From: Dmitry Shachnev <mitya57@debian.org>
Date: Sat, 11 Dec 2021 19:19:27 +0300
Subject: Make searchtools.js support documentation built with old Sphinx

Sphinx 4.3 has changed format of searchindex.js files, but in Debian
there are lots of packages built with older Sphinx, and we want to
keep them working for some time.

Also support legacy custom search.html templates, which don't have
data-content_root attribute on the top-level element.

Forwarded: not-needed
---
 sphinx/themes/basic/static/searchtools.js | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index 7918c3f..09d6458 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -62,7 +62,8 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
   const docFileSuffix = DOCUMENTATION_OPTIONS.FILE_SUFFIX;
   const docLinkSuffix = DOCUMENTATION_OPTIONS.LINK_SUFFIX;
   const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
-  const contentRoot = document.documentElement.dataset.content_root;
+  const contentRoot = document.documentElement.dataset.content_root
+    ?? DOCUMENTATION_OPTIONS.URL_ROOT;
 
   const [docName, title, anchor, descr, score, _filename] = item;
 
@@ -434,11 +435,14 @@ const Search = {
         filenames[match[0]],
       ]);
     };
-    Object.keys(objects).forEach((prefix) =>
+    Object.keys(objects).forEach((prefix) => {
+      if (!(objects[prefix] instanceof Array)) {
+        objects[prefix] = Object.entries(objects[prefix]).map(([name, match]) => [...match, name]);
+      }
       objects[prefix].forEach((array) =>
         objectSearchCallback(prefix, array)
-      )
-    );
+      );
+    });
     return results;
   },