Skip to content

Commit

Permalink
Implemented Algolia search (godotengine#4884)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
  • Loading branch information
leroy and Calinou authored Jun 13, 2021
1 parent 82ea79d commit 6ae96e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
6 changes: 6 additions & 0 deletions _static/css/algolia.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.wy-nav-side { overflow: visible; }
.wy-side-scroll { overflow: inherit; }

.algolia-autocomplete {
display: block !important;
}
22 changes: 22 additions & 0 deletions _static/js/algolia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

(function() {

var doc_version = document.querySelector('meta[name="doc_version"]').getAttribute('content');

// Initialize the Algolia search widget
docsearch({
apiKey: 'c39cb614363a2a156811478bc2d0573b',
indexName: 'godotengine',
inputSelector: '#rtd-search-form input[type=text]',
algoliaOptions: {
facetFilters: ["version:" + (doc_version || 'stable')]
},
});

window.addEventListener('keydown', function(event) {
if (event.key === '/') {
document.querySelector('#rtd-search-form input[type=text]').focus();
event.preventDefault();
}
})
})();
5 changes: 5 additions & 0 deletions _templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{% extends "!layout.html" -%}

{% block extrahead -%}
<meta name="doc_version" content="{{ version }}">
{% endblock -%}

{% block linktags -%}
<meta name="theme-color" content="#3d8fcc">
{% if godot_inject_language_links -%}
Expand Down
7 changes: 4 additions & 3 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
if not os.getenv("SPHINX_NO_GDSCRIPT"):
extensions.append("gdscript")

if not os.getenv("SPHINX_NO_SEARCH"):
extensions.append("sphinx_search.extension")

if not os.getenv("SPHINX_NO_DESCRIPTIONS"):
extensions.append("godot_descriptions")

Expand Down Expand Up @@ -189,11 +186,15 @@
# These paths are either relative to html_static_path
# or fully qualified paths (e.g. https://...)
html_css_files = [
'css/algolia.css',
'https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css',
"css/custom.css",
]

html_js_files = [
"js/custom.js",
('https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js', {'defer': 'defer'}),
('js/algolia.js', {'defer': 'defer'})
]

# Output file base name for HTML help builder
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ sphinx-notfound-page==0.7.1

# Adds Open Graph tags in the HTML `<head>` tag
sphinxext-opengraph==0.4.2

# Full-page search UI for RTD: https://readthedocs-sphinx-search.readthedocs.io
readthedocs-sphinx-search==0.1.0

0 comments on commit 6ae96e7

Please sign in to comment.