Skip to content

Commit fc0e328

Browse files
committed
Make it easier to create and run the slides.
1 parent 6d027e8 commit fc0e328

File tree

7 files changed

+71
-44
lines changed

7 files changed

+71
-44
lines changed

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@
44

55
Microsoft PowerPoint is cool. I like it! It is like a Swiss army knife for consultants. You can make beautiful slides with it. When it comes to code though, PowerPoint sucks. Really! The solution is to use [reveal.js](http://lab.hakim.se/reveal-js/#/). It is cool. You can use Markdown to highlight code. It is responsive but like LaTeX, it can be tedious.
66

7-
Another way to use reveal.js is through Jupyter Notebook. You just create a notebook and then use `nbconvert` to get reveal.js slides as well. The standard output is however boring. I seriously mean it! This repo therefore tries to bridge this gap by using customized colors and images which are based on the [Pivotal](https://pivotal.io/) color scheme.
7+
Another way to use reveal.js is through Jupyter Notebook. You just create a notebook and then use `nbconvert` to get reveal.js slides as well. The standard output is however boring. I seriously mean it! This repo therefore tries to bridge this gap by using customized colors and images.
88

99
Moreover, we live in a cloud native world with a cloud native lifestyle, cloud native storage, cloud native solution. Why not having cloud native presentation slides then? This repo also solves this problem by simply using `cf push`.
1010

1111
## Getting Started
1212

13-
1. You can find a notebook template in the `static` folder which contains some examples like cover and divider slides, markdown syntax and many more. Here is a [link](http://www.slideviper.oquanta.info/tutorial/slideshow_tutorial_slides.html#/3) for a nice intro into creating slides with jupyter notebook.
14-
15-
2. When you are done with editing your notebook, you need to generate the slides with this command `jupyter nbconvert presentation_template.ipynb --to slides --reveal-prefix "reveal.js-3.1.0" --config slides_config.py`. This command basically looks for the reveal.js folder and converts the notebook into a HTML file. The flag `--config slides_config.py` points to some customized settings defined in the `jupyter_template.tpl`. For example there you can control whether the slide numbers are shown or not or you can also add additional plugins etc..
16-
17-
3. Having created the HTML file, it is recommended to use this command `python clean_html.py presentation_template.slides.html` afterwards, especially if you use raw html code in the jupyter notebook. The reason is that in a newer version of nbconvert, it adds section instead of div tags so that data-background doesn't work as expected.
18-
19-
4. Now you can either call `python run.py` to serve the presentation on your local machine or just use `cf push` to push it to the cloud. I use Flask to serve those static files and also be aware that if you change the name of the notebook, this has to be reflected in the `run.py` as well.
13+
1. You can find a notebook template in the `static` folder which contains some examples like cover and divider slides, markdown syntax and many more. Here is a [link](http://www.slideviper.oquanta.info/tutorial/slideshow_tutorial_slides.html#/3) for a nice intro into creating slides with Jupyter notebook.
14+
2. When you are done with editing your notebook, you need to generate the slides with this command:
15+
```
16+
# from ./jupyter-presentation-template/
17+
python create_slides.py --file static/presentation_template.ipynb
18+
```
19+
3. Now you can either call this command to serve the presentation on your local machine
20+
```
21+
python run.py --file static/presentation_template.slides.html
22+
```
23+
or just use `cf push` to push it to the cloud. I use Flask to serve those static files.
2024
2125
#### Requirements:
2226
- Python 3.5.2
23-
- nbconvert 4.2.0
24-
- jupyter 1.0.0
27+
- nbconvert 5.2.1
2528
- reveal.js 3.1.0
2629
2730
#### Demo:
@@ -39,9 +42,6 @@ If you need to change the footer, open `jupyter_template.tpl` and go to `Change
3942
###### Where did you get the image and favicon?
4043
The image used for the cover slide is from [Pexel](https://www.pexels.com/) and the favicon is from [freefavicon](http://www.freefavicon.com/). They are both free to use.
4144
42-
###### Can I change the name of the jupyter notebook?
43-
Yes, you can but make sure to adjust the code for `jupyter nbconvert new_name.ipynb ...`, `python clean_html.py new_name.ipynb` and also in the `run.py` file.
44-
4545
###### Does it work with other reveal.js version?
4646
Yes, but this is not recommended as the colors might be broken due to differences in the css styles.
4747

create_slides.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import subprocess
2+
import argparse
3+
4+
parser = argparse.ArgumentParser()
5+
parser.add_argument('--file', dest='file_name', type=str, help='Name of the jupyter notebook.')
6+
args = parser.parse_args()
7+
8+
9+
def clean_html(html_file):
10+
"""Remove unnecessary tags from slides."""
11+
clean_file = (html_file.replace('<section><section><image>', '')
12+
.replace('</image></section></section>', ''))
13+
return clean_file
14+
15+
16+
def main():
17+
"""Convert the notebook to slides and then do some cleaning."""
18+
try:
19+
output = subprocess.check_output(
20+
['jupyter', 'nbconvert', args.file_name, '--to', 'slides', '--reveal-prefix', 'reveal.js-3.1.0',
21+
'--config', 'static/slides_config.py'], stderr=subprocess.STDOUT).decode('utf-8')
22+
print(output.rstrip())
23+
24+
slide_name = output.split(' ')[-1].rstrip()
25+
with open(slide_name, 'r') as f:
26+
clean_file = clean_html(f.read())
27+
with open(slide_name, 'w') as f:
28+
f.write(clean_file)
29+
print('Successfully adjusted.')
30+
except IndexError:
31+
print('Provide name of the slide.')
32+
33+
34+
main()

manifest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ applications:
66
disk_quota: 256MB
77
random-route: false
88
buildpack: python_buildpack
9-
command: python run.py
9+
command: python run.py --file static/presentation_template.slides.html

run.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
from flask import Flask, request, send_from_directory
21
import os
2+
import argparse
3+
4+
from flask import Flask, request, send_from_directory
5+
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument('--file', dest='file_name', type=str, help='Name of the slides to run.')
8+
args = parser.parse_args()
39

4-
port = int(os.getenv("PORT", 9099))
10+
port = int(os.getenv('PORT', 9099))
511

612
app = Flask(__name__)
713

8-
@app.route("/<path:path>")
14+
15+
@app.route('/<path:path>')
916
def serve_page(path):
10-
return send_from_directory("static", path)
17+
return send_from_directory('static', path)
18+
1119

12-
@app.route("/")
20+
@app.route('/')
1321
def main():
1422
"""Adjust the presentation_name if you rename the jupyter notebook."""
15-
presentation_name = "presentation_template.slides.html"
23+
presentation_name = args.file_name.split('/')[-1]
1624
return app.send_static_file(presentation_name)
1725

18-
if __name__ == "__main__":
19-
app.run(host="0.0.0.0", port=port)
26+
27+
if __name__ == '__main__':
28+
app.run(host='0.0.0.0', port=port)

static/clean_html.py

-17
This file was deleted.

static/css/custom.css

+5-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ ul li{
135135

136136
ul li:before {
137137
display: inline-block;
138-
content: "\25CB";
138+
content: "\25CD";
139139
width: 1em;
140140
margin-left: -1em;
141-
color: #1F6FB8;
141+
color: #000000;
142142
}
143143

144144
/* Correct for links in list */
@@ -176,7 +176,7 @@ ol li ul li:before {
176176
* LINKS
177177
*********************************************/
178178
.reveal a:not(.image) {
179-
color: darkblue;
179+
color: #2D7FDD;
180180
text-decoration: none;
181181
-webkit-transition: color .15s ease;
182182
-moz-transition: color .15s ease;
@@ -185,8 +185,9 @@ ol li ul li:before {
185185
transition: color .15s ease; }
186186

187187
.reveal a:not(.image):hover {
188-
color: #0000f1;
188+
color: #2D7FDD;
189189
text-shadow: none;
190+
text-decoration: underline;
190191
border: none; }
191192

192193
.reveal .roll span:after {

static/slides_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
c = get_config()
22

3-
c.Exporter.template_file = 'jupyter_template'
3+
c.Exporter.template_file = 'static/jupyter_template'

0 commit comments

Comments
 (0)