|
| 1 | +{% comment %} |
| 2 | + Lists static course files from the 'courses' collection, filtering by archive status. |
| 3 | +
|
| 4 | + Usage: |
| 5 | + Current: {% include course_listing_loop.html archive_status="current" %} |
| 6 | + Archived: {% include course_listing_loop.html archive_status="archived" %} |
| 7 | +{% endcomment %} |
| 8 | + |
| 9 | +{% assign target_status = include.archive_status %} |
| 10 | +{% assign course_files = site.static_files | where: 'collection', 'courses' | sort: 'path' %} |
| 11 | + |
| 12 | +<div class="course-list"> |
| 13 | + {% for file in course_files %} |
| 14 | + {% comment %} |
| 15 | + 1. Check if the file is the index.html we want to link to. |
| 16 | + 2. Skip system directories like .github. |
| 17 | + {% endcomment %} |
| 18 | + {% if file.path contains '/index.html' and file.path contains '/.github/' == false %} |
| 19 | + |
| 20 | + {% comment %} |
| 21 | + Determine the status based on the path. |
| 22 | + {% endcomment %} |
| 23 | + {% assign is_archived = false %} |
| 24 | + {% if file.path contains '/expired/' %} |
| 25 | + {% assign is_archived = true %} |
| 26 | + {% endif %} |
| 27 | + |
| 28 | + {% comment %} |
| 29 | + Only show the file if it matches the requested status. |
| 30 | + {% endcomment %} |
| 31 | + {% if (target_status == 'archived' and is_archived) or (target_status == 'current' and is_archived == false) %} |
| 32 | + |
| 33 | + {% assign full_path_parts = file.path | split: '/' %} |
| 34 | + |
| 35 | + {% comment %} |
| 36 | + Extract the course directory name. |
| 37 | + If path is: /_courses/course-A/index.html -> name is 'course-A' |
| 38 | + If path is: /_courses/expired/course-Z/index.html -> name is 'course-Z' |
| 39 | + {% endcomment %} |
| 40 | + {% assign course_folder_name = full_path_parts | slice: -2, 1 | first %} |
| 41 | + |
| 42 | + <div class="course-entry"> |
| 43 | + <h3> |
| 44 | + <a href="{{ file.url | relative_url }}"> |
| 45 | + {{ course_folder_name | replace: "-", " " | capitalize }} |
| 46 | + </a> |
| 47 | + |
| 48 | + {% if is_archived %} |
| 49 | + <span class="badge badge-secondary float-right">Archived</span> |
| 50 | + {% endif %} |
| 51 | + </h3> |
| 52 | + <hr> |
| 53 | + </div> |
| 54 | + {% endif %} |
| 55 | + {% endif %} |
| 56 | + {% endfor %} |
| 57 | +</div> |
0 commit comments