2 This file enables manual episode ordering until
3 GitHub Pages switches to Jekyll that supports it
4 without any major hackery. Note, some logic will
5 be required even when this transition happens
6 but it won't be as involved as what we have to do
9 To order lesson episodes or extras manually
10 (instead of the default alpha-numerical order),
11 create array variables 'episode_order' and
12 'extras_order' in `_config.yml` like so:
22 Note that "Reference" page is currently always
23 added to "Extras" as the first item.
25 The main outcomes of the code in this file are:
26 - 'lesson_episodes' variable that replaces
27 'site.episodes' variable when manual episode
29 - 'lesson_extras' variable that replaces
30 'site.extras' variable when manual ordering of
31 files in '_extras' is used
32 - 'previous_episode' and 'next_episode' objects
33 that replace 'page.previous' and 'page.next' variables,
34 correspondingly, and that have such properties
35 as 'url' and 'title' and that are used in
36 'episode_navbar.html'.
38 When episode order is specified manually, the 'lesson_episodes'
39 variable contains a list of episode names ("slugs", to be precise;
40 "slug" is the episode name without '.md'). Therefore, when we
41 iterate over 'lesson_episodes' (in syllabus.html and navbar.html) ,
42 we have to check whether we use manual episode ordering and, if so,
43 find the corresponding episode object. This is what we do with the
44 following code in every loop over 'lesson_episodes':
46 {% if site.episode_order %}
47 {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
49 {% assign episode = lesson_episode %}
54 Manual ordering of Episodes begins here
57 {% if site.episode_order %}
58 {% assign lesson_episodes = site.episode_order %}
60 {% assign lesson_episodes = site.episodes %}
65 If 'episode_order' is defined, we need to determine
66 - previous episode object ('previous_episode')
67 - and next episode object ('next_episode')
71 {% if site.episode_order %}
72 {% for lesson_episode in lesson_episodes %}
75 We iterate over the specified lesson episodes using
76 a 'for' loop because we can use
77 'forloop.first', 'forloop.last', and 'forloop.index0'.
80 {% unless lesson_episode == page.slug %} {% continue %} {% endunless %}
82 {% if forloop.first %}
83 {% assign previous_episode = nil %}
85 {% assign p_idx = forloop.index0 | minus: 1 %}
86 {% assign p_name = lesson_episodes[p_idx] %}
87 {% assign previous_episode = site.episodes | where: "slug", p_name | first %}
90 {% if forloop.last == true %}
91 {% assign next_episode = nil %}
93 {% assign n_idx = forloop.index0 | plus: 1 %}
94 {% assign n_name = lesson_episodes[n_idx] %}
95 {% assign next_episode = site.episodes | where: "slug", n_name | first %}
99 {% assign previous_episode = page.previous %}
100 {% assign next_episode = page.next %}
105 Manual ordering of Extras begins here
108 {% if site.extras_order %}
109 {% assign lesson_extras = site.extras_order %}
111 {% assign lesson_extras = site.extras %}
115 We do not need to determine "previous" or "next" extra.