programminghistorian / jekyll

Jekyll-based static site for The Programming Historian
http://programminghistorian.org
521 stars 229 forks source link

Investigating an issue with the embedded link Open with Colab badge on our organisationally-hosted `.ipynb` assets #3194

Closed anisa-hawes closed 4 months ago

anisa-hawes commented 8 months ago

I am opening this Issue to set out a puzzling issue relating to the embedded links within the Open with Colab badges on our organisationally-hosted .ipynb assets.

--

Context

In dialogue with the Managing Editors, we have agreed some guiding principles and workflows that enable us to manage codebooks as assets that are sustainable, translatable, and can be used flexibly by our readers.

We are hosting codebooks in our organisational Colab, which is part of our Google Workspace. At Phase 1 Submission, as part of the work done to process new lesson materials, the publishing team are uploading codebooks to Colab and utilising the facility to Save a Copy in GitHub that creates a copy of the file directly in ph-submissions:

  • File > Save a Copy in GitHub

  • Enter the following into the dialogue box:

  • Repository:
    programminghistorian/ph-submissions

  • Branch:
    gh-pages

  • File path:
    assets/lesson-slug/lesson-slug.ipynb

  • Commit message:
    Create lesson-slug.ipynb

  • Include a link to Colaboratory:
    [YES]

This Save a Copy action generates an active Open with Colab 'badge' in the upper left corner of the rendered file in ph-submissions. This means reviewers and editors can choose to click and use Colab to test run the code.

Problem

We cannot replicate this workflow in Jekyll, because we want our PR workflow to integrate our build checks and a colleague's review.

In a previous discussion #3001, we agreed a workflow for uploading codebooks to Jekyll which has been operating smoothly until now. This involves us manually uploading our .ipynb asset first (in a PR which precedes the publication) so that we can include a live nbviewer link in the published lesson.

However we've since noticed that when clicking on the Open with Colab badge in a codebook featured in a published lessons, we encounter a link error: /corpus-analysis-with-spacy.ipynb

What is happening is that the link embedded within the badge has automatically fixed to the temporary branch we used to publish the lesson (where we are referencing the codebook as an asset) (see 3053/files#diff):

Screenshot 2024-03-01 at 13 08 00

--

Trying to find a workable alternative

During some recent updates to the codebook associated with /en/lessons/clustering-visualizing-word-embeddings 3182/files we tested again. The only way I could fix the Issue was to bypass our established PR + colleague's review workflow, and use my Repo Owner credentials to make a direct commit to gh-pages when establishing the link with Save a Copy in GitHub: /clustering-visualizing-word-embeddings.ipynb.

This is (clearly) not a preferred practice, so I would like to ask for some help to find workable alternative.

A few notes/thoughts:

--

Hello @ZoeLeBlanc and @rivaquiroga,

Do you have any ideas how I could amend this workflow so that the 'badges' are operable after publication?

Thank you for your support to think this through.

A.

anisa-hawes commented 8 months ago

Noting here that I have made three further updates as direct commits:

anisa-hawes commented 4 months ago

Closing this investigation to confirm that when setting up codebooks, the Publishing Team can bypass Colab's Save a Copy in GitHub action and instead upload/create .ipynb files directly, then simply add the following cell to our file which creates the Open in Colab badge (which offers readers the option of opening codebooks in their local Google Drive):

In Jekyll:

{
     "cell_type": "markdown",
     "metadata": {
      "colab_type": "text",
      "id": "view-in-github"
     },
     "source": [
      "<a href=\"https://colab.research.google.com/github/programminghistorian/jekyll/blob/gh-pages/assets/lesson-slug/lesson-slug.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
     ]
    },

In ph-submissions:

{
     "cell_type": "markdown",
     "metadata": {
      "colab_type": "text",
      "id": "view-in-github"
     },
     "source": [
      "<a href=\"https://colab.research.google.com/github/programminghistorian/ph-submissions/blob/gh-pages/assets/lesson-slug/lesson-slug.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
     ]
    },

With thanks to @charlottejmc for collaborative puzzling + testing! ✨ and thanks also to @eliselavy for insights shared 👐🏼