move forum layout CSS to main site template system
- Remove FORUM_CSS_DEFAULT/KODAMA2 and _forum_css() from forum handlers - Add FORUM_CSS constant to templates.py with layout-only forum CSS - Inject forum CSS into any template's <head> via wrap_page() - Add forum layout styles to kodama2.html theme - Update database custom template
This commit is contained in:
parent
1cac0b1ef1
commit
b5ffc6c532
2 changed files with 41 additions and 2 deletions
24
templates.py
24
templates.py
|
|
@ -7,14 +7,30 @@ def esc(s):
|
||||||
return html.escape(str(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>"
|
FORUM_CSS = """
|
||||||
|
<style>
|
||||||
|
.forum-form { max-width: 500px; }
|
||||||
|
.forum-form input:not([type=checkbox]):not([type=radio]), .forum-form textarea { width: 100%; box-sizing: border-box; }
|
||||||
|
.forum-form textarea { resize: vertical; }
|
||||||
|
.forum-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
||||||
|
.forum-toolbar form { flex: 1; min-width: 160px; margin: 0; }
|
||||||
|
.forum-toolbar input[name=q] { width: 100%; box-sizing: border-box; }
|
||||||
|
.forum-toolbar-actions { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||||
|
.forum-list { list-style: none; padding: 0; }
|
||||||
|
.forum-status { margin: 0 0 0.8rem 0; }
|
||||||
|
.forum-status span { margin-right: 0.5rem; }
|
||||||
|
.forum-nav { margin: 0.5rem 0; }
|
||||||
|
</style>"""
|
||||||
|
|
||||||
|
DEFAULT_TEMPLATE = "<html>\n<head>\n<meta name=\"referrer\" content=\"no-referrer\">\n<meta http-equiv=\"x-dns-prefetch-control\" content=\"off\">\n" + FORUM_CSS + "</head>\n<body>\n{{content}}\n</body>\n</html>"
|
||||||
|
|
||||||
|
|
||||||
def _default_template():
|
def _default_template():
|
||||||
name = esc(get_setting("site_name", "tinyweb"))
|
name = esc(get_setting("site_name", "tinyweb"))
|
||||||
forum_link = ' | <a href="/forum">forum</a>' if FORUM_ENABLED else ""
|
forum_link = ' | <a href="/forum">forum</a>' if FORUM_ENABLED else ""
|
||||||
return (
|
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'
|
'<html>\n<head>\n<meta name="referrer" content="no-referrer">\n<meta http-equiv="x-dns-prefetch-control" content="off">\n'
|
||||||
|
f'{FORUM_CSS}</head>\n<body>\n'
|
||||||
f'<p><b><a href="/">{name}</a></b>'
|
f'<p><b><a href="/">{name}</a></b>'
|
||||||
' | <a href="/">search</a> | <a href="/pages">browse</a>'
|
' | <a href="/">search</a> | <a href="/pages">browse</a>'
|
||||||
' | <a href="/tags">tags</a> | <a href="/subscriptions">subscriptions</a>'
|
' | <a href="/tags">tags</a> | <a href="/subscriptions">subscriptions</a>'
|
||||||
|
|
@ -34,4 +50,8 @@ def wrap_page(body_html, use_default=False):
|
||||||
forum_link = ' <a href="/forum">forum</a>' if FORUM_ENABLED else ""
|
forum_link = ' <a href="/forum">forum</a>' if FORUM_ENABLED else ""
|
||||||
template = template.replace("{{forum_link}}", forum_link)
|
template = template.replace("{{forum_link}}", forum_link)
|
||||||
template = template.replace("{{site_name}}", esc(get_setting("site_name", "tinyweb")))
|
template = template.replace("{{site_name}}", esc(get_setting("site_name", "tinyweb")))
|
||||||
|
# Inject forum layout CSS into <head> for any template
|
||||||
|
head_end = "</head>"
|
||||||
|
if head_end in template and FORUM_CSS not in template:
|
||||||
|
template = template.replace(head_end, FORUM_CSS + head_end)
|
||||||
return template.replace("{{content}}", body_html)
|
return template.replace("{{content}}", body_html)
|
||||||
|
|
|
||||||
|
|
@ -335,6 +335,25 @@
|
||||||
}
|
}
|
||||||
a.forum-action:hover, a.forum-action-inline:hover { color: #90b4ac; background: rgba(10, 22, 25, 0.6); }
|
a.forum-action:hover, a.forum-action-inline:hover { color: #90b4ac; background: rgba(10, 22, 25, 0.6); }
|
||||||
a.forum-action-inline { padding: 2px 6px; border: none; }
|
a.forum-action-inline { padding: 2px 6px; border: none; }
|
||||||
|
.forum-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0.5rem 0; }
|
||||||
|
.forum-toolbar form { flex: 1; min-width: 160px; margin: 0; }
|
||||||
|
.forum-toolbar input[name=q] { width: 100%; box-sizing: border-box; padding: 6px 10px; }
|
||||||
|
.forum-toolbar-actions { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||||
|
.forum-status { font-size: 0.82rem; opacity: 0.65; margin: 0 0 0.8rem 0; }
|
||||||
|
.forum-status span { margin-right: 1.2rem; }
|
||||||
|
.forum-nav { margin: 0.5rem 0; }
|
||||||
|
.forum-list { list-style: none; padding: 0; }
|
||||||
|
.forum-list li { padding: 0.6rem 0; }
|
||||||
|
.forum-list li + li { border-top: 1px solid rgba(30, 55, 50, 0.2); }
|
||||||
|
.forum-list .thread-title { font-size: 1.05rem; margin-bottom: 0.1rem; }
|
||||||
|
.forum-list .thread-meta { font-size: 0.8rem; opacity: 0.7; }
|
||||||
|
.forum-list .thread-badge { font-size: 0.78rem; opacity: 0.6; }
|
||||||
|
.post { margin-bottom: 1rem; padding-left: 1rem; border-left: 1px solid rgba(40, 70, 65, 0.3); }
|
||||||
|
.post-meta { font-size: 0.82rem; opacity: 0.7; }
|
||||||
|
.section { margin: 1.5rem 0; }
|
||||||
|
.section-title { font-weight: bold; margin-bottom: 0.3rem; }
|
||||||
|
.section-desc { font-size: 0.85rem; opacity: 0.7; margin-bottom: 0.5rem; }
|
||||||
|
.section ul { margin: 0.3rem 0; }
|
||||||
hr { border: none; border-top: 1px solid rgba(30, 55, 50, 0.3); margin: 1rem 0; }
|
hr { border: none; border-top: 1px solid rgba(30, 55, 50, 0.3); margin: 1rem 0; }
|
||||||
|
|
||||||
small {
|
small {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue