hextra icon indicating copy to clipboard operation
hextra copied to clipboard

feat: shortcode for Jupyter Notebook

Open imfing opened this issue 1 year ago • 2 comments

Experimental shortcode to include jupyter notebook in a page. In the future, it will enable using a notebook file as an individual page.

Example usage:

---
title: Jupyter Notebook
math: true
---

{{< jupyter "Intro.ipynb" >}}

image

imfing avatar Mar 29 '24 22:03 imfing

Deploy Preview for hugo-hextra ready!

Name Link
Latest commit f8dd5fb16a23a2d921c0c05aaf5dbfcd462959d3
Latest deploy log https://app.netlify.com/sites/hugo-hextra/deploys/66e58f5482fa390008dae987
Deploy Preview https://deploy-preview-337--hugo-hextra.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Mar 29 '24 22:03 netlify[bot]

Very cool, thank you.

dogweather avatar Mar 30 '24 00:03 dogweather

Hi @imfing This is great! I just tested this branch for a use case and it worked perfectly. If I had any complaint, it'd be that I'd prefer host the notebooks in the same directory, like static, and I couldn't figure it out with page.Resources. But that's a minor thing.

Just wondering, is there any reason you don't want to merge this to main? I would start using it right away.

MattDodsonEnglish avatar Aug 25 '24 13:08 MattDodsonEnglish

. If I had any complaint,

Ah, one other: it seems the headings don't show in the ToC, having tried with both % and < tokens. I'm not sure how to fix that one yet, but I'll dig into the rendering logic and see if I can find a solution.

MattDodsonEnglish avatar Aug 26 '24 00:08 MattDodsonEnglish

@MattDodsonEnglish Thank you for the feedback.

I would start using it right away.

I think I will probably merge this as is once I resolve the conflicts.

Just wondering, is there any reason you don't want to merge this to main?

I didn't figure out a way to make Jupyter work nicely in Hugo so that we can essentially use jupyter notebooks instead of .md files. But this can be addressed separately.

If I had any complaint, it'd be that I'd prefer host the notebooks in the same directory,

This can be supported as what we can do for images: https://imfing.github.io/hextra/docs/guide/organize-files/#add-images

Ah, one other: it seems the headings don't show in the ToC

I'll try to address this, but I'm not sure if this is a easy thing.

imfing avatar Aug 26 '24 20:08 imfing

Ah, one other: it seems the headings don't show in the ToC

I'll try to address this, but I'm not sure if this is a easy thing.

From what I tried, I don't know how easy this is to do it elegantly. Using something like this with % works to make a ToC, but it causes a lot other issues, like requiring two lines two surround all markdown blocks, and things like embedded callout shortcodes fail.

      {{- if $toc -}}
        {{- $sourceContent -}}
      {{- else -}}
        {{- $sourceContent | $page.RenderString -}}
      {{- end -}}

MattDodsonEnglish avatar Aug 26 '24 21:08 MattDodsonEnglish

One more request: would it be possible to keep the copy button in the cells? It's a nice UX boost for readers who just want to grab a little sample from the wider notebook flow.

MattDodsonEnglish avatar Aug 30 '24 21:08 MattDodsonEnglish

@MattDodsonEnglish yes, see the latest demo page: https://deploy-preview-337--hugo-hextra.netlify.app/docs/guide/shortcodes/jupyter/

imfing avatar Sep 14 '24 13:09 imfing

@imfing preliminary test looks great, with ToC too. Thanks :bow:

MattDodsonEnglish avatar Sep 16 '24 20:09 MattDodsonEnglish

@MattDodsonEnglish let me know if things don't work as expected 🙌

imfing avatar Sep 16 '24 21:09 imfing