code: def main(app):
      logger.info("Starting thumbnail extractor.")
  
      working_dir = os.getcwd()
      os.chdir(app.builder.srcdir)
  
      file = [HEAD]
  
      for folder, title in folder_title_map.items():
          file.append(
              SECTION_TEMPLATE.format(
                  section_title=title,
                  section_id=folder,
                  underlines="-" * len(title),
              )
          )
          target_dir = os.path.join("..", "_thumbnails", folder)
          if not os.path.isdir(target_dir):
              os.mkdir(target_dir)
  
          if folder in external_nbs.keys():
              for descr in external_nbs[folder]:
                  file.append(
                      ITEM_TEMPLATE.format(
                          doc_name=descr["doc_name"],
                          image=descr["image"],
                          doc_reference=descr["doc_reference"],
                          link_type=descr["link_type"],
                      )
                  )
  
          nb_paths = glob(f"{folder}/*.ipynb")
          for nb_path in nb_paths:
              nbg = NotebookGenerator(nb_path, "..", folder)
              nbg.gen_previews()
              file.append(
                  ITEM_TEMPLATE.format(
                      doc_name=os.path.join(folder, nbg.stripped_name),
                      image=nbg.png_path,
                      doc_reference=os.path.join(
                          folder, nbg.stripped_name
                      ),
                      link_type="doc",
                  )
              )
  
      with open("gallery.rst", "w", encoding="utf-8") as f:
          f.write("\n".join(file))
  
      os.chdir(working_dir)
  
file_path: pymc-examples/sphinxext/thumbnail_extractor.py
imports: import base64
  import json
  import os
  import shutil
  from glob import glob
  import matplotlib
  import matplotlib.pyplot
  from matplotlib import image
  import sphinx
label_desc: Use image node_id 2 for calling a global function with example usage: main(app) without return types