Skip to content

Commit 3474a5f

Browse files
committed
Add all in one lesson build with Javascript
1 parent 895499e commit 3474a5f

File tree

6 files changed

+48
-34
lines changed

6 files changed

+48
-34
lines changed

_includes/episode_navbar.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ <h3>
1414
<div class="col-md-10">
1515
{% if include.episode_navbar_title %}
1616
<h3 class="maintitle"><a href="{{ page.root }}/">{{ site.title }}</a></h3>
17-
<h1 class="maintitle">{{ page.title }}</h1>
1817
{% endif %}
1918
</div>
2019
<div class="col-md-1">

_includes/episode_title.html

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,9 @@
1-
{% comment %}
2-
Find previous and next episodes (if any).
3-
{% endcomment %}
4-
{% for episode in site.episodes %}
5-
{% if episode.url == page.url %}
6-
{% unless forloop.first %}
7-
{% assign prev_episode = prev %}
8-
{% endunless %}
9-
{% unless forloop.last %}
10-
{% assign next_episode = site.episodes[forloop.index] %}
11-
{% endunless %}
12-
{% endif %}
13-
{% assign prev = episode %}
14-
{% endfor %}
15-
16-
{% comment %}
17-
Display title and prev/next links.
18-
{% endcomment %}
191
<div class="row">
202
<div class="col-md-1">
21-
<h3>
22-
{% if prev_episode %}
23-
<a href="{{ page.root }}{{ prev_episode.url }}"><span class="glyphicon glyphicon-menu-left"></span></a>
24-
{% else %}
25-
<a href="{{ page.root }}"><span class="glyphicon glyphicon-menu-up"></span></a>
26-
{% endif %}
27-
</h3>
283
</div>
294
<div class="col-md-10">
30-
<h3 class="maintitle"><a href="{{ page.root }}/">{{ site.title }}</a></h3>
315
<h1 class="maintitle">{{ page.title }}</h1>
326
</div>
337
<div class="col-md-1">
34-
<h3>
35-
{% if next_episode %}
36-
<a href="{{ page.root }}{{ next_episode.url }}"><span class="glyphicon glyphicon-menu-right"></span></a>
37-
{% else %}
38-
<a href="{{ page.root }}"><span class="glyphicon glyphicon-menu-up"></span></a>
39-
{% endif %}
40-
</h3>
418
</div>
429
</div>

_includes/navbar.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
{% for episode in site.episodes %}
4646
<li><a href="{{ page.root }}{{ episode.url }}">{{ episode.title }}</a></li>
4747
{% endfor %}
48+
<li role="separator" class="divider"></li>
49+
<li><a href="{{ page.root }}/aio/">All in one page (Beta)</a></li>
4850
</ul>
4951
</li>
5052
{% endif %}

_layouts/break.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
layout: base
33
---
44
{% include episode_navbar.html episode_navbar_title=true %}
5+
<article>
6+
{% include episode_title.html %}
57
{% include episode_break.html %}
68
{{content}}
9+
</article>
710
{% include episode_navbar.html episode_navbar_title=false %}

_layouts/episode.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
layout: base
33
---
44
{% include episode_navbar.html episode_navbar_title=true %}
5+
<article>
6+
{% include episode_title.html %}
57
{% include episode_overview.html %}
68
{{content}}
79
{% include episode_keypoints.html %}
10+
</article>
811
{% include episode_navbar.html episode_navbar_title=false %}

bin/lesson_initialize.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,45 @@
278278
FIXME
279279
'''
280280

281+
ROOT_SETUP_MD = '''\
282+
---
283+
layout: page
284+
permalink: /aio/
285+
---
286+
<script>
287+
window.onload = function() {
288+
var lesson_episodes = [
289+
{% for episode in site.episodes %}
290+
"{{ episode.url}}"{% unless forloop.last %},{% endunless %}
291+
{% endfor %}
292+
];
293+
var xmlHttp = []; /* Required since we are going to query every episode. */
294+
for (i=0; i < lesson_episodes.length; i++) {
295+
xmlHttp[i] = new XMLHttpRequest();
296+
xmlHttp[i].episode = lesson_episodes[i]; /* To enable use this later. */
297+
xmlHttp[i].onreadystatechange = function() {
298+
if (this.readyState == 4 && this.status == 200) {
299+
var article_here = document.getElementById(this.episode);
300+
var parser = new DOMParser();
301+
var htmlDoc = parser.parseFromString(this.responseText,"text/html");
302+
var htmlDocArticle = htmlDoc.getElementsByTagName("article")[0];
303+
article_here.innerHTML = htmlDocArticle.innerHTML;
304+
}
305+
}
306+
episode_url = "{{ page.root }}" + lesson_episodes[i];
307+
xmlHttp[i].open("GET", episode_url);
308+
xmlHttp[i].send(null);
309+
}
310+
}
311+
</script>
312+
{% comment %}
313+
Create anchor for each one of the episodes.
314+
{% endcomment %}
315+
{% for episode in site.episodes %}
316+
<article id="{{ episode.url }}"></article>
317+
{% endfor %}
318+
'''
319+
281320
EPISODES_INTRODUCTION_MD = '''\
282321
---
283322
title: "Introduction"
@@ -340,6 +379,7 @@
340379
('index.md', ROOT_INDEX_MD),
341380
('reference.md', ROOT_REFERENCE_MD),
342381
('setup.md', ROOT_SETUP_MD),
382+
('aio.md', ROOT_AIO_MD),
343383
('_episodes/01-introduction.md', EPISODES_INTRODUCTION_MD),
344384
('_extras/about.md', EXTRAS_ABOUT_MD),
345385
('_extras/discuss.md', EXTRAS_DISCUSS_MD),

0 commit comments

Comments
 (0)