Skip to content

Commit f559e3f

Browse files
committed
Remove course ID from slug and assume default course
Fixes #1288
1 parent ce68189 commit f559e3f

4 files changed

Lines changed: 13 additions & 41 deletions

File tree

autoload/NavigationManager.gd

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _url_normalization_regex := RegExpGroup.compile(
2222
r"^(?<prefix>user:\/\/|res:\/\/|\.*?\/+)(?<course>[^\/]+)\/(?<lesson>[^\/]+)\/?(?<lesson_file>[^\.]+\.[^\/]+)?\/?(?<practice>.*)?",
2323
)
2424
var _slug_normalization_regex := RegExpGroup.compile(
25-
r"^(?<course>[^\/]+)\/(?<lesson>[^\/]+)\/?(?<practice>.*)?",
25+
r"^(?<lesson>[^\/]+)\/?(?<practice>.*)?",
2626
)
2727
var _lesson_cache := { }
2828

@@ -136,12 +136,12 @@ func navigate_to_welcome_screen() -> void:
136136
welcome_screen_navigation_requested.emit()
137137

138138

139-
func navigate_to_lesson(course_id: String, lesson_slug: String) -> void:
140-
navigate_to("%s/%s" % [course_id, lesson_slug])
139+
func navigate_to_lesson(lesson_slug: String) -> void:
140+
navigate_to("%s" % [lesson_slug])
141141

142142

143-
func navigate_to_practice(course_id: String, lesson_slug: String, practice_id: String) -> void:
144-
navigate_to("%s/%s/%s" % [course_id, lesson_slug, practice_id])
143+
func navigate_to_practice(lesson_slug: String, practice_id: String) -> void:
144+
navigate_to("%s/%s" % [lesson_slug, practice_id])
145145

146146

147147
func navigate_to(metadata: String) -> void:
@@ -155,16 +155,13 @@ func navigate_to(metadata: String) -> void:
155155

156156
var normalized := NormalizedUrl.new(regex_result)
157157

158-
var course_index := CourseIndexPaths.get_course_index_instance(normalized.course_path)
159-
if not course_index:
160-
push_error("'%s' is not a valid course" % [normalized.course_path])
161-
return
158+
var course_index := CourseIndexPaths.get_course_index_instance(CourseIndexPaths.DEFAULT_COURSE_INDEX)
162159

163160
# legacy slugs support
164161
var legacy_path := normalized.lesson_path
165162
var lesson_slug := course_index.get_real_slug_from_slug(legacy_path)
166163
if lesson_slug != legacy_path:
167-
regex_result = _slug_normalization_regex.search("%s/%s" % [course_index.get_course_id(), lesson_slug])
164+
regex_result = _slug_normalization_regex.search("%s" % [lesson_slug])
168165
normalized = NormalizedUrl.new(regex_result)
169166

170167
var lesson_path := course_index.get_lesson_path_from_slug(normalized.lesson_path)
@@ -174,7 +171,7 @@ func navigate_to(metadata: String) -> void:
174171
push_error("`%s` is not a lesson" % lesson_path)
175172
return
176173

177-
var effective_path := "%s/%s" % [course_index.get_course_id(), normalized.lesson_path]
174+
var effective_path := "%s" % [normalized.lesson_path]
178175
if normalized.practice_path != "":
179176
var practice := course_index.get_practice_from_slug("%s/%s" % [normalized.lesson_path, normalized.practice_path])
180177
if not practice is BBCodeParser.ParseNode:
@@ -195,12 +192,13 @@ func get_navigation_resource(resource_id: String) -> BBCodeParser.ParseNode:
195192
is_slug = true
196193
normalized_url_groups = _slug_normalization_regex.search(resource_id)
197194
var is_practice := not normalized_url_groups.get_string("practice").is_empty()
195+
196+
var course_index := CourseIndexPaths.get_course_index_instance(CourseIndexPaths.DEFAULT_COURSE_INDEX)
198197

199198
var bbcode_path := resource_id
200199
if is_practice:
201200
bbcode_path = bbcode_path.left(-(normalized_url_groups.get_end("practice")-normalized_url_groups.get_start("practice")+1))
202201
if is_slug:
203-
var course_index := CourseIndexPaths.get_course_index_instance(normalized_url_groups.get_string("course"))
204202
bbcode_path = course_index.get_lesson_path_from_slug(normalized_url_groups.get_string("lesson").trim_suffix("/"))
205203

206204
var lesson_data: BBCodeParser.ParseNode = null
@@ -227,7 +225,6 @@ func get_navigation_resource(resource_id: String) -> BBCodeParser.ParseNode:
227225
_lesson_cache[bbcode_path] = lesson_data
228226

229227
if is_practice:
230-
var course_index := CourseIndexPaths.get_course_index_instance(normalized_url_groups.get_string("course"))
231228
var lesson_slug := course_index.get_lesson_slug_from_path(bbcode_path)
232229
return course_index.get_practice_from_slug("%s/%s" % [lesson_slug, normalized_url_groups.get_string("practice")])
233230
return lesson_data
@@ -354,15 +351,13 @@ func _push_javascript_state(url: String) -> void:
354351

355352
class NormalizedUrl:
356353
var protocol := ""
357-
var course_path := ""
358354
var lesson_path := ""
359355
var practice_path := ""
360356
var lesson_file := ""
361357

362358

363359
func _init(regex_result: RegExMatch) -> void:
364360
protocol = regex_result.get_string("prefix")
365-
course_path = regex_result.get_string("course")
366361
lesson_path = regex_result.get_string("lesson").trim_suffix("/")
367362
practice_path = regex_result.get_string("practice")
368363
lesson_file = regex_result.get_string("lesson_file")
@@ -371,26 +366,8 @@ class NormalizedUrl:
371366
protocol = "res://"
372367

373368

374-
func get_file_path(with_practices: bool = false) -> String:
375-
var file_path := "%s%s/%s" % [protocol, course_path, lesson_path]
376-
if lesson_file != "":
377-
file_path += "/%s" % [lesson_file]
378-
if with_practices and practice_path != "":
379-
file_path += "/%s" % [practice_path]
380-
return file_path
381-
382-
383-
func get_web_url() -> String:
384-
var url := "%s/%s" % [course_path, lesson_path]
385-
if lesson_file != "":
386-
url += "/%s" % [lesson_file]
387-
if practice_path != "":
388-
url += "/%s" % [practice_path]
389-
return url
390-
391-
392369
func _to_string() -> String:
393-
var string := "%s%s/%s" % [protocol, course_path, lesson_path]
370+
var string := "%s%s/%s" % [protocol, CourseIndexPaths.DEFAULT_COURSE_INDEX, lesson_path]
394371
if lesson_file != "":
395372
string += "/%s" % [lesson_file]
396373
if practice_path != "":

ui/UINavigator.gd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func _ready() -> void:
7171
if _lesson_index < 0 or _lesson_index >= course_index.get_lessons_count():
7272
_lesson_index = 0
7373
NavigationManager.navigate_to_lesson(
74-
course_index.get_course_id(),
7574
course_index.get_lesson_slug(_lesson_index),
7675
)
7776
else:
@@ -243,7 +242,6 @@ func _on_practice_next_requested(practice: BBCodeParser.ParseNode) -> void:
243242
var next_practice := BBCodeUtils.get_lesson_practice(lesson_data, index + 1)
244243
var next_practice_id := BBCodeUtils.get_practice_id(next_practice)
245244
NavigationManager.navigate_to_practice(
246-
course_index.get_course_id(),
247245
course_index.get_lesson_slug(_lesson_index),
248246
next_practice_id,
249247
)
@@ -273,15 +271,13 @@ func _on_practice_previous_requested(practice: BBCodeParser.ParseNode) -> void:
273271
var previous_practice_id := BBCodeUtils.get_practice_id(previous_practice)
274272
# Otherwise, go to the previous practice in the set.
275273
NavigationManager.navigate_to_practice(
276-
course_index.get_course_id(),
277274
course_index.get_lesson_slug(_lesson_index),
278275
previous_practice_id,
279276
)
280277

281278

282279
func _on_practice_requested(practice: BBCodeParser.ParseNode) -> void:
283280
NavigationManager.navigate_to_practice(
284-
course_index.get_course_id(),
285281
course_index.get_lesson_slug(_lesson_index),
286282
BBCodeUtils.get_practice_id(practice),
287283
)
@@ -298,7 +294,6 @@ func _on_lesson_completed() -> void:
298294

299295
_clear_history_stack()
300296
NavigationManager.navigate_to_lesson(
301-
course_index.get_course_id(),
302297
course_index.get_lesson_slug(_lesson_index),
303298
)
304299

ui/components/BreadCrumbs.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func _create_navigation_node(text: String, course_index: CourseIndex, path: Stri
116116
navigation_node.add_theme_font_size_override("font_size", NODE_FONT_SIZE)
117117
navigation_node.mouse_default_cursor_shape = CURSOR_POINTING_HAND
118118
add_child(navigation_node)
119-
var slug := "%s/%s" % [course_index.get_course_id(), course_index.get_lesson_slug_from_path(path)]
119+
var slug := "%s" % [course_index.get_lesson_slug_from_path(path)]
120120
navigation_node.pressed.connect(_on_navigation_pressed.bind(slug))
121121

122122

ui/screens/course_outliner/CourseLessonDetails.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ func _on_goto_lesson_pressed() -> void:
9393
if not lesson:
9494
return
9595

96-
NavigationManager.navigate_to("%s/%s" % [course_index.get_course_id(), course_index.get_lesson_slug_from_path(lesson.bbcode_path)])
96+
NavigationManager.navigate_to("%s" % [course_index.get_lesson_slug_from_path(lesson.bbcode_path)])

0 commit comments

Comments
 (0)