diff --git a/src/handler.py b/src/handler.py index 2e3726d..8a2b374 100644 --- a/src/handler.py +++ b/src/handler.py @@ -37,17 +37,27 @@ def get_url_content(url): } return targets +def get_dict_entry_fallback(d, key, fallback): + if key and key in d: + return d[key] + if fallback in d: + return d[fallback] + return d.get('_default', None) def get_entry(args, targets): while args: arg = args.pop(0) if not arg: continue - targets = targets.get(arg, None) + + # Fallback to _404 if the key is not found + targets = get_dict_entry_fallback(targets, arg, '_404') if isinstance(targets, dict): continue return targets, args - return None, args + + # Try to match an index entry + return get_dict_entry_fallback(targets, '', '_index'), args def get_entry_for_url(url, args): targets = get_url_content(url)