Skip to content

Commit f8f9a7c

Browse files
authored
Create sort_lessons.py
1 parent cef31b3 commit f8f9a7c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/scripts/sort_lessons.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import yaml
2+
3+
# Define preferred sort order for lesson status
4+
STATUS_ORDER = ["Beta", "Alpha", "pre-Alpha"]
5+
6+
# Load the YAML
7+
with open("_data/ui-text.yml", "r") as f:
8+
data = yaml.safe_load(f)
9+
10+
# Pull all lessons across years
11+
all_lessons = []
12+
for year in data["en"]["lessontab"]["years"]:
13+
for lesson in year["lessons"]:
14+
lesson["year"] = year["year"]
15+
all_lessons.append(lesson)
16+
17+
# Sorting function
18+
def lesson_sort_key(lesson):
19+
status = lesson.get("status", "pre-Alpha")
20+
return (STATUS_ORDER.index(status), lesson.get("lesson-title", ""))
21+
22+
# Sort the lessons
23+
sorted_lessons = sorted(all_lessons, key=lesson_sort_key)
24+
25+
# Save sorted list under a new key
26+
data["en"]["lessontab"]["lessons_sorted"] = sorted_lessons
27+
28+
# Output to a new file (optional: overwrite original if you prefer)
29+
with open("_data/ui-text-sorted.yml", "w") as f:
30+
yaml.dump(data, f, sort_keys=False, allow_unicode=True)

0 commit comments

Comments
 (0)