Skip to content
This repository was archived by the owner on Dec 4, 2019. It is now read-only.

Commit db41f00

Browse files
author
benhyland
committed
Work around broken search integration
MkDocs and Readthedocs don't currently agree on how to do search. This means that search has poor UX on the publically deployed docs on readthedocs.io. Here's a workaround suggested in github comments that we could use to fix things for us while we wait for the two projects to reconcile. See: readthedocs/readthedocs.org#2289 readthedocs/readthedocs.org#1088
1 parent 3087b86 commit db41f00

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/js/fix_search.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// See various broken search issues, but especially:
2+
// https://github.com/rtfd/readthedocs.org/pull/2289
3+
// https://github.com/rtfd/readthedocs.org/issues/1088
4+
5+
function fixSearch() {
6+
var target = document.getElementById('rtd-search-form');
7+
var config = {attributes: true, childList: true};
8+
9+
var observer = new MutationObserver(function(mutations) {
10+
observer.disconnect();
11+
var form = $('#rtd-search-form');
12+
form.empty();
13+
form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html');
14+
$('<input>').attr({
15+
type: "text",
16+
name: "q",
17+
placeholder: "Search docs"
18+
}).appendTo(form);
19+
});
20+
if (window.location.origin.indexOf('readthedocs') > -1) {
21+
observer.observe(target, config);
22+
}
23+
}
24+
25+
$(document).ready(function () {
26+
fixSearch();
27+
})

0 commit comments

Comments
 (0)