Legal documents, maintenance and status page descriptions get an editor with a toolbar of the formatting their field supports, keyboard shortcuts, list continuation, a character count and a preview rendered by the server. Images are no longer rendered: an external image on a status page would hand every visitor's address to its host, so the editor offers none. Editor behavior is tested in a headless browser when Chromium is available. Closes #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
93 lines
3.0 KiB
Templ
93 lines
3.0 KiB
Templ
package web
|
|
|
|
import (
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
|
)
|
|
|
|
templ legalLink(l LegalLink) {
|
|
if l.External {
|
|
<a href={ templ.SafeURL(l.Href) } rel="noopener" class="hover:text-ink">{ i18n.T(ctx, LegalTitleID(l.Kind)) }</a>
|
|
} else {
|
|
<a href={ templ.SafeURL(l.Href) } class="hover:text-ink">{ i18n.T(ctx, LegalTitleID(l.Kind)) }</a>
|
|
}
|
|
}
|
|
|
|
templ legalFooter(links []LegalLink) {
|
|
if len(links) > 0 {
|
|
<footer class="mx-auto flex w-full max-w-5xl justify-end gap-4 px-6 py-6 font-mono text-xs text-muted">
|
|
for _, l := range links {
|
|
@legalLink(l)
|
|
}
|
|
</footer>
|
|
}
|
|
}
|
|
|
|
templ legalBody(html string) {
|
|
<article class="legal-text max-w-2xl">
|
|
@templ.Raw(html)
|
|
</article>
|
|
}
|
|
|
|
// LegalPage shows a platform legal document.
|
|
templ LegalPage(p Page, html string) {
|
|
@Layout(p) {
|
|
<main class="mx-auto max-w-3xl px-6 py-14">
|
|
<p class="mb-10"><a href="/" class="font-mono text-xs tracking-wide text-muted hover:text-ink">uptimesebi</a></p>
|
|
@legalBody(html)
|
|
</main>
|
|
}
|
|
}
|
|
|
|
// PublicLegalPage shows a legal document of a status page.
|
|
templ PublicLegalPage(s agentapi.PageSnapshot, a PublicAssets, kind, html, back string) {
|
|
<!DOCTYPE html>
|
|
<html lang={ i18n.Lang(ctx) }>
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>{ i18n.T(ctx, LegalTitleID(kind)) } · { s.Title }</title>
|
|
<link rel="stylesheet" href={ a.CSSHref }/>
|
|
</head>
|
|
<body class="min-h-screen">
|
|
<main class="mx-auto max-w-3xl px-6 py-14">
|
|
<p class="mb-10"><a href={ templ.SafeURL(back) } class="text-sm text-muted hover:text-ink">{ "← " + s.Title }</a></p>
|
|
@legalBody(html)
|
|
</main>
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
// LegalForm is the stored state of one legal document.
|
|
type LegalForm struct {
|
|
Kind string
|
|
URL string
|
|
Markdown string
|
|
}
|
|
|
|
// LegalSettingsPage edits legal documents. apiBase plus the kind is the
|
|
// endpoint each form saves to.
|
|
templ LegalSettingsPage(p Page, me Me, titleID, introID, apiBase, next string, docs []LegalForm) {
|
|
@consoleShell(p, me) {
|
|
@settingsHeading(titleID, introID)
|
|
for _, d := range docs {
|
|
<section class="mb-12 max-w-2xl">
|
|
@sectionHeading(LegalTitleID(d.Kind))
|
|
<form data-api={ apiBase + d.Kind } data-method="put" data-next={ next }>
|
|
@formError()
|
|
<label class="mb-4 block">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "legal.url") }</span>
|
|
<input type="url" name="url" value={ d.URL } placeholder="https://" class="w-full border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"/>
|
|
</label>
|
|
<div class="mb-1">
|
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "legal.markdown") }</span>
|
|
@MarkdownEditor("markdown", d.Markdown, 14, 100000, MarkdownDocument)
|
|
</div>
|
|
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "legal.hint") }</p>
|
|
@submit(i18n.T(ctx, "common.save"))
|
|
</form>
|
|
</section>
|
|
}
|
|
}
|
|
}
|