binderhub icon indicating copy to clipboard operation
binderhub copied to clipboard

Add template_file config and document page customization

Open rgaiacs opened this issue 10 months ago • 9 comments

Closes https://github.com/jupyterhub/binderhub/issues/1907

We might want to make add a new traitlets for users to provide their own Jinja template that will be used in https://github.com/jupyterhub/binderhub/blob/4f0a91ac7a851238d0857e68691edf2ab70c4b3d/binderhub/main.py#L42 from https://github.com/jupyterhub/binderhub/blob/4f0a91ac7a851238d0857e68691edf2ab70c4b3d/binderhub/main.py#L41-L46

rgaiacs avatar Jan 30 '25 13:01 rgaiacs

I will address the comments in a couple of weeks.

rgaiacs avatar Feb 05 '25 20:02 rgaiacs

Sorry for the delay to return to this.

I address the comments.

Do I need to add some tests? If yes, can I have some help? Thanks!

rgaiacs avatar Mar 28 '25 16:03 rgaiacs

@rgaiacs thanks for this PR!

How complicated would it be to customize components like HowItWorks.jsx, and have the template page use the built dist to control what gets rendered inside <div id="root"></div>?

For example, I can easily add header/footer

image

but I cannot figure out a way to "replace" the binder logo with this design.

Also, I think extra_static_path no longer takes effect, or at least I could not figure out how to link assets I used to mount at /etc/binderhub/custom/static.

agahkarakuzu avatar Apr 28 '25 06:04 agahkarakuzu

Hi @agahkarakuzu,

the challenge to customise any file in binderhub/static/js is due to how the JavaScript works.

We are using webpack to merge all JavaScript files into a single bundle.js file that is we reference in the HTML that we send to the user, see https://github.com/jupyterhub/binderhub/blob/837169dfebf9640c4d3b4f4247240b15fe2278a0/binderhub/templates/page.html#L27

How complicated would it be to customize components like HowItWorks.jsx

If you want to change any of the JavaScript files, for example HowItWorks.jsx, you will have to

  1. re-run webpack to create a new bundle.js.
  2. create a new volume that overwrite the default bundle.js with the one that you created.

rgaiacs avatar Apr 28 '25 06:04 rgaiacs

Thanks @rgaiacs ! I actually created a new bundle.js. Would simply mounting the new distribution override the existing one?

agahkarakuzu avatar Apr 28 '25 06:04 agahkarakuzu

Would simply mounting the new distribution override the existing one?

It should.

rgaiacs avatar Apr 28 '25 06:04 rgaiacs

It did! https://binder.evidencepub.io

  - name: custom-templates
    mountPath: /usr/local/lib/python3.13/site-packages/binderhub/static/
    subPath: static

The mountPath is a bit dependent on the python version, but I was able to build the sources from modified content and have that content rendered.

Build sources are from https://github.com/evidencepub/binder-template/tree/preview. I'll add a github action to this repository to better streamline the builds.

agahkarakuzu avatar Apr 28 '25 17:04 agahkarakuzu

One of the tests are with

FAILED binderhub/tests/test_registry.py::test_get_image_manifest[False] - OSError: [Errno 98] Address already in use

I believe the failure not related with this pull request.

@yuvipanda and @minrk this is blocking https://github.com/jupyterhub/mybinder.org-deploy/pull/3186 and I would like to merge this earlier next week.

rgaiacs avatar Sep 09 '25 12:09 rgaiacs

Do we need the new template_file property? Can't we already override the template using template_path?

https://github.com/jupyterhub/binderhub/blob/43ecb3a8677ad4a5e0a0a70e1a0ab240f67d52dd/binderhub/app.py#L791-L798

manics avatar Sep 15 '25 19:09 manics