34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
import html
|
|
from db import get_setting
|
|
|
|
FORUM_ENABLED = False
|
|
|
|
def esc(s):
|
|
return html.escape(str(s))
|
|
|
|
|
|
DEFAULT_TEMPLATE = "<html>\n<head>\n<meta name=\"referrer\" content=\"no-referrer\">\n<meta http-equiv=\"x-dns-prefetch-control\" content=\"off\">\n</head>\n<body>\n{{content}}\n</body>\n</html>"
|
|
|
|
|
|
def _default_template():
|
|
name = esc(get_setting("site_name", "tinyweb"))
|
|
forum_link = ' | <a href="/forum">forum</a>' if FORUM_ENABLED else ""
|
|
return (
|
|
'<html>\n<head>\n<meta name="referrer" content="no-referrer">\n<meta http-equiv="x-dns-prefetch-control" content="off">\n</head>\n<body>\n'
|
|
f'<p><b><a href="/">{name}</a></b>'
|
|
' | <a href="/">search</a> | <a href="/pages">browse</a>'
|
|
' | <a href="/tags">tags</a> | <a href="/subscriptions">subscriptions</a>'
|
|
f'{forum_link}'
|
|
' | <a href="/style">customize</a> | <a href="/about">about</a></p>\n'
|
|
"<hr>\n{{content}}\n</body>\n</html>"
|
|
)
|
|
|
|
|
|
def wrap_page(body_html, use_default=False):
|
|
if use_default:
|
|
template = _default_template()
|
|
else:
|
|
template = get_setting("custom_template") or _default_template()
|
|
if "{{content}}" not in template:
|
|
template = _default_template()
|
|
return template.replace("{{content}}", body_html)
|