use request path as an alternative to Title metadata

This commit is contained in:
Brian S. Stephan 2021-02-20 22:43:42 -06:00
parent 1cef3b8196
commit 15c88d920b
4 changed files with 24 additions and 4 deletions

View File

@ -44,7 +44,11 @@ def display_page(path):
parent_navs = generate_parent_navs(resolved_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, 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')) mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'))

View File

@ -38,8 +38,14 @@ def test_page_without_title_metadata(client):
"""Test that a page without title metadata gets the default title.""" """Test that a page without title metadata gets the default title."""
response = client.get('/no-title') response = client.get('/no-title')
assert response.status_code == 200 assert response.status_code == 200
assert b'<title>incorporeal.org</title>' in response.data assert b'<title>/no-title - incorporeal.org</title>' in response.data
assert b'<h1>this page doesn\'t have a title!</h1>' 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'<title>/subdir/page-no-title - incorporeal.org</title>' in response.data
def test_page_with_card_metadata(client): def test_page_with_card_metadata(client):
@ -51,6 +57,15 @@ def test_page_with_card_metadata(client):
assert b'<meta property="og:image" content="http://buh.com/test.img">' in response.data assert b'<meta property="og:image" content="http://buh.com/test.img">' 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'<meta property="og:title" content="/no-title">' in response.data
assert b'<meta property="og:description"' not in response.data
assert b'<meta property="og:image"' not in response.data
def test_page_has_modified_timestamp(client): def test_page_has_modified_timestamp(client):
"""Test that pages have modified timestamps in them.""" """Test that pages have modified timestamps in them."""
response = client.get('/') response = client.get('/')

View File

@ -0,0 +1 @@
this is just a page

View File

@ -50,7 +50,7 @@ def test_title_override():
client = app.test_client() client = app.test_client()
response = client.get('/no-title') response = client.get('/no-title')
assert response.status_code == 200 assert response.status_code == 200
assert b'<title>suou.net</title>' in response.data assert b'<title>/no-title - suou.net</title>' in response.data
def test_media_file_access(client): def test_media_file_access(client):