From e6789d5e242f0fe66df7407972077017ea239b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Ara=C3=BAjo?= Date: Mon, 13 Mar 2023 21:56:44 -0300 Subject: [PATCH 1/9] Added support for jupyter notebooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: George Araújo --- Dockerfile | 12 ++++--- Gemfile | 1 + _config.yml | 1 + _posts/2023-03-13-jupyter-notebook.md | 14 ++++++++ assets/jupyter/blog.ipynb | 48 +++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 _posts/2023-03-13-jupyter-notebook.md create mode 100755 assets/jupyter/blog.ipynb diff --git a/Dockerfile b/Dockerfile index a1eb21a9f908..776b907464d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,18 +6,20 @@ RUN apt-get -y install locales # Set the locale RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \ locale-gen -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 # add ruby and jekyll -RUN apt-get install --no-install-recommends ruby-full build-essential zlib1g-dev -y -RUN apt-get install imagemagick -y +RUN apt-get install --no-install-recommends ruby-full build-essential zlib1g-dev python3-pip -y +RUN apt-get install imagemagick -y RUN apt-get clean \ && rm -rf /var/lib/apt/lists/ # ENV GEM_HOME='root/gems' \ # PATH="root/gems/bin:${PATH}" RUN gem install jekyll bundler +RUN pip3 install --upgrade jupyter +RUN pip3 cache purge RUN mkdir /srv/jekyll ADD Gemfile /srv/jekyll WORKDIR /srv/jekyll diff --git a/Gemfile b/Gemfile index b0cf11d34238..98d4bea4a34d 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ group :jekyll_plugins do gem 'jekyll-email-protect' gem 'jekyll-feed' gem 'jekyll-imagemagick' + gem 'jekyll-jupyter-notebook' gem 'jekyll-link-attributes' gem 'jekyll-minifier' gem 'jekyll-paginate-v2' diff --git a/_config.yml b/_config.yml index 63ae0d1a263c..3aa9c1aa3efc 100644 --- a/_config.yml +++ b/_config.yml @@ -209,6 +209,7 @@ plugins: - jekyll-email-protect - jekyll-feed - jekyll-imagemagick + - jekyll-jupyter-notebook - jekyll-minifier - jekyll-paginate-v2 - jekyll/scholar diff --git a/_posts/2023-03-13-jupyter-notebook.md b/_posts/2023-03-13-jupyter-notebook.md new file mode 100644 index 000000000000..81362dbc1a3a --- /dev/null +++ b/_posts/2023-03-13-jupyter-notebook.md @@ -0,0 +1,14 @@ +--- +layout: post +title: a post with jupyter notebook +date: 2023-03-13 08:57:00-0400 +description: an example of a blog post with jupyter notebook +categories: sample-posts jupyter-notebook +giscus_comments: true +related_posts: false +--- + +{::nomarkdown} +{% assign jupyter_path = "/assets/jupyter/blog.ipynb" | relative_url %} +{% jupyter_notebook jupyter_path %} +{:/nomarkdown} diff --git a/assets/jupyter/blog.ipynb b/assets/jupyter/blog.ipynb new file mode 100755 index 000000000000..bc870dcd161e --- /dev/null +++ b/assets/jupyter/blog.ipynb @@ -0,0 +1,48 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "sys.version_info(major=3, minor=6, micro=2, releaselevel='final', serial=0)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import sys\n", + "sys.version_info" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 9698abf511c2b414d28bf80ba6417a782a92737e Mon Sep 17 00:00:00 2001 From: George Araujo Date: Fri, 23 Jun 2023 12:27:32 -0300 Subject: [PATCH 2/9] Fixed error when jupyter notebook file is not found Signed-off-by: George Araujo --- _plugins/file-exists.rb | 23 +++++++++++++++++++++++ _posts/2023-03-13-jupyter-notebook.md | 7 ++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 _plugins/file-exists.rb diff --git a/_plugins/file-exists.rb b/_plugins/file-exists.rb new file mode 100644 index 000000000000..30480caa4f2c --- /dev/null +++ b/_plugins/file-exists.rb @@ -0,0 +1,23 @@ +module Jekyll + class FileExistsTag < Liquid::Tag + + def initialize(tag_name, path, tokens) + super + @path = path + end + + def render(context) + # Pipe parameter through Liquid to make additional replacements possible + url = Liquid::Template.parse(@path).render context + + # Adds the site source, so that it also works with a custom one + site_source = context.registers[:site].config['source'] + file_path = site_source + '/' + url + + # Check if file exists (returns true or false) + "#{File.exist?(file_path.strip!)}" + end + end +end + +Liquid::Template.register_tag('file_exists', Jekyll::FileExistsTag) \ No newline at end of file diff --git a/_posts/2023-03-13-jupyter-notebook.md b/_posts/2023-03-13-jupyter-notebook.md index 81362dbc1a3a..97e0c314bbfd 100644 --- a/_posts/2023-03-13-jupyter-notebook.md +++ b/_posts/2023-03-13-jupyter-notebook.md @@ -10,5 +10,10 @@ related_posts: false {::nomarkdown} {% assign jupyter_path = "/assets/jupyter/blog.ipynb" | relative_url %} -{% jupyter_notebook jupyter_path %} +{% capture notebook_exists %}{% file_exists /assets/jupyter/blog.ipynb %}{% endcapture %} +{% if notebook_exists == "true" %} + {% jupyter_notebook jupyter_path %} +{% else %} +

Sorry, the notebook you are looking for does not exist.

+{% endif %} {:/nomarkdown} From ace901574ed91b198e51a80ef8bb9f13348ecf6f Mon Sep 17 00:00:00 2001 From: George Araujo Date: Sun, 25 Jun 2023 17:56:44 -0300 Subject: [PATCH 3/9] Added python3 installation to Dockerfile Signed-off-by: George Araujo --- Dockerfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 776b907464d1..6edddd735833 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM bitnami/minideb:latest Label MAINTAINER Amir Pourmand RUN apt-get update -y + # add locale RUN apt-get -y install locales # Set the locale @@ -13,13 +14,21 @@ ENV LC_ALL en_US.UTF-8 # add ruby and jekyll RUN apt-get install --no-install-recommends ruby-full build-essential zlib1g-dev python3-pip -y RUN apt-get install imagemagick -y + +# install jupyter +RUN apt-get install python3-pip -y +RUN pip3 install --upgrade jupyter + +# clean everything RUN apt-get clean \ && rm -rf /var/lib/apt/lists/ +RUN pip3 cache purge + # ENV GEM_HOME='root/gems' \ # PATH="root/gems/bin:${PATH}" + +# install jekyll and dependencies RUN gem install jekyll bundler -RUN pip3 install --upgrade jupyter -RUN pip3 cache purge RUN mkdir /srv/jekyll ADD Gemfile /srv/jekyll WORKDIR /srv/jekyll From 62d9d3684556489f90abf04ef98069578878fe84 Mon Sep 17 00:00:00 2001 From: George Araujo Date: Sun, 25 Jun 2023 18:08:56 -0300 Subject: [PATCH 4/9] Moved python installation to its own section Signed-off-by: George Araujo --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6edddd735833..ea7431e83149 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,10 +12,10 @@ ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 # add ruby and jekyll -RUN apt-get install --no-install-recommends ruby-full build-essential zlib1g-dev python3-pip -y +RUN apt-get install --no-install-recommends ruby-full build-essential zlib1g-dev -y RUN apt-get install imagemagick -y -# install jupyter +# install python3 and jupyter RUN apt-get install python3-pip -y RUN pip3 install --upgrade jupyter From bc0a3b9ead2cb3919bc9739dd4d13b8da8c25228 Mon Sep 17 00:00:00 2001 From: George Araujo Date: Sun, 25 Jun 2023 18:15:31 -0300 Subject: [PATCH 5/9] Removed leading / from jupyter notebook path Signed-off-by: George Araujo --- _posts/2023-03-13-jupyter-notebook.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_posts/2023-03-13-jupyter-notebook.md b/_posts/2023-03-13-jupyter-notebook.md index 97e0c314bbfd..e98676532de4 100644 --- a/_posts/2023-03-13-jupyter-notebook.md +++ b/_posts/2023-03-13-jupyter-notebook.md @@ -9,8 +9,8 @@ related_posts: false --- {::nomarkdown} -{% assign jupyter_path = "/assets/jupyter/blog.ipynb" | relative_url %} -{% capture notebook_exists %}{% file_exists /assets/jupyter/blog.ipynb %}{% endcapture %} +{% assign jupyter_path = "assets/jupyter/blog.ipynb" | relative_url %} +{% capture notebook_exists %}{% file_exists assets/jupyter/blog.ipynb %}{% endcapture %} {% if notebook_exists == "true" %} {% jupyter_notebook jupyter_path %} {% else %} From a3c6fe53aae536e0f2e8cb3929cee2bf7f4fbea4 Mon Sep 17 00:00:00 2001 From: Amir Pourmand Date: Mon, 3 Jul 2023 17:11:57 +0330 Subject: [PATCH 6/9] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea7431e83149..c335f3a5bfb3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN apt-get install imagemagick -y # install python3 and jupyter RUN apt-get install python3-pip -y -RUN pip3 install --upgrade jupyter +RUN python3 -m pip install jupyter --break-system-packages # clean everything RUN apt-get clean \ @@ -32,4 +32,4 @@ RUN gem install jekyll bundler RUN mkdir /srv/jekyll ADD Gemfile /srv/jekyll WORKDIR /srv/jekyll -RUN bundle install \ No newline at end of file +RUN bundle install From 7e50922f2cb7bbfba0bc22b28e2fc5d580633595 Mon Sep 17 00:00:00 2001 From: George Araujo Date: Tue, 4 Jul 2023 12:16:08 -0300 Subject: [PATCH 7/9] Added step to install jupyter on github action Signed-off-by: George Araujo --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7174c87a9332..298d73326b2d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,6 +16,7 @@ permissions: jobs: deploy: + # available images: https://github.com/actions/runner-images#available-images runs-on: ubuntu-latest steps: - name: Checkout 🛎️ @@ -27,6 +28,7 @@ jobs: bundler-cache: true - name: Install and Build 🔧 run: | + pip3 install --upgrade jupyter npm install -g mermaid.cli export JEKYLL_ENV=production bundle exec jekyll build From 8d1261fdb99104f372d0509333c90a8b77d74a12 Mon Sep 17 00:00:00 2001 From: George Araujo Date: Tue, 4 Jul 2023 12:49:06 -0300 Subject: [PATCH 8/9] Updated jupyter notebook blog post Signed-off-by: George Araujo --- _posts/2023-03-13-jupyter-notebook.md | 19 ------------- _posts/2023-07-04-jupyter-notebook.md | 41 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 19 deletions(-) delete mode 100644 _posts/2023-03-13-jupyter-notebook.md create mode 100644 _posts/2023-07-04-jupyter-notebook.md diff --git a/_posts/2023-03-13-jupyter-notebook.md b/_posts/2023-03-13-jupyter-notebook.md deleted file mode 100644 index e98676532de4..000000000000 --- a/_posts/2023-03-13-jupyter-notebook.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -layout: post -title: a post with jupyter notebook -date: 2023-03-13 08:57:00-0400 -description: an example of a blog post with jupyter notebook -categories: sample-posts jupyter-notebook -giscus_comments: true -related_posts: false ---- - -{::nomarkdown} -{% assign jupyter_path = "assets/jupyter/blog.ipynb" | relative_url %} -{% capture notebook_exists %}{% file_exists assets/jupyter/blog.ipynb %}{% endcapture %} -{% if notebook_exists == "true" %} - {% jupyter_notebook jupyter_path %} -{% else %} -

Sorry, the notebook you are looking for does not exist.

-{% endif %} -{:/nomarkdown} diff --git a/_posts/2023-07-04-jupyter-notebook.md b/_posts/2023-07-04-jupyter-notebook.md new file mode 100644 index 000000000000..8437908deeb6 --- /dev/null +++ b/_posts/2023-07-04-jupyter-notebook.md @@ -0,0 +1,41 @@ +--- +layout: post +title: a post with jupyter notebook +date: 2023-07-04 08:57:00-0400 +description: an example of a blog post with jupyter notebook +categories: sample-posts jupyter-notebook +giscus_comments: true +related_posts: false +--- + +To include a jupyter notebook in a post, you can use the following code: + +{% raw %} + +```html +{::nomarkdown} +{% assign jupyter_path = "assets/jupyter/blog.ipynb" | relative_url %} +{% capture notebook_exists %}{% file_exists assets/jupyter/blog.ipynb %}{% endcapture %} +{% if notebook_exists == "true" %} + {% jupyter_notebook jupyter_path %} +{% else %} +

Sorry, the notebook you are looking for does not exist.

+{% endif %} +{:/nomarkdown} +``` + +{% endraw %} + +Let's break it down: this is possible thanks to [Jekyll Jupyter Notebook plugin](https://github.com/red-data-tools/jekyll-jupyter-notebook) that allows you to embed jupyter notebooks in your posts. It basically calls [`jupyter nbconvert --to html`](https://nbconvert.readthedocs.io/en/latest/usage.html#convert-html) to convert the notebook to an html page and then includes it in the post. Since [Kramdown](https://jekyllrb.com/docs/configuration/markdown/) is the default Markdown renderer for Jekyll, we need to surround the call to the plugin with the [::nomarkdown](https://kramdown.gettalong.org/syntax.html#extensions) tag so that it stops processing this part with Kramdown and outputs the content as-is. + +The plugin takes as input the path to the notebook, but it assumes the file exists. If you want to check if the file exists before calling the plugin, you can use the `file_exists` filter. This avoids getting a 404 error from the plugin and ending up displaying the main page inside of it instead. If the file does not exist, you can output a message to the user. The code displayed above outputs the following: + +{::nomarkdown} +{% assign jupyter_path = "assets/jupyter/blog.ipynb" | relative_url %} +{% capture notebook_exists %}{% file_exists assets/jupyter/blog.ipynb %}{% endcapture %} +{% if notebook_exists == "true" %} + {% jupyter_notebook jupyter_path %} +{% else %} +

Sorry, the notebook you are looking for does not exist.

+{% endif %} +{:/nomarkdown} From 3d256d43ecf72209522002b2dfd9d5356658245f Mon Sep 17 00:00:00 2001 From: George Araujo Date: Tue, 4 Jul 2023 12:49:14 -0300 Subject: [PATCH 9/9] Fixed spacing in code blog post Signed-off-by: George Araujo --- _posts/2015-07-15-code.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2015-07-15-code.md b/_posts/2015-07-15-code.md index a86fa077c536..9431265cf211 100644 --- a/_posts/2015-07-15-code.md +++ b/_posts/2015-07-15-code.md @@ -41,7 +41,7 @@ By default, it does not display line numbers. If you want to display line number If you want to display line numbers for a specific code block, all you have to do is wrap your code in a liquid tag: -{% raw %} +{% raw %} {% highlight c++ linenos %}
code code code
{% endhighlight %} {% endraw %}