Fix custom template rendering and ensure customize page uses default layout

Add use_default parameter to wrap_page/respond so the customize page
always renders with the default template (preventing a broken custom
template from locking out the editor). Also fix the stored custom
template: add <!DOCTYPE html> to prevent quirks mode and remove
newlines inside CSS cursor data URIs that caused CSS parse errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Derick Phan 2026-03-26 09:45:42 -07:00
parent 8741c2fffb
commit b17988fc95
No known key found for this signature in database
3 changed files with 10 additions and 6 deletions

View file

@ -6,11 +6,11 @@ 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": {},
}
@ -386,7 +386,8 @@ def handle_style_form(msg="", query=None):
f"<p>Drag this link to your bookmarks bar. Click it on any page to index it instantly.</p>"
f'<p><a href="javascript:void(fetch(\'http://localhost:8080/bookmark?url=\'+encodeURIComponent(location.href)).then(r=>r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}</a></p>'
f"<p>{msg}</p>"
f'<a href="/">back</a>'
f'<a href="/">back</a>',
use_default=True,
)

BIN
index.db

Binary file not shown.

View file

@ -30,8 +30,11 @@ def _default_template():
)
def wrap_page(body_html):
template = get_setting("custom_template") or _default_template()
if "{{content}}" not in template:
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)