From 15c88d920be6c39c4887f4ef9a1d8c3467a09772 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 20 Feb 2021 22:43:42 -0600 Subject: [PATCH] use request path as an alternative to Title metadata --- incorporealcms/pages.py | 6 +++++- tests/functional_tests.py | 19 +++++++++++++++++-- tests/instance/pages/subdir/page-no-title.md | 1 + tests/test_factory.py | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 tests/instance/pages/subdir/page-no-title.md diff --git a/incorporealcms/pages.py b/incorporealcms/pages.py index 3c51176..9b245ea 100644 --- a/incorporealcms/pages.py +++ b/incorporealcms/pages.py @@ -44,7 +44,11 @@ def display_page(path): parent_navs = generate_parent_navs(resolved_path) - return render('base.html', title=get_meta_str(md, 'title'), description=get_meta_str(md, 'description'), + page_title = (get_meta_str(md, 'title') if md.Meta.get('title') else + f'/{instance_resource_path_to_request_path(resolved_path)}') + logger.debug("title (potentially derived): %s", page_title) + + return render('base.html', title=page_title, description=get_meta_str(md, 'description'), image=get_meta_str(md, 'image'), base_url=request.base_url, content=content, navs=parent_navs, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z')) diff --git a/tests/functional_tests.py b/tests/functional_tests.py index 02e643c..47de777 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -38,8 +38,14 @@ def test_page_without_title_metadata(client): """Test that a page without title metadata gets the default title.""" response = client.get('/no-title') assert response.status_code == 200 - assert b'incorporeal.org' in response.data - assert b'

this page doesn\'t have a title!

' in response.data + assert b'/no-title - incorporeal.org' in response.data + + +def test_page_in_subdir_without_title_metadata(client): + """Test that the title-less page display is as expected.""" + response = client.get('/subdir//page-no-title') + assert response.status_code == 200 + assert b'/subdir/page-no-title - incorporeal.org' in response.data def test_page_with_card_metadata(client): @@ -51,6 +57,15 @@ def test_page_with_card_metadata(client): assert b'' in response.data +def test_page_with_card_title_even_when_no_metadata(client): + """Test that a page without metadata still has a card with the derived title.""" + response = client.get('/no-title') + assert response.status_code == 200 + assert b'' in response.data + assert b'suou.net' in response.data + assert b'/no-title - suou.net' in response.data def test_media_file_access(client):