Repository: sphinx-gallery/sphinx-gallery

Issue:
Broken plot links if sphinx uses `htmldir`
If I build our documentation with the sphinx builder option `htmldir` the links to the in-site plots are broken. The thumbnails are working.

I already discussed this issue on [read the docs](https://github.com/readthedocs/readthedocs.org/issues/8982) because I thought the problems is there. But they figured out that this might be a flaw with sphinx-gallery.




Discussion:

Patch:
diff --git a/doc/getting_started.rst b/doc/getting_started.rst
index bceb311..a596a9e 100644
--- a/doc/getting_started.rst
+++ b/doc/getting_started.rst
@@ -24,6 +24,14 @@ A `template repository <https://github.com/sphinx-gallery/sample-project>`_,
 with sample example galleries and basic configurations is also available to
 help you get started.
 
+.. note::
+   Working `sphinx 
+   builders <https://www.sphinx-doc.org/en/master/man/sphinx-build.html#options>`_ 
+   for sphinx_gallery include `html` and `latex`. Support for other builders
+   is not guaranteed (e.g., `dirhtml` is known to be broken and will cause
+   broken image links.).
+
+
 .. _set_up_your_project:
 
 Overview your project files and folders
diff --git a/sphinx_gallery/gen_gallery.py b/sphinx_gallery/gen_gallery.py
index aff560f..53a768d 100644
--- a/sphinx_gallery/gen_gallery.py
+++ b/sphinx_gallery/gen_gallery.py
@@ -422,6 +422,14 @@ def generate_gallery_rst(app):
     Start the Sphinx-Gallery configuration and recursively scan the examples
     directories in order to populate the examples gallery
     """
+    blocked_builder = ['dirhtml']
+    if app.builder.name in blocked_builder:
+        msg = (
+            f'Builder is set to {repr(app.builder.name)}. sphinx_gallery does '
+            f'not work for any of the following: {[blocked_builder]}'
+        )
+        raise ConfigError(msg)
+
     logger.info('generating gallery...', color='white')
     gallery_conf = parse_config(app)
 


Test patch:
diff --git a/sphinx_gallery/tests/test_gen_gallery.py b/sphinx_gallery/tests/test_gen_gallery.py
index 75e061c..d199657 100644
--- a/sphinx_gallery/tests/test_gen_gallery.py
+++ b/sphinx_gallery/tests/test_gen_gallery.py
@@ -27,6 +27,13 @@ def test_bad_config():
         _complete_gallery_conf(sphinx_gallery_conf, '', True, False)
 
 
+def test_bad_builder(sphinx_app_wrapper):
+    """Test that we raise an error for a bad builder."""
+    sphinx_app_wrapper.buildername = 'dirhtml'
+    with pytest.raises(ConfigError, match=".*dirhtml.*sphinx_gallery does not work.*"):  # noqa: E501
+        sphinx_app_wrapper.create_sphinx_app()
+
+
 def test_default_config(sphinx_app_wrapper):
     """Test the default Sphinx-Gallery configuration is loaded