pub const DEFAULT_CONNECT_URL: &str = "https://dig.net";
pub const HTML_CONTENT_TYPE: &str = "text/html";
fn escape(input: &str) -> String {
input
.replace('&', "&")
.replace('<', "<")
.replace('>', ">")
.replace('"', """)
.replace('\'', "'")
}
fn page(accent: &str, glow: &str, brand_tag: &str, heading: &str, body_html: &str) -> String {
format!(
r##"<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{heading}</title>
<style>
:root {{ color-scheme: dark; }}
* {{ box-sizing: border-box; }}
html, body {{ height: 100%; margin: 0; }}
body {{
display: flex; align-items: center; justify-content: center;
min-height: 100%; padding: 24px;
background: radial-gradient(1200px 600px at 50% -10%, {glow} 0%, #0a0f1e 60%, #070a14 100%);
color: #e8ecf6;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}}
main {{ width: 100%; max-width: 30rem; text-align: center; }}
.brand {{
font-size: 0.8125rem; letter-spacing: 0.18em; text-transform: uppercase;
color: {accent}; margin: 0 0 1.25rem;
}}
.brand b {{ color: #cdd6f0; font-weight: 700; }}
h1 {{ font-size: 1.5rem; line-height: 1.25; margin: 0 0 0.75rem; color: #ffffff; }}
p {{ font-size: 1rem; line-height: 1.6; margin: 0 0 1.75rem; color: #aeb7d4; }}
a.cta {{
display: inline-block; padding: 0.75rem 1.5rem; border-radius: 0.625rem;
background: {accent}; color: #ffffff; font-weight: 600; font-size: 1rem;
text-decoration: none; transition: background 120ms ease;
}}
a.cta:focus-visible {{ outline: 3px solid #9fb8ff; outline-offset: 3px; }}
@media (prefers-reduced-motion: reduce) {{ a.cta {{ transition: none; }} }}
</style>
</head>
<body>
<main role="main">
<p class="brand">{brand_tag}</p>
<h1>{heading}</h1>
{body_html}
</main>
</body>
</html>
"##
)
}
pub fn unreachable_html(connect_url: &str) -> String {
let href = escape(connect_url);
page(
"#3b6cf6",
"#14213a",
"<b>DIG</b> Network",
"DIG Network unreachable",
&format!(
r##"<p>We couldn't reach a DIG node or the public gateway to load this content. Connect a local DIG node to view it — it's faster and fully decentralized.</p>
<a class="cta" href="{href}" rel="noopener noreferrer">Connect to Node</a>"##
),
)
}
pub fn integrity_failure_html() -> String {
page(
"#e5484d",
"#3a1416",
"<b>DIG</b> Network · Security",
"Integrity Verification Failed",
r##"<p role="alert">The content served for this address did not match its on-chain fingerprint. It may have been tampered with or served by an impostor, so it was <strong>not displayed</strong>. This is a security protection — the verified content could not be produced.</p>"##,
)
}