code: def gen_binder_url(fpath, binder_conf, gallery_conf):
      
      # Build the URL
      fpath_prefix = binder_conf.get('filepath_prefix')
      link_base = binder_conf.get('notebooks_dir')
  
      # We want to keep the relative path to sub-folders
      relative_link = os.path.relpath(fpath, gallery_conf['src_dir'])
      path_link = os.path.join(
          link_base, replace_py_ipynb(relative_link))
  
      # In case our website is hosted in a sub-folder
      if fpath_prefix is not None:
          path_link = '/'.join([fpath_prefix.strip('/'), path_link])
  
      # Make sure we have the right slashes (in case we're on Windows)
      path_link = path_link.replace(os.path.sep, '/')
  
      # Create the URL
      binder_url = binder_conf['binderhub_url']
      binder_url = '/'.join([binder_conf['binderhub_url'],
                             'v2', 'gh',
                             binder_conf['org'],
                             binder_conf['repo'],
                             binder_conf['branch']])
  
      if binder_conf.get('use_jupyter_lab', False) is True:
          binder_url += '?urlpath=lab/tree/{}'.format(path_link)
      else:
          binder_url += '?filepath={}'.format(path_link)
      return binder_url
docs: Generate a Binder URL according to the configuration in conf.py.
  
      Parameters
      ----------
      fpath: str
          The path to the `.py` file for which a Binder badge will be generated.
      binder_conf: dict or None
          The Binder configuration dictionary. See `gen_binder_rst` for details.
  
      Returns
      -------
      binder_url : str
          A URL that can be used to direct the user to the live Binder
          environment.