From f6e533f74cad701e436eaa1cc3fbff374f6a942c Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Wed, 30 Jun 2021 17:10:44 -0500 Subject: [PATCH 1/3] Default `hoverxref_api_host` to the proxied API --- docs/Makefile | 1 - docs/conf.py | 18 ++---------------- docs/configuration.rst | 4 ++-- docs/development.rst | 37 +++---------------------------------- hoverxref/extension.py | 4 ++-- 5 files changed, 9 insertions(+), 55 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index 8e5394ff..be0642e5 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -8,7 +8,6 @@ SOURCEDIR = . BUILDDIR = _build # sphinx-hoverxref expected variables -export READTHEDOCS=True export READTHEDOCS_PROJECT=sphinx-hoverxref export READTHEDOCS_VERSION=latest diff --git a/docs/conf.py b/docs/conf.py index 2228cd8a..0edb0a6f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a @@ -65,22 +63,10 @@ 'sphinx': 'tooltip', } -# Used when building the documentation from the terminal and using a local Read -# the Docs instance as backend -hoverxref_api_host = 'http://localhost:8000' - -if os.environ.get('READTHEDOCS') == 'True': - # Building on Read the Docs +# Used when building the documentation locally. +if os.environ.get('READTHEDOCS') != 'True': hoverxref_api_host = 'https://readthedocs.org' - if os.environ.get('PROXIED_API_ENDPOINT') == 'True': - # Use the proxied API endpoint - hoverxref_api_host = '/_' - -if os.environ.get('LOCAL_READTHEDOCS') == 'True': - # Building on a local Read the Docs instance - hoverxref_api_host = 'http://community.dev.readthedocs.io' - hoverxref_tooltip_maxwidth = 650 hoverxref_auto_ref = True hoverxref_roles = [ diff --git a/docs/configuration.rst b/docs/configuration.rst index 7aefa9a1..171326d0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -160,9 +160,9 @@ These settings are global and have effect on both, tooltips and modal dialogues. .. confval:: hoverxref_api_host - Description: Host URL for the API to retrieve the content of the floating window + Description: Host or root URL for the API to retrieve the content of the floating window - Default: ``https://readthedocs.org`` + Default: ``/_`` Type: string diff --git a/docs/development.rst b/docs/development.rst index a81d82fa..279a5812 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -56,45 +56,14 @@ Serve the documentation locally with this command: Now, you can hit http://localhost:9000/ and you should see your documentation here. - -Avoid CORS on local backend -+++++++++++++++++++++++++++ - -When building the documentation locally, -the API calls will be blocked by the browser because of :abbr:`CORS (Cross Origin Resource Sharing)` -(you are hitting the URL http://localhost:9000/ and the API calls are to https://readthedocs.org/). - -You can disable this while developing our extension. -To do this, you can open Google Chrome with these arguments: - -.. prompt:: bash - - google-chrome-stable --disable-web-security --user-data-dir='/tmp/testing' - -If Firefox, you can install this add-ons: `Allow CORS: Access-Control-Allow-Origin `_. - - Using a local Read the Docs instance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can `install Read the Docs locally following these instructions`_. -Although, it may be too complicated just to retrieve the same content that you could have in https://readthedocs.org. - -To make the extension to work, you will need to define this setting in your ``conf.py`` file: - -.. code-block:: python - - hoverxref_api_host = 'http://dev.readthedocs.io:8000' - -.. tip:: - - The value of this setting should be the same as ``PUBLIC_API_URL``. - -Once you have done that, you can just import the project directly in your local instance, -and the tooltips should work without problem. - -.. _install Read the Docs locally following these instructions: https://docs.readthedocs.io/en/stable/development/install.html +You don't need to change anything to be able to use your local instance, +the default :confval:`hoverxref_api_host` value should work. +.. _install Read the Docs locally following these instructions: https://docs.readthedocs.io/page/development/install.html Permanent tooltip to work with CSS ---------------------------------- diff --git a/hoverxref/extension.py b/hoverxref/extension.py index d3668424..7e8fb2fe 100644 --- a/hoverxref/extension.py +++ b/hoverxref/extension.py @@ -367,11 +367,11 @@ def setup(app): app.add_config_value('hoverxref_default_type', 'tooltip', 'env') app.add_config_value('hoverxref_intersphinx', [], 'env') app.add_config_value('hoverxref_intersphinx_types', {}, 'env') - app.add_config_value('hoverxref_api_host', 'https://readthedocs.org', 'env') + app.add_config_value('hoverxref_api_host', '/_', 'env') # Tooltipster settings # Deprecated in favor of ``hoverxref_api_host`` - app.add_config_value('hoverxref_tooltip_api_host', 'https://readthedocs.org', 'env') + app.add_config_value('hoverxref_tooltip_api_host', '/_', 'env') app.add_config_value('hoverxref_tooltip_theme', ['tooltipster-shadow', 'tooltipster-shadow-custom'], 'env') app.add_config_value('hoverxref_tooltip_interactive', True, 'env') app.add_config_value('hoverxref_tooltip_maxwidth', 450, 'env') From e11ba6ac06df1bf09e46cac71f6094f829bf5bc8 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Wed, 22 Mar 2023 13:41:58 -0500 Subject: [PATCH 2/3] Update --- docs/Makefile | 4 ---- docs/development.rst | 18 ------------------ 2 files changed, 22 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index be0642e5..0170576d 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -7,10 +7,6 @@ SPHINXBUILD = sphinx-build SOURCEDIR = . BUILDDIR = _build -# sphinx-hoverxref expected variables -export READTHEDOCS_PROJECT=sphinx-hoverxref -export READTHEDOCS_VERSION=latest - # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/development.rst b/docs/development.rst index 4e43ba8c..747613a3 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -54,24 +54,6 @@ Serve the documentation locally with this command: Now, you can hit http://localhost:9000/ and you should see your documentation here. - -Avoid CORS on local backend -+++++++++++++++++++++++++++ - -When building the documentation locally, -the API calls will be blocked by the browser because of :abbr:`CORS (Cross Origin Resource Sharing)` -(you are hitting the URL http://localhost:9000/ and the API calls are to https://readthedocs.org/). - -You can disable this while developing our extension. -To do this, you can open Google Chrome with these arguments: - -.. prompt:: bash - - google-chrome-stable --disable-web-security --user-data-dir='/tmp/testing' - -If Firefox, you can install this add-ons: `Allow CORS: Access-Control-Allow-Origin `_. - - Using a local Read the Docs instance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From eaa2944d4781e71fc1098a8ac39b5f76f4535b9b Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 28 Mar 2023 10:21:58 -0500 Subject: [PATCH 3/3] Fix tests --- tests/test_htmltag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_htmltag.py b/tests/test_htmltag.py index ebf38cd1..45c85abc 100644 --- a/tests/test_htmltag.py +++ b/tests/test_htmltag.py @@ -44,7 +44,7 @@ def test_js_render(app, status, warning): "animationDuration: 0", "contentAsHTML: true", "content: 'Loading...'", - "var url = 'https://readthedocs.org' + '/api/v3/embed/?' + $.param(params);", + "var url = '/_' + '/api/v3/embed/?' + $.param(params);", textwrap.indent( textwrap.dedent(""" var params = {{