diff --git a/incorporealcms/pages.py b/incorporealcms/pages.py index 6191852..c952eaf 100644 --- a/incorporealcms/pages.py +++ b/incorporealcms/pages.py @@ -132,12 +132,15 @@ def generate_parent_navs(path): md = init_md() # read the resource - with app.open_instance_resource(path, 'r') as entry_file: - entry = entry_file.read() - _ = Markup(md.convert(entry)) - page_name = (" ".join(md.Meta.get('title')) if md.Meta.get('title') - else request_path_to_breadcrumb_display(request_path)) - return generate_parent_navs(parent_resource_path) + [(page_name, request_path)] + try: + with app.open_instance_resource(path, 'r') as entry_file: + entry = entry_file.read() + _ = Markup(md.convert(entry)) + page_name = (" ".join(md.Meta.get('title')) if md.Meta.get('title') + else request_path_to_breadcrumb_display(request_path)) + return generate_parent_navs(parent_resource_path) + [(page_name, request_path)] + except FileNotFoundError: + return generate_parent_navs(parent_resource_path) + [(request_path, request_path)] def request_path_to_breadcrumb_display(path): diff --git a/tests/instance/pages/no-index-dir/page.md b/tests/instance/pages/no-index-dir/page.md new file mode 100644 index 0000000..2bcf858 --- /dev/null +++ b/tests/instance/pages/no-index-dir/page.md @@ -0,0 +1 @@ +this is a test page diff --git a/tests/test_pages.py b/tests/test_pages.py index f438540..83c3886 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -35,6 +35,16 @@ def test_generate_page_navs_subdir_with_title_parsing_real_page(app): ] +def test_generate_page_navs_subdir_with_no_index(app): + """Test that breadcrumbs still generate even if a subdir doesn't have an index.md.""" + with app.app_context(): + assert generate_parent_navs('pages/no-index-dir/page.md') == [ + ('incorporeal.org', '/'), + ('/no-index-dir/', '/no-index-dir/'), + ('page', '/no-index-dir/page') + ] + + def test_render_with_user_dark_theme(app): """Test that a request with the dark theme selected renders the dark theme.""" cookie = dump_cookie("user-style", 'dark')