Add custom HTML template editor and clean up UI
- Replace CSS-only customization with full HTML template editing
- Users edit the entire page wrapper with {{content}} placeholder
- Add /style?reset escape hatch to recover from broken templates
- Move nav links to template, remove redundant nav from search page
- Delete remote pages when unsubscribing from an instance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4df0ef03f5
commit
8741c2fffb
2 changed files with 36 additions and 32 deletions
22
templates.py
22
templates.py
|
|
@ -15,7 +15,23 @@ def snippet(text, query, ctx=80):
|
|||
return ("..." if start > 0 else "") + text[start:end] + ("..." if end < len(text) else "")
|
||||
|
||||
|
||||
DEFAULT_TEMPLATE = "<html>\n<head>\n</head>\n<body>\n{{content}}\n</body>\n</html>"
|
||||
|
||||
|
||||
def _default_template():
|
||||
name = esc(get_setting("site_name", "tinyweb"))
|
||||
return (
|
||||
"<html>\n<head>\n</head>\n<body>\n"
|
||||
f'<p><b><a href="/">{name}</a></b>'
|
||||
' | <a href="/">search</a> | <a href="/pages">browse</a>'
|
||||
' | <a href="/tags">tags</a> | <a href="/subscriptions">subscriptions</a>'
|
||||
' | <a href="/style">customize</a> | <a href="/about">about</a></p>\n'
|
||||
"<hr>\n{{content}}\n</body>\n</html>"
|
||||
)
|
||||
|
||||
|
||||
def wrap_page(body_html):
|
||||
css = get_setting("custom_css")
|
||||
style = f"<style>{css}</style>" if css else ""
|
||||
return f"<html><head>{style}</head><body>{body_html}</body></html>"
|
||||
template = get_setting("custom_template") or _default_template()
|
||||
if "{{content}}" not in template:
|
||||
template = _default_template()
|
||||
return template.replace("{{content}}", body_html)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue