Skip to content

Commit

Permalink
Add all in one lesson build with Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaiacs committed May 6, 2017
1 parent 895499e commit 3474a5f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
1 change: 0 additions & 1 deletion _includes/episode_navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ <h3>
<div class="col-md-10">
{% if include.episode_navbar_title %}
<h3 class="maintitle"><a href="{{ page.root }}/">{{ site.title }}</a></h3>
<h1 class="maintitle">{{ page.title }}</h1>
{% endif %}
</div>
<div class="col-md-1">
Expand Down
33 changes: 0 additions & 33 deletions _includes/episode_title.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
{% comment %}
Find previous and next episodes (if any).
{% endcomment %}
{% for episode in site.episodes %}
{% if episode.url == page.url %}
{% unless forloop.first %}
{% assign prev_episode = prev %}
{% endunless %}
{% unless forloop.last %}
{% assign next_episode = site.episodes[forloop.index] %}
{% endunless %}
{% endif %}
{% assign prev = episode %}
{% endfor %}

{% comment %}
Display title and prev/next links.
{% endcomment %}
<div class="row">
<div class="col-md-1">
<h3>
{% if prev_episode %}
<a href="{{ page.root }}{{ prev_episode.url }}"><span class="glyphicon glyphicon-menu-left"></span></a>
{% else %}
<a href="{{ page.root }}"><span class="glyphicon glyphicon-menu-up"></span></a>
{% endif %}
</h3>
</div>
<div class="col-md-10">
<h3 class="maintitle"><a href="{{ page.root }}/">{{ site.title }}</a></h3>
<h1 class="maintitle">{{ page.title }}</h1>
</div>
<div class="col-md-1">
<h3>
{% if next_episode %}
<a href="{{ page.root }}{{ next_episode.url }}"><span class="glyphicon glyphicon-menu-right"></span></a>
{% else %}
<a href="{{ page.root }}"><span class="glyphicon glyphicon-menu-up"></span></a>
{% endif %}
</h3>
</div>
</div>
2 changes: 2 additions & 0 deletions _includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
{% for episode in site.episodes %}
<li><a href="{{ page.root }}{{ episode.url }}">{{ episode.title }}</a></li>
{% endfor %}
<li role="separator" class="divider"></li>
<li><a href="{{ page.root }}/aio/">All in one page (Beta)</a></li>
</ul>
</li>
{% endif %}
Expand Down
3 changes: 3 additions & 0 deletions _layouts/break.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
layout: base
---
{% include episode_navbar.html episode_navbar_title=true %}
<article>
{% include episode_title.html %}
{% include episode_break.html %}
{{content}}
</article>
{% include episode_navbar.html episode_navbar_title=false %}
3 changes: 3 additions & 0 deletions _layouts/episode.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
layout: base
---
{% include episode_navbar.html episode_navbar_title=true %}
<article>
{% include episode_title.html %}
{% include episode_overview.html %}
{{content}}
{% include episode_keypoints.html %}
</article>
{% include episode_navbar.html episode_navbar_title=false %}
40 changes: 40 additions & 0 deletions bin/lesson_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,45 @@
FIXME
'''

ROOT_SETUP_MD = '''\
---
layout: page
permalink: /aio/
---
<script>
window.onload = function() {
var lesson_episodes = [
{% for episode in site.episodes %}
"{{ episode.url}}"{% unless forloop.last %},{% endunless %}
{% endfor %}
];
var xmlHttp = []; /* Required since we are going to query every episode. */
for (i=0; i < lesson_episodes.length; i++) {
xmlHttp[i] = new XMLHttpRequest();
xmlHttp[i].episode = lesson_episodes[i]; /* To enable use this later. */
xmlHttp[i].onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var article_here = document.getElementById(this.episode);
var parser = new DOMParser();
var htmlDoc = parser.parseFromString(this.responseText,"text/html");
var htmlDocArticle = htmlDoc.getElementsByTagName("article")[0];
article_here.innerHTML = htmlDocArticle.innerHTML;
}
}
episode_url = "{{ page.root }}" + lesson_episodes[i];
xmlHttp[i].open("GET", episode_url);
xmlHttp[i].send(null);
}
}
</script>
{% comment %}
Create anchor for each one of the episodes.
{% endcomment %}
{% for episode in site.episodes %}
<article id="{{ episode.url }}"></article>
{% endfor %}
'''

EPISODES_INTRODUCTION_MD = '''\
---
title: "Introduction"
Expand Down Expand Up @@ -340,6 +379,7 @@
('index.md', ROOT_INDEX_MD),
('reference.md', ROOT_REFERENCE_MD),
('setup.md', ROOT_SETUP_MD),
('aio.md', ROOT_AIO_MD),
('_episodes/01-introduction.md', EPISODES_INTRODUCTION_MD),
('_extras/about.md', EXTRAS_ABOUT_MD),
('_extras/discuss.md', EXTRAS_DISCUSS_MD),
Expand Down

0 comments on commit 3474a5f

Please sign in to comment.