Skip to content

Commit 557494e

Browse files
committed
fix: dark-mode email body legibility and cross-subdomain visited flag
- EmailView: render decrypted email in a forced light-themed iframe so emails that hardcode dark text on no background stay legible when the host page is in dark mode (#159). - Marketing page: store the returning-visitor flag in a cookie scoped to the registrable domain so it carries across postguard.eu subdomains instead of being trapped per-origin in localStorage (#208).
1 parent 1fcfa93 commit 557494e

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/lib/components/fallback/EmailView.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
<div class="email-body">
7272
<iframe
73-
srcdoc={`<style>body{margin:1rem}</style>${parsed.html ?? parsed.text ?? ''}`}
73+
srcdoc={`<!doctype html><html><head><meta charset="utf-8"><style>:root{color-scheme:light}html,body{background:#fff;color:#000}body{margin:1rem}</style></head><body>${parsed.html ?? parsed.text ?? ''}</body></html>`}
7474
title="Mail message"
7575
sandbox=""
7676
></iframe>

src/lib/visitedCookie.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const COOKIE_NAME = 'pg_visited'
2+
const ONE_YEAR_SECONDS = 60 * 60 * 24 * 365
3+
4+
function registrableDomain(hostname: string): string | null {
5+
if (!hostname || hostname === 'localhost') return null
6+
if (/^\d+\.\d+\.\d+\.\d+$/.test(hostname)) return null
7+
const parts = hostname.split('.')
8+
if (parts.length < 2) return null
9+
return parts.slice(-2).join('.')
10+
}
11+
12+
export function hasVisited(): boolean {
13+
if (typeof document === 'undefined') return false
14+
return document.cookie
15+
.split(';')
16+
.some((c) => c.trim().startsWith(`${COOKIE_NAME}=`))
17+
}
18+
19+
export function markVisited(): void {
20+
if (typeof document === 'undefined') return
21+
const domain = registrableDomain(window.location.hostname)
22+
const secure = window.location.protocol === 'https:' ? '; Secure' : ''
23+
const domainAttr = domain ? `; Domain=.${domain}` : ''
24+
document.cookie = `${COOKIE_NAME}=1; Max-Age=${ONE_YEAR_SECONDS}; Path=/; SameSite=Lax${domainAttr}${secure}`
25+
}

src/routes/(marketing)/+page.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { browser } from '$app/environment'
22
import { redirect } from '@sveltejs/kit'
3+
import { hasVisited } from '$lib/visitedCookie'
34

45
export function load() {
56
// Only redirect returning visitors on direct/external navigation (full page load),
67
// not on client-side navigations (e.g. clicking "Home" in the navbar).
78
if (
89
browser &&
910
!(/** @type {any} */ (window).__pg_client_nav) &&
10-
localStorage.getItem('pg_visited')
11+
hasVisited()
1112
) {
1213
redirect(302, '/fileshare')
1314
}

src/routes/(marketing)/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import { resolve } from '$app/paths'
55
import SEO from '$lib/components/SEO.svelte'
66
import { FF_BUSINESS } from '$lib/env'
7+
import { markVisited } from '$lib/visitedCookie'
78
89
let contactEl: HTMLAnchorElement
910
1011
onMount(() => {
11-
localStorage.setItem('pg_visited', 'true')
12+
markVisited()
1213
if (contactEl) {
1314
const addr = `${contactEl.dataset.name}@${contactEl.dataset.domain}`
1415
contactEl.href = `mailto:${addr}`

0 commit comments

Comments
 (0)