use request path as an alternative to Title metadata
This commit is contained in:
parent
1cef3b8196
commit
15c88d920b
@ -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'))
|
||||
|
||||
|
@ -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'<title>incorporeal.org</title>' in response.data
|
||||
assert b'<h1>this page doesn\'t have a title!</h1>' in response.data
|
||||
assert b'<title>/no-title - incorporeal.org</title>' 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):
|
||||
@ -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
|
||||
|
||||
|
||||
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):
|
||||
"""Test that pages have modified timestamps in them."""
|
||||
response = client.get('/')
|
||||
|
1
tests/instance/pages/subdir/page-no-title.md
Normal file
1
tests/instance/pages/subdir/page-no-title.md
Normal file
@ -0,0 +1 @@
|
||||
this is just a page
|
@ -50,7 +50,7 @@ def test_title_override():
|
||||
client = app.test_client()
|
||||
response = client.get('/no-title')
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user