diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index fae4bf3b..dc683049 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -106,6 +106,24 @@ jobs: run: | echo "current jupyter-notebook: ${{ matrix.notebook }}" + - name: Add nb-myst download badge + run: | + notebook=${{ matrix.notebook }} + notebook_name=$(basename $notebook) + download_badge_md="[![Download notebook](https://img.shields.io/badge/Download-notebook-blue?logo=jupyter)](path:$notebook_name)" + python_command="import nbformat as nbf\n\ + nb = nbf.read(open('$notebook'), as_version=4)\n\ + # if the 1st cell is md and has colab text => add space after\n\ + if nb['cells'][0]['cell_type'] == 'markdown' and 'colab' in nb['cells'][0]['source'].lower():\n\ + nb['cells'][0]['source'] += ' '\n\ + # if there is no md cell with colab => create empty md cell on top\n\ + else:\n\ + nb['cells'].insert(0, nbf.v4.new_markdown_cell())\n\ + nb['cells'][0]['source'] += '$download_badge_md'\n\ + nbf.write(nb, open('$notebook', 'w'))" + + python -c "exec (\"$python_command\")" + - name: Run notebook uses: fzimmermann89/run-notebook@v3 env: