sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.56k stars 2.12k forks source link

Download link displays output in browser instead of downloading. #11023

Open eccles opened 1 year ago

eccles commented 1 year ago

Describe the bug

Adding a downlod role to download a notebook successfully create the download ling in the generated dosc. However clicking on the link simply displays the notebook in the browser instead of downloading the notebook file.

How to Reproduce

======== ls -l docs/notebooks total 64 -rw-rw-r-- 1 paul paul 326 Dec 9 17:46 index.rst -rw-rw-r-- 1 paul paul 199 Dec 9 17:52 Manage_Credentials_download.rst -rw-r--r-- 1 paul paul 6065 Dec 9 17:15 Manage_Credentials.ipynb

======= cat docs/notebooks/index.rst: .. _notebooksref:

Note Books

.. toctree:: :maxdepth: 2 :caption: Contents:

Manage_Credentials Manage_Credentials_download

====== cat docs/notebooks/Manage_Credentials_download.rst .. _managed_credentials_downloadref:

Manage_Credentials Download

.. only:: builder_html or readthedoc

See :download:Manage Credentials <Manage_Credentials.ipynb>.

Environment Information

sphinx-build --bug-report Please paste all output below into the bug report template text Platform: linux; (Linux-6.0.6-76060006-generic-x86_64-with-debian-11.5) Python version: 3.7.15 (default, Oct 26 2022, 04:14:11) [GCC 10.2.1 20210110]) Python implementation: CPython Sphinx version: 5.3.0 Docutils version: 0.17.1 Jinja2 version: 3.1.2

Sphinx extensions

No response

Additional context

No response

eccles commented 1 year ago

The output is displayed instead of downloaded.

Browser is Firefox 107.0 64 bit Linux

eccles commented 1 year ago

Further investigation shows that Firefox dynamically type the files as JSON which causes the browser to 'interpret' it. I have made a workaround by zipping the notebook and now the downloading works. Possibly this is the only solution - if so maybe this needs a documentation change to point out the caveats of different filetypes masquerading as (say) json. Official mimetype for notebook is application/ ipynb+json

jdillard commented 1 year ago

This seems like a webserver configuration issue, making sure the mime type and Content-Disposition headers are set as desired for the appropriate file extensions. Although, adding a note to the docs for the download role seems appropriate.