Show website logos and the logo.dev credit in the appearance preview

The preview of unsaved changes now draws button icons like the public
page: website logos when logos are enabled, the first letter when
not, plus the "Logos provided by Logo.dev" credit. /me exposes the
publishable logo.dev key for this (it's already part of every public
logo URL).

Also fixes the sticky phone preview on the content and appearance
tabs, which scrolled away because its column was only as tall as the
phone itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 17:00:28 +02:00
co-authored by Claude Opus 5.5
parent 3eea5c23ef
commit ab2150330a
5 changed files with 63 additions and 9 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ export function apiRoutes(deps: Deps) {
.get("/me", (c) => {
const { username, isAdmin } = c.var.actor;
return c.json({ username, isAdmin, logoDev: !!config.logoDevToken } satisfies Me);
return c.json({ username, isAdmin, logoDev: !!config.logoDevToken, logoDevToken: config.logoDevToken ?? null } satisfies Me);
})
// Pages (redirects and link pages)
+2
View File
@@ -8,6 +8,8 @@ export interface Me {
isAdmin: boolean;
/** Whether the server has a logo.dev token, i.e. link pages can show website logos. */
logoDev: boolean;
/** Publishable logo.dev key (it's part of every public logo URL), used for the editor preview. */
logoDevToken: string | null;
}
export interface PageSummary {
+57 -6
View File
@@ -11,18 +11,62 @@ import { stripMarkdown } from "../../lib/markdown.js";
import { PhoneFrame } from "./PhonePreview.js";
import { sameTheme, ThemePicker } from "./ThemePicker.js";
// Button icon like on the public page: the website's logo when logos are on, otherwise its first letter.
function MockIcon({ dest, logoDevToken }: { dest: string | null; logoDevToken: string | null }) {
const [failed, setFailed] = useState(false);
let host = "";
try {
host = dest ? new URL(dest).hostname : "";
} catch {
// Keep the letter placeholder.
}
if (host && logoDevToken && !failed) {
return (
<img
src={`https://img.logo.dev/${encodeURIComponent(host)}?token=${encodeURIComponent(logoDevToken)}`}
alt=""
onError={() => setFailed(true)}
className="size-7 shrink-0 rounded-full bg-white/85 object-cover"
/>
);
}
return (
<span className="flex size-7 shrink-0 items-center justify-center rounded-full bg-white/85 text-xs font-bold text-gray-700">
{host.replace(/^www\./, "").charAt(0).toUpperCase() || "•"}
</span>
);
}
// Renders the page with unsaved settings so changes are visible while editing.
function MockPreview({ title, avatarUrl, theme, page }: { title: string; avatarUrl: string | null; theme: Theme; page: PageDetail }) {
function MockPreview({
title,
avatarUrl,
theme,
page,
logoDevToken,
}: {
title: string;
avatarUrl: string | null;
theme: Theme;
page: PageDetail;
/** Set when logos are enabled for this page. */
logoDevToken: string | null;
}) {
return (
<PhoneFrame caption="Preview of unsaved changes">
<div className="absolute inset-0 overflow-y-auto px-5 py-10 text-center" style={{ background: theme.background, color: theme.text }}>
<div className="absolute inset-0 flex flex-col overflow-y-auto px-5 pt-10 pb-5 text-center" style={{ background: theme.background, color: theme.text }}>
{avatarUrl && <img src={avatarUrl} alt="" className="mx-auto size-20 rounded-full object-cover" />}
<div className="mt-4 mb-6 text-xl font-bold">{title || "Untitled"}</div>
<div className="flex flex-col gap-2.5">
{page.blocks.map((b) =>
b.kind === "link" ? (
<div key={b.id} className="rounded-lg px-3 py-2.5 text-sm font-semibold" style={{ background: theme.button, color: theme.buttonText }}>
{b.label}
<div
key={b.id}
className="flex items-center gap-2 rounded-lg px-2 py-1.5 text-sm font-semibold"
style={{ background: theme.button, color: theme.buttonText }}
>
<MockIcon dest={b.target?.dest ?? null} logoDevToken={logoDevToken} />
<span className="flex-1 truncate pr-7">{b.label}</span>
</div>
) : (
<p key={b.id} className="line-clamp-3 text-sm opacity-90">
@@ -33,6 +77,7 @@ function MockPreview({ title, avatarUrl, theme, page }: { title: string; avatarU
{!page.blocks.length &&
[0, 1, 2].map((i) => <div key={i} className="h-10 rounded-lg opacity-60" style={{ background: theme.button }} />)}
</div>
{logoDevToken && <p className="mt-auto pt-8 text-[11px] opacity-50">Logos provided by Logo.dev</p>}
</div>
</PhoneFrame>
);
@@ -153,8 +198,14 @@ export function AppearanceTab({ page, me, onChange }: { page: PageDetail; me: Me
</Card>
</div>
<div className="hidden lg:block">
<MockPreview title={title} avatarUrl={page.avatarUrl} theme={theme} page={page} />
<div className="hidden lg:block lg:self-stretch">
<MockPreview
title={title}
avatarUrl={page.avatarUrl}
theme={theme}
page={page}
logoDevToken={me.logoDev && showLogos ? me.logoDevToken : null}
/>
</div>
</div>
);
+1 -1
View File
@@ -355,7 +355,7 @@ export function ContentTab({ page, me, onChange }: { page: PageDetail; me: Me; o
)}
</Card>
<div className="hidden lg:block">
<div className="hidden lg:block lg:self-stretch">
<LivePreview path={page.path} version={version} />
</div>
+2 -1
View File
@@ -46,7 +46,7 @@ describe("authentication", () => {
expect(callback.status).toBe(302);
const session = callback.headers.getSetCookie().find((c) => c.startsWith("short_session="))!.split(";")[0]!;
const me = await (await app.request("/~/api/me", { headers: { cookie: session } })).json();
expect(me).toEqual({ username: "alice", isAdmin: true, logoDev: false });
expect(me).toEqual({ username: "alice", isAdmin: true, logoDev: false, logoDevToken: null });
// A renamed account keeps its original namespace; losing the group removes admin.
const login2 = await app.request("/~/auth/login");
@@ -59,6 +59,7 @@ describe("authentication", () => {
username: "alice",
isAdmin: false,
logoDev: false,
logoDevToken: null,
});
});