-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(admin): use the configured Site Icon as the admin favicon #1505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7c540ab
1432258
4a0c7e6
6eb89fe
0c5de8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "emdash": patch | ||
| --- | ||
|
|
||
| The admin shell now falls back to the Site Icon configured in Settings → General for its favicon, so the EmDash backend is branded like the public site. An explicit build-time `admin.favicon` still takes precedence, and the default EmDash mark is used when neither is set. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { Font } from "astro:assets"; | |
| export const prerender = false; | ||
|
|
||
| import { resolveLocale, loadMessages, getLocaleDir } from "@emdash-cms/admin/locales"; | ||
| import { getSiteSettingsWithDb } from "#settings/index.js"; | ||
|
|
||
| const resolvedLocale = resolveLocale(Astro.request); | ||
| const resolvedDir = getLocaleDir(resolvedLocale); | ||
|
|
@@ -33,6 +34,29 @@ const pageTitle = adminConfig?.siteName ? `${adminConfig.siteName} Admin` : "EmD | |
| // via cookie/Accept-Language). API routes already send `private, no-store` | ||
| // (API_CACHE_HEADERS); this closes the same gap for the admin HTML. | ||
| Astro.response.headers.set("Cache-Control", "private, no-store"); | ||
|
|
||
| // Favicon precedence: an explicit build-time `admin.favicon` is admin-specific | ||
| // and always wins — in that case the settings read is skipped entirely. | ||
| // Otherwise fall back to the Site Icon configured in Settings → General, so | ||
| // the admin shell is branded like the public site (WordPress-style Site Icon, | ||
| // which also brands wp-admin), and finally the bundled EmDash mark below. | ||
| const emdash = Astro.locals.emdash; | ||
| let siteFavicon: string | undefined; | ||
| let siteFaviconType: string | undefined; | ||
| if (!adminConfig?.favicon && emdash?.db) { | ||
| try { | ||
| const settings = await getSiteSettingsWithDb(emdash.db, emdash.storage ?? null); | ||
| siteFavicon = settings.favicon?.url ?? undefined; | ||
| siteFaviconType = settings.favicon?.contentType ?? undefined; | ||
| } catch { | ||
| // Settings unavailable (e.g. pre-setup) — fall back to the config/default. | ||
| } | ||
| } | ||
| const favicon = adminConfig?.favicon ?? siteFavicon; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we're defaulting to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — the settings read is now skipped entirely when an explicit |
||
| // The media-file URL has no extension, so browsers need the MIME type — | ||
| // Chromium ignores SVG favicons without type="image/svg+xml". Only set for | ||
| // Site Icons; build-time `admin.favicon` strings keep their current behavior. | ||
| const faviconType = adminConfig?.favicon ? undefined : siteFaviconType; | ||
| --- | ||
|
|
||
| <!doctype html> | ||
|
|
@@ -42,8 +66,8 @@ Astro.response.headers.set("Cache-Control", "private, no-store"); | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="stylesheet" href={adminStylesUrl} /> | ||
| <Font cssVariable="--font-emdash" /> | ||
| {adminConfig?.favicon ? ( | ||
| <link rel="icon" href={adminConfig.favicon} /> | ||
| {favicon ? ( | ||
| <link rel="icon" href={favicon} type={faviconType} /> | ||
| ) : ( | ||
| <link | ||
| rel="icon" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion] AGENTS.md asks that bug fixes ship with a reproducing test, and the e2e suite already exercises the admin shell (see
e2e/tests/admin-fixes.spec.ts). Consider adding an assertion that visits/_emdash/adminand checkslink[rel="icon"]— ideally after setting a Site Icon through the settings API — to guard both the precedence ordering and anytype-attribute fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 6eb89fe — new e2e case in
admin-fixes.spec.ts: uploads an SVG via the media API, sets it as the Site Icon throughPOST /_emdash/api/settings, then loads/_emdash/adminand assertslink[rel="icon"]points at the media-file URL withtype="image/svg+xml". Verified green locally.