Skip to content

Commit

Permalink
Added support for rendering iPython notebooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarlinSchaefer committed Dec 29, 2021
1 parent e1e00d3 commit 637de57
Show file tree
Hide file tree
Showing 25 changed files with 465 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ _site/
assets/fonts
posts_backup/
.jekyll-cache/
.ipynb_checkpoints

!assets/fonts/fontawesome/*
12 changes: 12 additions & 0 deletions _includes/main_head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<meta charset="utf-8">
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/assets/css/styles.css">
<link rel="stylesheet" href="/assets/fonts/fontawesome/css/all.css">

<!--Icons-->
<link rel="shortcut icon" type="image/svg" href={{ "assets/images/logov3.svg" | absolute_url }}>
<link rel="apple-touch-icon" sizes="180x180" href={{ "assets/images/apple-touch-icon.png" | absolute_url }}>
<link rel="manifest" href={{ "assets/images/site.webmanifest" | absolute_url }}>
<link rel="mask-icon" href={{ "assets/images/safari-pinned-tab.svg" | absolute_url }} color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
31 changes: 21 additions & 10 deletions _layouts/blog.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/assets/css/styles.css">
<link rel="stylesheet" href="/assets/fonts/fontawesome/css/all.css">
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->
{% include main_head.html %}

<!--Icons-->
<!--TODO Redo icons using https://realfavicongenerator.net/favicon_result?file_id=p1f53disqm26k1ih194v17oi16366#.YJU2BSaxVaQ -->
<link rel="shortcut icon" type="image/svg" href="assets/images/logov3.svg">
<!-- javascript -->
<script src={{ "assets/js/vendor/marked.min.js" | absolute_url }}></script>
<script src={{ "assets/js/vendor/purify.min.js" | absolute_url }}></script>
<script src={{ "assets/js/vendor/ansi_up.min.js" | absolute_url }}></script>
<script src={{ "assets/js/vendor/prism.min.js" | absolute_url }}></script>
<script src={{ "assets/js/vendor/katex.min.js" | absolute_url }}></script>
<script src={{ "assets/js/vendor/katex-auto-render.min.js" | absolute_url }}></script>
<script type="text/javascript" src={{ "assets/js/notebookjs/notebook.js" | absolute_url }}></script>
<script type="text/javascript" src={{ "assets/js/nbjs_call.js" | absolute_url }}></script>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css" integrity="sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs" crossorigin="anonymous">
<link rel="stylesheet" href={{ "assets/css/vendor/prism.css" | absolute_url }} />
<link rel="stylesheet" href={{ "assets/css/notebook.css" | absolute_url }} />

<!-- SEO optimization -->
{% seo %}
</head>
<body>
<body onload="load_notebooks()">
<div id="main-box">
{% include header.html %}
{% include navigation.html %}
<div id="main-content-box">
{{ content }}
<div class="blog-main">
{{ content }}
</div>
</div>
{% include footer.html %}
</div>
Expand Down
14 changes: 1 addition & 13 deletions _layouts/default.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{ page.title }}</title>
<link rel="stylesheet" href="/assets/css/styles.css">
<link rel="stylesheet" href="/assets/fonts/fontawesome/css/all.css">
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->

<!--Icons-->
<link rel="shortcut icon" type="image/svg" href={{ "assets/images/logov3.svg" | absolute_url }}>
<link rel="apple-touch-icon" sizes="180x180" href={{ "assets/images/apple-touch-icon.png" | absolute_url }}>
<link rel="manifest" href={{ "assets/images/site.webmanifest" | absolute_url }}>
<link rel="mask-icon" href={{ "assets/images/safari-pinned-tab.svg" | absolute_url }} color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
{% include main_head.html %}

<!-- SEO optimization -->
{% seo %}
Expand Down
10 changes: 10 additions & 0 deletions _posts/2021-12-29-ipython-to-html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: iPython Notebook Rendering
layout: blog
image: ../assets/images/2021-12-29.png
description: How to render iPython notebooks on github-pages using Jekyll.
author: Marlin Benedikt Schäfer
excerpt: Since I'm a theoretical physicist that mainly works as a data analyst, I wanted a way to convey information both in text/formulas as well as in code. Usually the ideal way to do something like this are iPython notebooks. However, there was no direct way of rendering them.
---

<div class="notebook" data-nb-path= {{ "assets/notebooks/2021-12-29.ipynb" | relative_url }}></div>
5 changes: 3 additions & 2 deletions _sass/blog.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.blog-main {
padding-left: 20px;
padding-left: 40px;
padding-right: 20px;
padding-top: 20px;
padding-bottom: 20px;
Expand Down Expand Up @@ -42,9 +42,10 @@
}
.blog-post-title {
font-weight: bold;
padding-bottom: 3px;
padding-bottom: 20px;
}
.blog-post-excerpt {
padding-top: .5em;
padding-left: 3px;
}
.blog-feature-img {
Expand Down
23 changes: 23 additions & 0 deletions _sass/notebook_styling.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.notebook {
color: var(--darkgrey);
}
.notebook h1 {
font-size: 2em;
padding-bottom: 10px;
}
.notebook h2 {
font-size: 1.6em;
padding-bottom: 6px;
}
.notebook p {
padding-left: 15px;
line-height: 1.6;
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.notebook code {
/*background: #f5f2f0;*/
background: var(--lightgrey);
border-radius: 6px;
padding: .2em .4em;
}
85 changes: 85 additions & 0 deletions assets/css/notebook.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.nb-notebook {
line-height: 1.5;
}

.nb-stdout, .nb-stderr {
white-space: pre-wrap;
margin: 1em 0;
padding: 0.1em 0.5em;
}

.nb-stderr {
background-color: #FAA;
}

.nb-cell + .nb-cell {
margin-top: 0.5em;
}

.nb-output table {
border: 1px solid #000;
border-collapse: collapse;
}

.nb-output th {
font-weight: bold;
}

.nb-output th, .nb-output td {
border: 1px solid #000;
padding: 0.25em;
text-align: left;
vertical-align: middle;
border-collapse: collapse;
}

.nb-notebook blockquote {
border-left: 5px solid #CCC;
margin-left: 0;
padding-left: 1em;
}

.nb-cell {
position: relative;
}

.nb-raw-cell {
white-space: pre-wrap;
background-color: #f5f2f0;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
padding: 1em;
margin: .5em 0;
}

.nb-output {
min-height: 1em;
width: 100%;
overflow-x: scroll;
border-right: 1px dotted #CCC;
}

.nb-output img {
max-width: 100%;
}

.nb-output:before, .nb-input:before {
position: absolute;
font-family: monospace;
color: #999;
left: -7.5em;
width: 7em;
text-align: right;
}

.nb-input:before {
content: "In [" attr(data-prompt-number) "]:";
}
.nb-output:before {
content: "Out [" attr(data-prompt-number) "]:";
}

// Fix pandas dataframe formatting
div[style="max-height:1000px;max-width:1500px;overflow:auto;"] {
max-height: none !important;
}

3 changes: 2 additions & 1 deletion assets/css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
@import "cv";
@import "blog";
@import "resources";
@import "publications";
@import "publications";
@import "notebook_styling"
1 change: 1 addition & 0 deletions assets/css/vendor/katex.min.css

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions assets/css/vendor/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/* PrismJS 1.21.0
https://prismjs.com/download.html#themes=prism&languages=markup+clike+javascript+julia+python+r */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/

code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.token.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #9a6e3a;
/* This background color was intended by the author of this theme. */
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function,
.token.class-name {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}
Binary file added assets/images/2021-12-29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 637de57

Please sign in to comment.