Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 10:02:47

0001 {% comment %}
0002     This file enables manual episode ordering until
0003     GitHub Pages switches to Jekyll that supports it
0004     without any major hackery. Note, some logic will
0005     be required even when this transition happens
0006     but it will not be as involved as what we have to do
0007     in this file.
0008 
0009     To order lesson episodes or extras manually
0010     (instead of the default alpha-numerical order),
0011     create array variables 'episode_order' and
0012     'extras_order' in `_config.yml` like so:
0013 
0014     episode_order:
0015       - episodeA
0016       - episodeB
0017 
0018     extras_order:
0019       - extraA
0020       - extraB
0021 
0022     Note that "Reference" page is currently  always
0023     added to "Extras" as the first item.
0024 
0025     The main outcomes of the code in this file are:
0026      - 'lesson_episodes' variable that replaces
0027        'site.episodes' variable when manual episode
0028        order is defined.
0029      - 'lesson_extras' variable that replaces
0030        'site.extras' variable when manual ordering of
0031        files in '_extras' is used
0032        - 'previous_episode' and 'next_episode' objects
0033        that replace 'page.previous' and 'page.next' variables,
0034        correspondingly, and that have such properties
0035        as 'url' and 'title' and that are used in
0036        'episode_navbar.html'.
0037 
0038     When episode order is specified manually, the 'lesson_episodes'
0039     variable contains a list of episode names ("slugs", to be precise;
0040     "slug" is the episode name without '.md').  Therefore, when we
0041     iterate over 'lesson_episodes' (in syllabus.html and navbar.html) ,
0042     we have to check whether we use manual episode ordering and, if so,
0043     find the corresponding episode object. This is what we do with the
0044     following code in every loop over 'lesson_episodes':
0045 
0046         {% if site.episode_order %}
0047           {% assign episode = site.episodes | where: "slug", lesson_episode | first %}
0048         {% else %}
0049           {% assign episode = lesson_episode %}
0050         {% endif %}
0051 {% endcomment %}
0052 
0053 {% comment %}
0054 Manual ordering of Episodes begins here
0055 {% endcomment %}
0056 
0057 {% if site.episode_order %}
0058     {% assign lesson_episodes = site.episode_order %}
0059 {% else %}
0060     {% assign lesson_episodes = site.episodes %}
0061 {% endif %}
0062 
0063 
0064 {% comment %}
0065     If 'episode_order' is defined, we need to determine
0066     - previous episode object ('previous_episode')
0067     - and next episode object ('next_episode')
0068 {% endcomment %}
0069 
0070 
0071 {% if site.episode_order %}
0072   {% for lesson_episode in lesson_episodes %}
0073 
0074     {% comment %}
0075         We iterate over the specified lesson episodes using
0076         a 'for' loop because we can use
0077         'forloop.first', 'forloop.last', and 'forloop.index0'.
0078     {% endcomment %}
0079 
0080     {% unless lesson_episode == page.slug %} {% continue %} {% endunless %}
0081 
0082     {% if forloop.first %}
0083       {% assign previous_episode = nil %}
0084     {% else %}
0085       {% assign p_idx = forloop.index0 | minus: 1 %}
0086       {% assign p_name = lesson_episodes[p_idx] %}
0087       {% assign previous_episode = site.episodes | where: "slug", p_name | first %}
0088     {% endif %}
0089 
0090     {% if forloop.last == true %}
0091       {% assign next_episode = nil %}
0092     {% else %}
0093       {% assign n_idx = forloop.index0 | plus: 1 %}
0094       {% assign n_name = lesson_episodes[n_idx] %}
0095       {% assign next_episode = site.episodes | where: "slug", n_name | first %}
0096     {% endif %}
0097   {% endfor %}
0098 {% else %}
0099   {% assign previous_episode = page.previous %}
0100   {% assign next_episode  = page.next %}
0101 {% endif %}
0102 
0103 
0104 {% comment %}
0105 Manual ordering of Extras begins here
0106 {% endcomment %}
0107 
0108 {% if site.extras_order %}
0109     {% assign lesson_extras = site.extras_order %}
0110 {% else %}
0111     {% assign lesson_extras = site.extras %}
0112 {% endif %}
0113 
0114 {% comment %}
0115     We do not need to determine "previous" or "next" extra.
0116 {% endcomment %}