|
| 1 | +{% comment %} |
| 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 |
| 7 | + in this file. |
| 8 | + |
| 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: |
| 13 | + |
| 14 | + episode_order: |
| 15 | + - episodeA |
| 16 | + - episodeB |
| 17 | + |
| 18 | + extras_order: |
| 19 | + - extraA |
| 20 | + - extraB |
| 21 | + |
| 22 | + Note that "Reference" page is currently always |
| 23 | + added to "Extras" as the first item. |
| 24 | + |
| 25 | + The main outcomes of the code in this file are: |
| 26 | + - 'lesson_episodes' variable that replaces |
| 27 | + 'site.episodes' variable when manual episode |
| 28 | + order is defined. |
| 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'. |
| 37 | + |
| 38 | + When episode order is specified manualy, 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': |
| 45 | + |
| 46 | + {% if site.episode_order %} |
| 47 | + {% assign episode = site.episodes | where: "slug", lesson_episode | first %} |
| 48 | + {% else %} |
| 49 | + {% assign episode = lesson_episode %} |
| 50 | + {% endif %} |
| 51 | +{% endcomment %} |
| 52 | + |
| 53 | +<!-- Manual ordering of Episodes begins here --> |
| 54 | + |
| 55 | +{% if site.episode_order %} |
| 56 | + {% assign lesson_episodes = site.episode_order %} |
| 57 | +{% else %} |
| 58 | + {% assign lesson_episodes = site.episodes %} |
| 59 | +{% endif %} |
| 60 | + |
| 61 | + |
| 62 | +{% comment %} |
| 63 | + If 'episode_order' is defined, we need to determine |
| 64 | + - previous episode object ('previous_episode') |
| 65 | + - and next episode object ('next_episode') |
| 66 | +{% endcomment %} |
| 67 | + |
| 68 | + |
| 69 | +{% if site.episode_order %} |
| 70 | + {% for lesson_episode in lesson_episodes %} |
| 71 | + |
| 72 | + {% comment %} |
| 73 | + We iterate over the specified lesson episodes using |
| 74 | + a 'for' loop because we can use |
| 75 | + 'forloop.first', 'forloop.last', and 'forloop.index0'. |
| 76 | + {% endcomment %} |
| 77 | + |
| 78 | + {% unless lesson_episode == page.slug %} {% continue %} {% endunless %} |
| 79 | + |
| 80 | + {% if forloop.first %} |
| 81 | + {% assign previous_episode = nil %} |
| 82 | + {% else %} |
| 83 | + {% assign p_idx = forloop.index0 | minus: 1 %} |
| 84 | + {% assign p_name = lesson_episodes[p_idx] %} |
| 85 | + {% assign previous_episode = site.episodes | where: "slug", p_name | first %} |
| 86 | + {% endif %} |
| 87 | + |
| 88 | + {% if forloop.last == true %} |
| 89 | + {% assign next_episode = nil %} |
| 90 | + {% else %} |
| 91 | + {% assign n_idx = forloop.index0 | plus: 1 %} |
| 92 | + {% assign n_name = lesson_episodes[n_idx] %} |
| 93 | + {% assign next_episode = site.episodes | where: "slug", n_name | first %} |
| 94 | + {% endif %} |
| 95 | + {% endfor %} |
| 96 | +{% else %} |
| 97 | + {% assign previous_episode = page.previous %} |
| 98 | + {% assign next_episode = page.next %} |
| 99 | +{% endif %} |
| 100 | + |
| 101 | +<!-- Manual ordering of Extras begins here --> |
| 102 | + |
| 103 | +{% if site.extras_order %} |
| 104 | + {% assign lesson_extras = site.extras_order %} |
| 105 | +{% else %} |
| 106 | + {% assign lesson_extras = site.extras %} |
| 107 | +{% endif %} |
| 108 | + |
| 109 | +{% comment %} |
| 110 | + We do not need to determine "previous" or "next" extra. |
| 111 | +{% endcomment %} |
0 commit comments