diff --git a/handlers.py b/handlers.py index 6e67f47..4ef8939 100644 --- a/handlers.py +++ b/handlers.py @@ -2,15 +2,15 @@ import json from datetime import datetime from db import get_db, get_setting, set_setting, get_site_name, index_url, clean_url -from templates import esc, snippet, wrap_page +from templates import esc, snippet, wrap_page, DEFAULT_TEMPLATE from rns_client import fetch_remote_sites -def _respond(body_html, status=200): +def _respond(body_html, status=200, use_default=False): return { "status": status, "content_type": "text/html; charset=utf-8", - "body": wrap_page(body_html), + "body": wrap_page(body_html, use_default=use_default), "headers": {}, } @@ -186,19 +186,13 @@ def handle_search(query): if q and remote_rows: sub_count = f" + {len(remote_rows)} from subscriptions" return _respond( - f'
{count} page(s) indexed.' - f' + add url' - f' | browse' - f' | tags' - f' | subscriptions' - f' | customize' - f' | about
' - f'Some classes you can target:
" - f"" - f"body - page background, font\n" - f"h1 - page titles\n" - f"input, button - search bar\n" - f"a - links\n" - f".result - each search result\n" - f".note - your notes on results\n" - f".trusted - trusted sites dropdown\n" - f"small - url text\n" - f"ul, li - browse page list" - f"" - f'
Edit the full page template. Use {esc('{{content}}')} "
+ f"where page content should appear.
Drag this link to your bookmarks bar. Click it on any page to index it instantly.
" f'' f"{msg}
" - f'back' + f'back', + use_default=True, ) def handle_style_submit(body): - css = body.get("css", [""])[0] + template = body.get("template", [""])[0] name = body.get("site_name", ["tinyweb"])[0].strip() sharing = "1" if body.get("sharing_enabled") else "0" - set_setting("custom_css", css) + set_setting("custom_template", template if template.strip() != DEFAULT_TEMPLATE.strip() else "") set_setting("site_name", name or "tinyweb") set_setting("sharing_enabled", sharing) return handle_style_form("Saved.") @@ -755,6 +743,7 @@ def handle_subscription_autosync(sub_id): def handle_subscription_delete(sub_id): db = get_db() + db.execute("DELETE FROM remote_pages WHERE subscription_id = ?", (sub_id,)) db.execute("DELETE FROM subscriptions WHERE id = ?", (sub_id,)) db.commit() db.close() @@ -826,7 +815,7 @@ def dispatch_request(data): elif path == "/bookmark": return handle_bookmark(query) elif path == "/style": - return handle_style_form() + return handle_style_form(query=query) elif path == "/about": return handle_about() elif path == "/export": diff --git a/index.db b/index.db index eaa39d2..e9cae1f 100644 Binary files a/index.db and b/index.db differ diff --git a/templates.py b/templates.py index 735a38e..372e736 100644 --- a/templates.py +++ b/templates.py @@ -15,7 +15,26 @@ def snippet(text, query, ctx=80): return ("..." if start > 0 else "") + text[start:end] + ("..." if end < len(text) else "") -def wrap_page(body_html): - css = get_setting("custom_css") - style = f"" if css else "" - return f"{style}{body_html}" +DEFAULT_TEMPLATE = "\n\n\n\n{{content}}\n\n" + + +def _default_template(): + name = esc(get_setting("site_name", "tinyweb")) + return ( + "\n\n\n\n" + f'{name}' + ' | search | browse' + ' | tags | subscriptions' + ' | customize | about
\n' + "