Skip to content

Commit

Permalink
Make it easy to test locally (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Aug 18, 2021
1 parent d857859 commit 526eb58
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
Empty file removed docs/_static/.keep
Empty file.
6 changes: 6 additions & 0 deletions docs/_static/rtd_dummy_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var READTHEDOCS_DATA = {
'project': 'readthedocs-sphinx-search',
'version': 'latest',
'language': 'en',
'proxied_api_host': 'https://readthedocs.org',
};
5 changes: 5 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
sys.path.insert(0, os.path.abspath('..'))
sys.path.append(os.path.abspath("./_ext"))

ON_RTD = os.environ.get('READTHEDOCS', False)


# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -96,6 +98,9 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

if not ON_RTD:
html_js_files = ['rtd_dummy_data.js']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
Expand Down
20 changes: 20 additions & 0 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ Generate minified JS and CSS files via ``Gulp``:
Run the test suite with ``tox``. More information about testing is
available at :doc:`Testing page <testing>`.

Local testing
-------------

You can test this extension from the docs folder:

.. prompt:: bash

cd docs
pip install sphinx-autobuild
pip install -r requirement.txt
sphinx-autobuild . _build/html

Go to http://127.0.0.1:8000 and start searching!

.. note::

The extension works when is hosted on Read the Docs,
but to make it work locally a custom ``READTHEDOCS_DATA`` js variable is injected automatically
to send the search requests to https://readthedocs.org/api/v2/search/.

Releasing
---------

Expand Down
2 changes: 1 addition & 1 deletion sphinx_search/static/js/rtd_sphinx_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ window.addEventListener("DOMContentLoaded", () => {
const project = READTHEDOCS_DATA.project;
const version = READTHEDOCS_DATA.version;
const language = READTHEDOCS_DATA.language || "en";
const api_host = '/_';
const api_host = READTHEDOCS_DATA.proxied_api_host || '/_';

let initialHtml = generateAndReturnInitialHtml();
document.body.appendChild(initialHtml);
Expand Down
Loading

0 comments on commit 526eb58

Please sign in to comment.