parent
27bb139a2b
commit
954f7f4e80
@ -39,6 +39,15 @@ def display_page(path):
|
|||||||
logger.debug("redirect path: '%s'", redirect_path)
|
logger.debug("redirect path: '%s'", redirect_path)
|
||||||
return redirect(redirect_path, code=301)
|
return redirect(redirect_path, code=301)
|
||||||
elif render_type == 'markdown':
|
elif render_type == 'markdown':
|
||||||
|
logger.debug("treating path '%s' as markdown '%s'", path, resolved_path)
|
||||||
|
return handle_markdown_file_path(resolved_path)
|
||||||
|
else:
|
||||||
|
logger.exception("unsupported render_type '%s'!?", render_type)
|
||||||
|
abort(500)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_markdown_file_path(resolved_path):
|
||||||
|
"""Given a location on disk, attempt to open it and render the markdown within."""
|
||||||
try:
|
try:
|
||||||
with app.open_instance_resource(resolved_path, 'r') as entry_file:
|
with app.open_instance_resource(resolved_path, 'r') as entry_file:
|
||||||
mtime = datetime.datetime.fromtimestamp(os.path.getmtime(entry_file.name), get_localzone())
|
mtime = datetime.datetime.fromtimestamp(os.path.getmtime(entry_file.name), get_localzone())
|
||||||
@ -60,12 +69,15 @@ def display_page(path):
|
|||||||
|
|
||||||
template = get_meta_str(md, 'template') if md.Meta.get('template') else 'base.html'
|
template = get_meta_str(md, 'template') if md.Meta.get('template') else 'base.html'
|
||||||
|
|
||||||
|
# check if this has a HTTP redirect
|
||||||
|
redirect_url = get_meta_str(md, 'redirect') if md.Meta.get('redirect') else None
|
||||||
|
if redirect_url:
|
||||||
|
logger.debug("redirecting via meta tag to '%s'", redirect_url)
|
||||||
|
return redirect(redirect_url, code=301)
|
||||||
|
|
||||||
return render(template, title=page_title, description=get_meta_str(md, 'description'),
|
return render(template, title=page_title, description=get_meta_str(md, 'description'),
|
||||||
image=get_meta_str(md, 'image'), base_url=request.base_url, content=content,
|
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'))
|
navs=parent_navs, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'))
|
||||||
else:
|
|
||||||
logger.exception("unsupported render_type '%s'!?", render_type)
|
|
||||||
abort(500)
|
|
||||||
|
|
||||||
|
|
||||||
def request_path_to_instance_resource_path(path):
|
def request_path_to_instance_resource_path(path):
|
||||||
|
@ -112,6 +112,13 @@ def test_page_with_forced_empty_title_just_shows_suffix(client):
|
|||||||
assert b'<title>incorporeal.org</title>' in response.data
|
assert b'<title>incorporeal.org</title>' in response.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_page_with_redirect_meta_url_redirects(client):
|
||||||
|
"""Test that if a page specifies a URL to redirect to, that the site serves up a 301."""
|
||||||
|
response = client.get('/redirect')
|
||||||
|
assert response.status_code == 301
|
||||||
|
assert response.location == 'http://www.google.com/'
|
||||||
|
|
||||||
|
|
||||||
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('/')
|
||||||
|
1
tests/instance/pages/redirect.md
Normal file
1
tests/instance/pages/redirect.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
Redirect: http://www.google.com/
|
Loading…
Reference in New Issue
Block a user