code: def expand_gallery(generator, metadata):
      
      if "gallery" not in metadata or metadata['gallery'] is None:
          return  # If no gallery specified, we do nothing
  
      lines = [ ]
      base_path = _image_path(generator)
      in_path = path.join(base_path, metadata['gallery'])
      template = generator.settings.get('GALLERY_TEMPLATE', DEFAULT_TEMPLATE)
      thumbnail_name = generator.settings.get("GALLERY_THUMBNAIL", DEFAULT_GALLERY_THUMB)
      thumbnail_prefix = generator.settings.get("")
      resizer = _resizer(thumbnail_name, '?x?', base_path)
      for dirpath, _, filenames in os.walk(in_path):
          for filename in filenames:
              if not filename.startswith('.'):
                  url = path.join(dirpath, filename).replace(base_path, "")[1:]
                  url = path.join('/static', generator.settings.get('IMAGE_PATH', DEFAULT_IMAGE_DIR), url).replace('\\', '/')
                  logger.debug("GALLERY: {0}".format(url))
                  thumbnail = resizer.get_thumbnail_name(filename)
                  thumbnail = path.join('/', generator.settings.get('THUMBNAIL_DIR', DEFAULT_THUMBNAIL_DIR), thumbnail).replace('\\', '/')
                  lines.append(template.format(
                      filename=filename,
                      url=url,
                      thumbnail=thumbnail,
                  ))
      metadata['gallery_content'] = "\n".join(lines)
docs: Expand a gallery tag to include all of the files in a specific directory under IMAGE_PATH
  
      :param pelican: The pelican instance
      :return: None