customize: split into separate settings and template forms
This commit is contained in:
parent
0928008531
commit
86565b13ac
2 changed files with 14 additions and 12 deletions
|
|
@ -32,7 +32,7 @@ from .subscriptions import (
|
||||||
handle_subscription_delete, handle_subscription_syncall,
|
handle_subscription_delete, handle_subscription_syncall,
|
||||||
_sync_threads,
|
_sync_threads,
|
||||||
)
|
)
|
||||||
from .customize import handle_style_form, handle_style_submit, handle_about
|
from .customize import handle_style_form, handle_style_submit, handle_style_template_submit, handle_about
|
||||||
from .tags import handle_tags, handle_tag_browse
|
from .tags import handle_tags, handle_tag_browse
|
||||||
from .data import (
|
from .data import (
|
||||||
handle_export, handle_import_form, handle_import_submit,
|
handle_export, handle_import_form, handle_import_submit,
|
||||||
|
|
@ -123,6 +123,8 @@ def _dispatch_inner(data):
|
||||||
return handle_delete(pid) if pid is not None else _error(400)
|
return handle_delete(pid) if pid is not None else _error(400)
|
||||||
elif path == "/style":
|
elif path == "/style":
|
||||||
return handle_style_submit(body, gateway_host=gateway_host, scheme=scheme)
|
return handle_style_submit(body, gateway_host=gateway_host, scheme=scheme)
|
||||||
|
elif path == "/style/template":
|
||||||
|
return handle_style_template_submit(body, gateway_host=gateway_host, scheme=scheme)
|
||||||
elif path == "/style/reset":
|
elif path == "/style/reset":
|
||||||
set_setting("custom_template", "")
|
set_setting("custom_template", "")
|
||||||
return handle_style_form("Template reset to default.", gateway_host=gateway_host, scheme=scheme)
|
return handle_style_form("Template reset to default.", gateway_host=gateway_host, scheme=scheme)
|
||||||
|
|
|
||||||
|
|
@ -127,22 +127,16 @@ def handle_style_form(msg="", gateway_host="", scheme="http"):
|
||||||
f'<a href="/reindex">manage semantic index</a><br><br>'
|
f'<a href="/reindex">manage semantic index</a><br><br>'
|
||||||
f"</div>"
|
f"</div>"
|
||||||
f"{forum_section}"
|
f"{forum_section}"
|
||||||
f'<div id="unsaved" style="display:none;color:#888">* unsaved changes</div>'
|
f'<button type="submit">save settings</button>'
|
||||||
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"</form>"
|
f"</form>"
|
||||||
f"<h2>custom html</h2>"
|
f"<h2>custom html</h2>"
|
||||||
f"<p>Edit the full page template. Use <code>{esc('{{content}}')}</code> "
|
f"<p>Edit the full page template. Use <code>{esc('{{content}}')}</code> "
|
||||||
f"where page content should appear.</p>"
|
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'<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"<h2>bookmarklet</h2>"
|
||||||
f"<p>Drag this link to your bookmarks bar. Click it on any page to index it instantly.</p>"
|
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>'
|
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)
|
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():
|
def handle_about():
|
||||||
name = get_site_name()
|
name = get_site_name()
|
||||||
dest_hash = get_setting("dest_hash")
|
dest_hash = get_setting("dest_hash")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue