Package: jupyterlab-hubshare
jupyterlab_hubshareshare notebooks on jupyterhubThis extension is composed of a Python package namedjupyterlab_hubsharefor the server extension and a NPM package namedjupyterlab_hubsharefor the frontend extension.SharingIn general, there will be multiple use case when using jupyterhub:RequirementsJupyterLab >= 3.0Installpipinstalljupyterlab_hubshareConfigurationThe extension supports multiple use cases:Use Case 1: All users on jupyterhub share the same InterfaceIn this scenario, the path for user A and user B are exactly the same, therefore we only need to configure the URLc.HubShare.file_path_template="{path}"This will make the sharable link looks likehttp://your.jupyter/user-redirect/?hubshare-preview=path/to/ipynbif you prefer directly access the file, you can also add:c.HubShare.use_preview = Falsethis will make the sharable link looks likehttp://your.jupyter/user-redirect/path/to/ipynbbut please be aware that this will allow other user directly modify the same file, which should be avoided in most cases.Use Case 2: User have their own work space but can still access others workspaceThis is honestly my preferable settings, for example:userA work space:path/workspaces/userA/userB work space:path/workspaces/userB/but both userA and userB have ashortcutfolder links topath/workspaces/so that they can still check others workspaces.In this case, you can configure that with:c.HubShare.file_path_template="shortcut/{user}/{path}"This will make the shareable link looks likehttp://your.jupyter/user-redirect/?hubshare-preview=shortcut/userA/path/to/ipynb(if sharing userA's notebook)Similarly, you can also setc.HubShare.use_preview=FalseThis will make the sharable link looks likehttp://your.jupyter/user-redirect/shortcut/userA/path/to/ipynbSame as above, be aware that this will allow the other user directly modify the same file!Use Case 3: User have their own work space, and they are unable to directly reach to others workspaceThis is much more like the previous scenario, but there's noshortcutfolder to give access to other folder.
In this case, you will need to also configure the contents_manager:c.HubShare.contents_manager={"manager_cls":FileContentManager,"kwargs":{"root_dir":"path/to/workspaces/}}c.HubShare.file_path_template="{user}/{path}"This will create a sharable link looks like:
This will make the shareable link looks likehttp://your.jupyter/user-redirect/?hubshare-preview=userA/path/to/ipynb(if sharing userA's notebook)Note that given that the current contents manager doesn't have access to other users workspaces, settinguse_preview=Falsewill make invalid link.Rewrite Shared File PathIn general, you can usefile_path_templateto provide a easy way to rewrite the shared file path. However, if you
want a more complicated rule for path rewrite. You can usefile_path_funcinstead.def get_share_path(path):
    return f"actual_folder/{path}" if path.startswith("folderA"/) else path

c.HubShare.file_path_func = get_share_pathYou shoud choose eitherfile_path_funcorfile_path_template. If both set, we will only usefile_path_funcand ignorefile_path_templateCopy link to external sitesStarting 0.3.0, you are now able to copy custom link to any external site. For example, copy the link to github, or some related url.
To do so, please add the following config:c.HubShare.other_link_functions={"github":{"label":"github URL","path_func":lambdapath:f"https://github.com/test/repo/{path}"},"view-only":{"label":"other URL","path_func":lambdapath:f"http://example.com/prefix/{path}"}}the dict key is just an identifiable ID so that we are able to find the correct path_func to update. You can use anythinglabelis the actul item visible on your context. It will be shown as "Copy {LABEL}".path_funcis a function that takespathas argument, and return the expected url to createTroubleshootIf you are seeing the frontend extension, but it is not working, check
that the server extension is enabled:jupyterserverextensionlistIf the server extension is installed and enabled, but you are not seeing
the frontend extension, check the frontend extension is installed:jupyterlabextensionlistContributingDevelopment installNote: You will need NodeJS to build the extension package.Thejlpmcommand is JupyterLab's pinned version ofyarnthat is installed with JupyterLab. You may useyarnornpmin lieu ofjlpmbelow.# Clone the repo to your local environment# Change directory to the jupyterlab_hubshare directory# Install package in development modepipinstall-e.# Link your development version of the extension with JupyterLabjupyterlabextensiondevelop.--overwrite# Rebuild extension Typescript source after making changesjlpmrunbuildYou can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.# Watch the source directory in one terminal, automatically rebuilding when neededjlpmrunwatch# Run JupyterLab in another terminaljupyterlabWith the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).By default, thejlpm run buildcommand generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:jupyterlabbuild--minimize=FalseThere's also a quick target in Makefile:makevenvbuild the workspacemakebuildbuild the packagemakewatchto quickly develop with jupyterlabmakejupyterhubto test the share function in jupyterhubUninstallpipuninstalljupyterlab_hubshare