-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slight modification of main, styles, and script to automate notebook to HTML #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this specific to your workflow? if yes, could you remove this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, you are right. |
||
|
||
#run nbconvert on a notebook, copy to the templates folter, create a new template and render. | ||
|
||
#First argument: File name of the notebook to work on: e.g., if the notebook is analysis.ipynb, argument is analysis. | ||
#Second argument: Output directory. | ||
#Third argument: title of the post | ||
TITLE=$3 | ||
OUTPUT_DIR=$2 | ||
POST_DATE=`date +'%Y'-%m-%d` | ||
cd notebooks/ | ||
echo "Converting" | ||
jupyter nbconvert --to markdown $1.ipynb | ||
|
||
cd .. | ||
echo "Appending to base post" | ||
cp ./base_post.md $OUTPUT_DIR/$POST_DATE-$1.md | ||
|
||
echo "Copying images" | ||
mkdir $OUTPUT_DIR/images/ | ||
cat ./notebooks/$1.md | tee -a $OUTPUT_DIR/$POST_DATE-$1.md | ||
cp ./notebooks/$1_files/* $OUTPUT_DIR/images/ | ||
echo "Replacing $1" | ||
|
||
sed -ri "s/__TITLE__/$TITLE/g" $OUTPUT_DIR/$POST_DATE-$1.md | ||
sed -ri "s/__DATE__/$POST_DATE/g" $OUTPUT_DIR/$POST_DATE-$1.md | ||
sed -ri "s/$1_files/\/assets\/images\//g" $OUTPUT_DIR/$POST_DATE-$1.md | ||
|
||
#cd .. | ||
|
||
#sed -r "s/FNAME/'$1.html'/g" ./templates/main.html > ./templates/main_$1.html | ||
|
||
#python render.py main_$1.html output_$1.html |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/bash | ||
|
||
#run nbconvert on a notebook, copy to the templates folter, create a new template and render. | ||
|
||
#First argument: File name of the notebook to work on: e.g., if the notebook is analysis.ipynb, argument is analysis. | ||
|
||
cd notebooks/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good idea, but I think that it would be better to write this code in python instead of in a shell script. I think that a good interface could be:
One could also think about the options. For example, the name of the output file (index.html by default) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll use this interface, then. I'd have to research jinja2 a bit to see what templating options are available. |
||
jupyter nbconvert --template basic $1.ipynb | ||
cp $1.html ../templates/ | ||
cd .. | ||
|
||
sed -r "s/FNAME/'$1.html'/g" ./templates/main.html > ./templates/main_$1.html | ||
|
||
python render.py main_$1.html output_$1.html |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import os | ||
import sys | ||
|
||
from jinja2 import Environment, FileSystemLoader | ||
|
||
|
@@ -15,8 +16,8 @@ | |
loader = FileSystemLoader('templates'), | ||
) | ||
|
||
input_file = 'main.html' | ||
output_file = 'index.html' | ||
input_file = sys.argv[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current behaviour is not preserved. Could you please do the following?
|
||
output_file = sys.argv[2] | ||
|
||
# reading the template | ||
template = env.get_template(input_file) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,27 +13,7 @@ | |
|
||
<body> | ||
<div class="container"> | ||
<h1>Integrating a Jupyter Notebook in a Web Page</h1> | ||
<p>Some text.</p> | ||
|
||
<h2>Maths</h2> | ||
|
||
<p>Here is a simple inline equation: $E=mc^2$.</p> | ||
|
||
<p>And for longer equations, use the standard math mode:</p> | ||
|
||
$$ | ||
\mathcal{L}=\bar{\psi}\left(i\gamma^{\mu}\partial_ {\mu}-m\right)\psi | ||
$$ | ||
|
||
<h2>A code section</h2> | ||
<p>Here is some code:</p> | ||
<pre> | ||
import foo | ||
print foo.bar() | ||
</pre> | ||
|
||
{% include 'overfitting.html' %} | ||
{% include FNAME %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If used out of your scripts, FNAME is undefined. So the current behavior is not preserved. Could you use jinja2 in python instead of sed in a shell script to replace FNAME? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right: Here, I was using FNAME as a placeholder and replacing it in the bash Script: The "template/main.html" file was copied into "template/[name-of-the-notebook].html" file, and replaced FNAME with the name of the html created in the previous step. |
||
|
||
</div> | ||
<!-- mathjax --> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, I look forward to see the new style.