code: def _generate_redirects(app, exception):
      builder = app.builder
      if builder.name != "html" or exception:
          return
      for k, v in app.env.get_domain("redirect_from").redirects.items():
          p = Path(app.outdir, k + builder.out_suffix)
          html = HTML_TEMPLATE.format(v=builder.get_relative_uri(k, v))
          if p.is_file():
              if p.read_text() != html:
                  logger.warning(
                      "A redirect-from directive is trying to "
                      "create %s, but that file already exists "
                      '(perhaps you need to run "make clean")',
                      p,
                  )
          else:
              logger.info(
                  "making refresh html file: %s redirect to %s", k, v
              )
              p.parent.mkdir(parents=True, exist_ok=True)
              p.write_text(html, encoding="utf-8")
  
file_path: matplotlib/doc/sphinxext/redirect_from.py
imports: from pathlib import Path
  from docutils.parsers.rst import Directive
  from sphinx.domains import Domain
  from sphinx.util import logging
label_desc: Use image node_id 2 for calling a global function with example usage: _generate_redirects(app, exception) without return types