customize: split into separate settings and template forms

This commit is contained in:
blankie 2026-06-14 08:14:43 +00:00
parent 0928008531
commit 86565b13ac
2 changed files with 14 additions and 12 deletions

View file

@ -127,22 +127,16 @@ def handle_style_form(msg="", gateway_host="", scheme="http"):
f'<a href="/reindex">manage semantic index</a><br><br>'
f"</div>"
f"{forum_section}"
f'<div id="unsaved" style="display:none;color:#888">* unsaved changes</div>'
f'<button type="submit">save</button>'
f'<script>'
f'(function(){{'
f"var f=document.querySelector('form');"
f"var u=document.getElementById('unsaved');"
f"f.addEventListener('change',function(){{u.style.display=''}});"
f"f.addEventListener('submit',function(){{u.style.display='none'}});"
f'}})();'
f'</script>'
f'<button type="submit">save settings</button>'
f"</form>"
f"<h2>custom html</h2>"
f"<p>Edit the full page template. Use <code>{esc('{{content}}')}</code> "
f"where page content should appear.</p>"
f'<form method="post" action="/style/template">'
f'{_csrf_field()}'
f'<textarea name="template" rows="20" cols="60">{esc(template)}</textarea><br>'
f'<small>Saved with the form above.</small><br><br>'
f'<button type="submit">save template</button>'
f"</form>"
f"<h2>bookmarklet</h2>"
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(\'{esc(scheme)}://{esc(gateway_host or "localhost:8080")}/bookmark?url=\'+encodeURIComponent(location.href)+\'&token={_get_bookmark_token()}\').then(r=>r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}</a></p>'
@ -223,6 +217,12 @@ def handle_style_submit(body, gateway_host="", scheme="http"):
gateway_host=gateway_host, scheme=scheme)
def handle_style_template_submit(body, gateway_host="", scheme="http"):
template = body.get("template", [""])[0].replace("\r\n", "\n").replace("\r", "\n")
set_setting("custom_template", template if template.strip() != DEFAULT_TEMPLATE.strip() else "")
return handle_style_form("Template saved.", gateway_host=gateway_host, scheme=scheme)
def handle_about():
name = get_site_name()
dest_hash = get_setting("dest_hash")