strip forum CSS, defer all styling to site template

This commit is contained in:
user 2026-06-06 01:41:41 +00:00
parent 14a885d314
commit 5dce1323c6

View file

@ -19,85 +19,6 @@ def esc(s):
from tinyweb_forum.bloom import BloomFilter from tinyweb_forum.bloom import BloomFilter
FORUM_CSS_DEFAULT = """
<style>
.forum-form { max-width: 500px; }
.forum-form input:not([type=checkbox]):not([type=radio]), .forum-form textarea {
width: 100%; box-sizing: border-box; margin-bottom: 10px; }
.forum-form input[type=checkbox] { width: auto; margin: 0; }
.forum-form button { cursor: pointer; padding: 1px 6px; }
.forum-form textarea { line-height: 1.5; resize: vertical; }
.forum-form small { display: block; margin-bottom: 6px; font-size: 0.8rem; opacity: 0.7; }
.forum-form label { display: block; margin-bottom: 6px; }
.forum-form + .forum-form { margin-top: 0.8rem; }
.forum-form label.checkbox-label { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.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; }
.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; }
a.forum-action { text-decoration: none; padding: 1px 4px; }
a.forum-action:hover, .tag:hover { text-decoration: underline; }
.tag { text-decoration: none; }
.forum-list { list-style: none; padding: 0; }
.forum-list li { padding: 0.6rem 0; }
.forum-list li + li { border-top: 1px solid; opacity: 0.25; }
.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; opacity: 0.85; }
.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; }
.section .forum-form { margin-bottom: 0; }
.pagination { font-size: 0.85rem; }
</style>"""
FORUM_CSS_KODAMA2 = """
<style>
.forum-form { max-width: 500px; }
.forum-form input:not([type=checkbox]):not([type=radio]), .forum-form textarea {
width: 100%; box-sizing: border-box; padding: 10px 12px; margin-bottom: 12px; font-size: 0.95rem;
border: 1px solid; border-radius: 6px; }
.forum-form input[type=checkbox] { width: auto; margin: 0; }
.forum-form button { padding: 10px 20px; cursor: pointer; border: 1px solid; border-radius: 6px; }
.forum-form button:hover { opacity: 0.8; }
.forum-form textarea { font-size: 0.85rem; line-height: 1.5; resize: vertical; }
.forum-form small { display: block; margin-bottom: 6px; font-size: 0.8rem; opacity: 0.7; }
.forum-form label { display: block; margin-bottom: 6px; }
.forum-form + .forum-form { margin-top: 0.8rem; }
.forum-form label.checkbox-label { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.forum-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0.5rem 0; padding: 0.6rem 0.8rem; border: 1px solid; border-radius: 8px; opacity: 0.85; }
.forum-toolbar form { flex: 1; min-width: 160px; }
.forum-toolbar input[name=q] { width: 100%; box-sizing: border-box; padding: 8px 10px; font-size: 0.9rem; border: 1px solid; border-radius: 6px; }
.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; display: flex; gap: 8px; align-items: center; }
a.forum-action { text-decoration: none; font-size: 0.88rem; padding: 6px 14px; border-radius: 6px; }
a.forum-action:hover { text-decoration: none; opacity: 0.8; }
.tag { text-decoration: none; display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 0.82rem; }
a.tag:hover { opacity: 0.8; }
.forum-list { list-style: none; padding: 0; }
.forum-list li { padding: 0.8rem; margin-bottom: 0.5rem; border: 1px solid; border-radius: 8px; }
.forum-list .thread-title { font-size: 1.05rem; margin-bottom: 0.15rem; }
.forum-list .thread-meta { font-size: 0.8rem; opacity: 0.7; }
.forum-list .thread-badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; }
.post { margin-bottom: 1rem; padding: 0.6rem 0.8rem; border: 1px solid; border-radius: 6px; }
.post-meta { font-size: 0.82rem; opacity: 0.7; }
.section { margin: 1.5rem 0; padding: 1rem; border: 1px solid; border-radius: 8px; }
.section-title { font-weight: bold; font-size: 1.05rem; margin-bottom: 0.5rem; }
.section-desc { font-size: 0.85rem; opacity: 0.7; margin-bottom: 0.5rem; }
.section ul { margin: 0.3rem 0; }
.section .forum-form { margin-bottom: 0; }
.pagination { font-size: 0.85rem; }
</style>"""
class ForumHandlers: class ForumHandlers:
def __init__(self, fdb, sync, identity, reticulum, site_name="me"): def __init__(self, fdb, sync, identity, reticulum, site_name="me"):
self.fdb = fdb self.fdb = fdb
@ -138,16 +59,11 @@ class ForumHandlers:
return "" return ""
return f' <a class="forum-action-inline" href="/forum/blockhash/{instance}">[block]</a>' return f' <a class="forum-action-inline" href="/forum/blockhash/{instance}">[block]</a>'
def _forum_css(self):
theme = self.fdb.get_setting("forum_theme", "default")
css = FORUM_CSS_KODAMA2 if theme == "kodama2" else FORUM_CSS_DEFAULT
return css
def _respond(self, body_html, status=200): def _respond(self, body_html, status=200):
return { return {
"status": status, "status": status,
"content_type": "text/html; charset=utf-8", "content_type": "text/html; charset=utf-8",
"body": self._forum_css() + body_html, "body": body_html,
"headers": {}, "headers": {},
} }