File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments