Skip to content

Add notebook-gallery plugin to auto-generate gallery style cards on index pages#298

Open
jaladh-singhal wants to merge 4 commits intoCaltech-IPAC:mainfrom
jaladh-singhal:auto-gen-gallery
Open

Add notebook-gallery plugin to auto-generate gallery style cards on index pages#298
jaladh-singhal wants to merge 4 commits intoCaltech-IPAC:mainfrom
jaladh-singhal:auto-gen-gallery

Conversation

@jaladh-singhal
Copy link
Copy Markdown
Member

@jaladh-singhal jaladh-singhal commented Apr 15, 2026

Fixes #233

Added a custom local MyST plugin (notebook-gallery directive) that auto-generates a notebook gallery we have for the Euclid index page and used it for all other mission pages.

Design decisions:

@bsipocz you probably care about this more (since we had past conversations about this):

  • Implemented this as a MyST JS plugin (the .mjs file) rather than a Python script, as the MyST plugin system integrates JS plugins cleanly at build time and avoids a separate generation step for executable plugins. Also if we want more complexity we can easily migrate to widgets from JS route - right now we don't need it because we are not working with HTML DOM directly
  • Took inspiration from JB example-js-plugin
  • The plugin depends on the yaml npm package for parsing notebook_metadata.yml. So a build step is required and I had to add package.json (+package-lock.json) and a bundling step via esbuild in tox.ini (as opposed to a single self-contained .mjs file).
    • This has an added benefit: we can eventually move plugins/ to a separate irsa-myst-plugins repo and publish it as npm/GH package if we decide to reuse it across projects or to contribute upstream.

Things to check:

  • Test mission index pages: WISE, SPHEREx, Simulated Data, Techniques & Tools, Euclid
  • Title differences in the Euclid gallery cards at ops and this PR build
    • Can be fixed if we add short titles from toc.yml to notebook_metadata.yml (they should be reconciled)
    • If not, I can try modifying the plugin to override title for some notebooks but it will make code a bit more complex
  • Exception cases in euclid.md will be removed before merging

Add packaging to it since we need yaml npm package
Add tests for exception handling
@jaladh-singhal jaladh-singhal self-assigned this Apr 15, 2026
@jaladh-singhal jaladh-singhal added infrastructure Infrastructure related issues/PRs. html rendering / skip testing Rendering related issues/PRs. Skips tests in PRs. labels Apr 15, 2026
@jaladh-singhal
Copy link
Copy Markdown
Member Author

This is relevant for build step changes in tox: https://app.circleci.com/pipelines/github/Caltech-IPAC/irsa-tutorials/849/workflows/b6cd0cd5-fd7d-43d6-9d30-86bd8a2c1fc6/jobs/826?invite=true#step-103-10522_83

image

Also note L265: the plugin is loaded successfully (right now we just have 1 directive and that's what it tells us)

Copy link
Copy Markdown
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you so much.

I think 1) this should go in as first version before we jump into with new ideas for improvements (with the removal of the test sections of course -- those could maybe go into a new test md file in the plugin itself, or added as a test md file if/when the plugin will live in its separate repo)

Comment thread myst.yml
plugins:
# note: we need to use the built plugin bundle here so make sure to build it with
# `cd plugins && npm install && npm run build` after any changes to the plugins/src/
- plugins/dist/notebook-gallery.mjs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is OK for now, but ultimately we may want to ship the plugin separately from this repo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - and note the plural in "plugins", I envision it as a suite of plugins that we can maintain, ship and potentially share with MyST community.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am definitely thinking of multiple plugins, whether to ship them one per repo or multiple in a plugins one is a separate question :)

Comment thread tox.ini
buildhtml: bash -c "echo 'Notebooks ignored (not tested/executed) in this job:'; cat ignore_execute | sort | uniq"

# Build the MyST plugin bundle before building the site with jupyter-book
buildhtml: bash -c "cd plugins && npm install && npm run build"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK here, but we will need to make sure npm is available for tox? I suppose we can kind of rely on that it's available already for JB so we can just piggy-back?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seemed to work locally as well as on the CircleCI/GA runner had npm pre-installed (which is common for most of their runner images). I don't think we particularly piggybacked on JB because we install JB via pip as python package not as an npm package.

That being said, I didn't think this through and we should be aware of it if we run into npm missing issues. Another reason why plugins/ should be it's own repo and we don't maintain the build step here at irsa-tutorials.

Comment thread tox.ini

# Using srtict so we fail with trackbacks and debug mode to have a richer log
# For full build we disable parallel runs to easy server load
buildhtml: bash -c "jupyter-book build --execute --execute-parallel 1 --html --strict -d"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this goes in with the merge we will need to open a follow-up issue to ensure that eventually we turn back on the checks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will revert it before merging.

The first build failed (when strict was on) not because of plugin installation step but because of some notebook or something (I couldn't tell because the logs are way more verbose than my attention span). But yeah, I'm afraid it's becoming more common to remove strict for these kind of PR builds, maybe we should make it a label like skip testing GH label?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yes, we do use debug level logging to have more info available when there are issues.

Ideally no content executing testing was done with these changes as you haven't touched the notebooks themselves; so I suppose we should go back and check what was going on with that failure.

````
```{notebook-gallery} notebook_metadata.yml
tutorials/euclid/1_Euclid_intro_MER_images.md
tutorials/euclid/3_Euclid_intro_1D_spectra.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach very much; thanks Jaladh.

However; I already start seeing a list of options for improvements. What would work best, comment on the plugin itself or here argue for the usecase?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's upto you. If you wish to get this merged, then you can open an issue listing all improvements you see. Else you can comment here and I can iterate within the PR

@jaladh-singhal
Copy link
Copy Markdown
Member Author

those could maybe go into a new test md file in the plugin itself, or added as a test md file if/when the plugin will live in its separate repo)

@bsipocz Agreed. I plan to add a readme when it becomes more mature and independent. That readme will be a good place for these test cases.

@bsipocz
Copy link
Copy Markdown
Member

bsipocz commented Apr 15, 2026

OK, so features that comes to mind, but I don't think we should wait for any of them and just get this PR merged as is already:

  • being able to wildcard the list of notebooks for the gallery. I like the current explicit approach, but I think it would make sense to be able to also say tutorials/euclid/*md

  • alternatively to the wildcard, and this is very IRSA specific, we could also match on the field 'section'.

  • we could raise an error for the unrecognised notebooks when using --strict. I'm not sure how complicated this would be.

  • have the test cases moved into the plugin directory/future repository; as you suggested a README would suffice to start with as it could both serve as documentation and test

  • probably a separate plugin/widget idea; or maybe an add-on feature here: do add a filtering on top of the gallery view. This would definitely be a feature that would also be super useful for upstream.

Copy link
Copy Markdown
Contributor

@troyraen troyraen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

html rendering / skip testing Rendering related issues/PRs. Skips tests in PRs. infrastructure Infrastructure related issues/PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-generate gallery style cards on index pages

3 participants