Remove software carpentries logo
[rnaseq-cwl-training.git] / _includes / manual_episode_order.html
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 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':
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 {% comment %}
54 Manual ordering of Episodes begins here
55 {% endcomment %}
56
57 {% if site.episode_order %}
58     {% assign lesson_episodes = site.episode_order %}
59 {% else %}
60     {% assign lesson_episodes = site.episodes %}
61 {% endif %}
62
63
64 {% comment %}
65     If 'episode_order' is defined, we need to determine
66     - previous episode object ('previous_episode')
67     - and next episode object ('next_episode')
68 {% endcomment %}
69
70
71 {% if site.episode_order %}
72   {% for lesson_episode in lesson_episodes %}
73
74     {% comment %}
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'.
78     {% endcomment %}
79
80     {% unless lesson_episode == page.slug %} {% continue %} {% endunless %}
81
82     {% if forloop.first %}
83       {% assign previous_episode = nil %}
84     {% else %}
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 %}
88     {% endif %}
89
90     {% if forloop.last == true %}
91       {% assign next_episode = nil %}
92     {% else %}
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 %}
96     {% endif %}
97   {% endfor %}
98 {% else %}
99   {% assign previous_episode = page.previous %}
100   {% assign next_episode  = page.next %}
101 {% endif %}
102
103
104 {% comment %}
105 Manual ordering of Extras begins here
106 {% endcomment %}
107
108 {% if site.extras_order %}
109     {% assign lesson_extras = site.extras_order %}
110 {% else %}
111     {% assign lesson_extras = site.extras %}
112 {% endif %}
113
114 {% comment %}
115     We do not need to determine "previous" or "next" extra.
116 {% endcomment %}