diff --git a/_includes/aio-script.md b/_includes/aio-script.md
index 926e0a6e..a81fbcdd 100644
--- a/_includes/aio-script.md
+++ b/_includes/aio-script.md
@@ -1,13 +1,20 @@
{% comment %}
As a maintainer, you don't need to edit this file.
-If you notice that something doesn't work, please
+If you notice that something doesn't work, please
open an issue: https://github.com/carpentries/styles/issues/new
{% endcomment %}
+{% include manual_episode_order.html %}
+
-{% comment %}
-Create an anchor for every episode.
-{% endcomment %}
-{% for episode in site.episodes %}
-
+
+{% comment %} Create an anchor for every episode. {% endcomment %}
+
+{% for lesson_episode in lesson_episodes %}
+ {% if site.episode_order %}
+ {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
+ {% else %}
+ {% assign episode = lesson_episode %}
+ {% endif %}
+
{% endfor %}
diff --git a/_includes/all_keypoints.html b/_includes/all_keypoints.html
index e4fd289f..f0abd251 100644
--- a/_includes/all_keypoints.html
+++ b/_includes/all_keypoints.html
@@ -3,10 +3,16 @@
{% endcomment %}
{% include base_path.html %}
+{% include manual_episode_order.html %}
Key Points
-{% for episode in site.episodes %}
+{% for lesson_episode in lesson_episodes %}
+ {% if site.episode_order %}
+ {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
+ {% else %}
+ {% assign episode = lesson_episode %}
+ {% endif %}
{% unless episode.break %}
diff --git a/_includes/episode_navbar.html b/_includes/episode_navbar.html
index ea368eba..5abf86f2 100644
--- a/_includes/episode_navbar.html
+++ b/_includes/episode_navbar.html
@@ -9,11 +9,17 @@
Navigation bar for an episode.
{% endcomment %}
+{% include manual_episode_order.html %}
+{% comment %}
+ 'previous_episode' and 'next_episodes' are defined in 'manual_episode_order.html'.
+ These replace 'page.previous' and 'page.next' objects, correspondingly.
+{% endcomment %}
+
- {% if page.next.url %}
- next episode
+ {% if next_episode %}
+ next episode
{% else %}
lesson home
{% endif %}
diff --git a/_includes/manual_episode_order.html b/_includes/manual_episode_order.html
new file mode 100644
index 00000000..2928ee85
--- /dev/null
+++ b/_includes/manual_episode_order.html
@@ -0,0 +1,111 @@
+{% comment %}
+ This file enables manual episode ordering until
+ GitHub Pages switches to Jekyll that supports it
+ without any major hackery. Note, some logic will
+ be required even when this transition happens
+ but it won't be as involved as what we have to do
+ in this file.
+
+ To order lesson episodes or extras manually
+ (instead of the default alpha-numerical order),
+ create array variables 'episode_order' and
+ 'extras_order' in `_config.yml` like so:
+
+ episode_order:
+ - episodeA
+ - episodeB
+
+ extras_order:
+ - extraA
+ - extraB
+
+ Note that "Reference" page is currently always
+ added to "Extras" as the first item.
+
+ The main outcomes of the code in this file are:
+ - 'lesson_episodes' variable that replaces
+ 'site.episodes' variable when manual episode
+ order is defined.
+ - 'lesson_extras' variable that replaces
+ 'site.extras' variable when manual ordering of
+ files in '_extras' is used
+ - 'previous_episode' and 'next_episode' objects
+ that replace 'page.previous' and 'page.next' variables,
+ correspondingly, and that have such properties
+ as 'url' and 'title' and that are used in
+ 'episode_navbar.html'.
+
+ When episode order is specified manualy, the 'lesson_episodes'
+ variable contains a list of episode names ("slugs", to be precise;
+ "slug" is the episode name without '.md'). Therefore, when we
+ iterate over 'lesson_episodes' (in syllabus.html and navbar.html) ,
+ we have to check whether we use manual episode ordering and, if so,
+ find the corresponding episode object. This is what we do with the
+ following code in every loop over 'lesson_episodes':
+
+ {% if site.episode_order %}
+ {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
+ {% else %}
+ {% assign episode = lesson_episode %}
+ {% endif %}
+{% endcomment %}
+
+
+
+{% if site.episode_order %}
+ {% assign lesson_episodes = site.episode_order %}
+{% else %}
+ {% assign lesson_episodes = site.episodes %}
+{% endif %}
+
+
+{% comment %}
+ If 'episode_order' is defined, we need to determine
+ - previous episode object ('previous_episode')
+ - and next episode object ('next_episode')
+{% endcomment %}
+
+
+{% if site.episode_order %}
+ {% for lesson_episode in lesson_episodes %}
+
+ {% comment %}
+ We iterate over the specified lesson episodes using
+ a 'for' loop because we can use
+ 'forloop.first', 'forloop.last', and 'forloop.index0'.
+ {% endcomment %}
+
+ {% unless lesson_episode == page.slug %} {% continue %} {% endunless %}
+
+ {% if forloop.first %}
+ {% assign previous_episode = nil %}
+ {% else %}
+ {% assign p_idx = forloop.index0 | minus: 1 %}
+ {% assign p_name = lesson_episodes[p_idx] %}
+ {% assign previous_episode = site.episodes | where: "slug", p_name | first %}
+ {% endif %}
+
+ {% if forloop.last == true %}
+ {% assign next_episode = nil %}
+ {% else %}
+ {% assign n_idx = forloop.index0 | plus: 1 %}
+ {% assign n_name = lesson_episodes[n_idx] %}
+ {% assign next_episode = site.episodes | where: "slug", n_name | first %}
+ {% endif %}
+ {% endfor %}
+{% else %}
+ {% assign previous_episode = page.previous %}
+ {% assign next_episode = page.next %}
+{% endif %}
+
+
+
+{% if site.extras_order %}
+ {% assign lesson_extras = site.extras_order %}
+{% else %}
+ {% assign lesson_extras = site.extras %}
+{% endif %}
+
+{% comment %}
+ We do not need to determine "previous" or "next" extra.
+{% endcomment %}
diff --git a/_includes/navbar.html b/_includes/navbar.html
index cc9b884a..e406d871 100644
--- a/_includes/navbar.html
+++ b/_includes/navbar.html
@@ -3,6 +3,7 @@
{% endcomment %}
{% include gh_variables.html %}
+{% include manual_episode_order.html %}
- {% for episode in site.episodes %}
+ {% for lesson_episode in lesson_episodes %}
+ {% if site.episode_order %}
+ {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
+ {% else %}
+ {% assign episode = lesson_episode %}
+ {% endif %}
{% if episode.start %} {% comment %} Starting a new day? {% endcomment %}
{% assign day = day | plus: 1 %}
{% if day > 1 %} {% comment %} If about to start day 2 or later, show finishing time for previous day {% endcomment %}
diff --git a/bin/boilerplate/_extras/figures.md b/bin/boilerplate/_extras/figures.md
index ee5b6508..0012c88e 100644
--- a/bin/boilerplate/_extras/figures.md
+++ b/bin/boilerplate/_extras/figures.md
@@ -3,11 +3,17 @@ title: Figures
---
{% include base_path.html %}
+{% include manual_episode_order.html %}
-{% comment %}
-Create anchor for each one of the episodes.
-{% endcomment %}
-{% for episode in site.episodes %}
+
+{% comment %} Create anchor for each one of the episodes. {% endcomment %}
+
+{% for lesson_episode in lesson_episodes %}
+ {% if site.episode_order %}
+ {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
+ {% else %}
+ {% assign episode = lesson_episode %}
+ {% endif %}
{% endfor %}