Skip to content

Commit 5df6680

Browse files
committed
Workaround for RTD search
For details, see readthedocs/readthedocs.org#1487 FIX #153
1 parent a80c680 commit 5df6680

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

docs/extra/extra.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Make the huge table always visible */
2+
table.features-cross-reference {
3+
overflow: visible !important;
4+
}
5+
.rst-content table.features-cross-reference.docutils th,
6+
.rst-content table.features-cross-reference.docutils td {
7+
background-color: white;
8+
}

docs/extra/extra.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var nodemcu = nodemcu || {};
2+
(function () {
3+
'use strict';
4+
5+
$(document).ready(function () {
6+
fixSearch();
7+
});
8+
9+
/*
10+
* RTD messes up MkDocs' search feature by tinkering with the search box defined in the theme, see
11+
* https://github.com/rtfd/readthedocs.org/issues/1088. This function sets up a DOM4 MutationObserver
12+
* to react to changes to the search form (triggered by RTD on doc ready). It then reverts everything
13+
* the RTD JS code modified.
14+
*/
15+
function fixSearch() {
16+
var target = document.getElementById('rtd-search-form');
17+
var config = {attributes: true, childList: true};
18+
19+
var observer = new MutationObserver(function (mutations) {
20+
// if it isn't disconnected it'll loop infinitely because the observed element is modified
21+
observer.disconnect();
22+
var form = $('#rtd-search-form');
23+
form.empty();
24+
form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html');
25+
$('<input>').attr({
26+
type: "text",
27+
name: "q",
28+
placeholder: "Search docs"
29+
}).appendTo(form);
30+
});
31+
32+
if (window.location.origin.indexOf('readthedocs') > -1) {
33+
observer.observe(target, config);
34+
}
35+
}
36+
37+
/**
38+
* Analyzes the URL of the current page to find out what the selected GitHub branch is. It's usually
39+
* part of the location path. The code needs to distinguish between running MkDocs standalone
40+
* and docs served from RTD. If no valid branch could be determined 'dev' returned.
41+
*
42+
* @returns GitHub branch name
43+
*/
44+
function determineSelectedBranch() {
45+
var branch = 'dev', path = window.location.pathname;
46+
if (window.location.origin.indexOf('readthedocs') > -1) {
47+
// path is like /en/<branch>/<lang>/build/ -> extract 'lang'
48+
// split[0] is an '' because the path starts with the separator
49+
var thirdPathSegment = path.split('/')[2];
50+
// 'latest' is an alias on RTD for the 'dev' branch - which is the default for 'branch' here
51+
if (thirdPathSegment !== 'latest') {
52+
branch = thirdPathSegment;
53+
}
54+
}
55+
return branch;
56+
}
57+
}());

docs/references/features-cross-reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- <span style="text-align: center; color: red;">✖</span> Not supported
66
- N/A Cannot be supported
77

8-
<table>
8+
<table class="features-cross-reference">
99
<tr>
1010
<th></th>
1111
<th colspan="7">Readers</th>

mkdocs.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
site_name: PhpSpreadsheet Documentation
2+
repo_url: https://github.com/PHPOffice/phpspreadsheet
3+
edit_uri: edit/develop/docs/
4+
5+
theme: readthedocs
6+
extra_css:
7+
- extra/extra.css
8+
9+
extra_javascript:
10+
- extra/extra.js
11+

0 commit comments

Comments
 (0)