SITE_TITLE per Docker-Variable, Favicon im Admin-Bereich austauschbar
- SITE_TITLE (Default "Canteen Menu") steuert Browser-Tab-Titel und H1-Fallback ohne Logo - Favicon-Upload analog zum Logo über den Design-Bereich (Storage- Bucket branding); generateMetadata setzt icons.icon jetzt immer explizit, da Next.js sonst app/favicon.ico zusätzlich einbindet – die Datei liegt daher als expliziter Fallback unter public/
This commit is contained in:
@@ -16,3 +16,6 @@ SUPABASE_SERVICE_ROLE_KEY=<service-role-key>
|
|||||||
# SUPABASE_ACCESS_TOKEN=<token> node scripts/configure-passkeys.mjs
|
# SUPABASE_ACCESS_TOKEN=<token> node scripts/configure-passkeys.mjs
|
||||||
# ausführen, damit Passkeys auf der neuen Domain funktionieren.
|
# ausführen, damit Passkeys auf der neuen Domain funktionieren.
|
||||||
APP_URL=http://localhost:3000
|
APP_URL=http://localhost:3000
|
||||||
|
|
||||||
|
# Titel im Browser-Tab und Überschrift, solange kein Logo hochgeladen ist.
|
||||||
|
SITE_TITLE=Canteen Menu
|
||||||
|
|||||||
+19
-6
@@ -2,10 +2,10 @@ import type { Metadata } from "next";
|
|||||||
import { Geist } from "next/font/google";
|
import { Geist } from "next/font/google";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import { createClient } from "@/lib/supabase/server";
|
import { createClient } from "@/lib/supabase/server";
|
||||||
import { COLOR_VARS, DEFAULT_COLORS } from "@/lib/types";
|
import { COLOR_VARS, DEFAULT_COLORS, faviconUrl, SITE_TITLE } from "@/lib/types";
|
||||||
import packageJson from "@/package.json";
|
import packageJson from "@/package.json";
|
||||||
|
|
||||||
// Farben/Logo sollen Änderungen sofort widerspiegeln.
|
// Farben/Logo/Favicon sollen Änderungen sofort widerspiegeln.
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
const geistSans = Geist({
|
const geistSans = Geist({
|
||||||
@@ -13,10 +13,23 @@ const geistSans = Geist({
|
|||||||
subsets: ["latin"],
|
subsets: ["latin"],
|
||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
title: "Canteen Menu",
|
const supabase = await createClient();
|
||||||
description: "Speisekarte der Betriebskantine",
|
const { data: settings } = await supabase
|
||||||
};
|
.from("settings")
|
||||||
|
.select("favicon_path")
|
||||||
|
.eq("id", 1)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: SITE_TITLE,
|
||||||
|
description: "Speisekarte der Betriebskantine",
|
||||||
|
// Immer explizit setzen: app/favicon.ico würde sonst zusätzlich zu
|
||||||
|
// einem eigenen Favicon eingebunden (Next.js kombiniert Datei-
|
||||||
|
// Konvention und Metadata statt sie zu ersetzen).
|
||||||
|
icons: { icon: faviconUrl(settings?.favicon_path) ?? "/favicon.ico" },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default async function RootLayout({
|
export default async function RootLayout({
|
||||||
children,
|
children,
|
||||||
|
|||||||
+80
-21
@@ -3,13 +3,21 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { createClient } from "@/lib/supabase/client";
|
import { createClient } from "@/lib/supabase/client";
|
||||||
import { COLOR_LABELS, DEFAULT_COLORS, logoUrl } from "@/lib/types";
|
import { COLOR_LABELS, DEFAULT_COLORS, faviconUrl, logoUrl } from "@/lib/types";
|
||||||
|
|
||||||
|
type AssetKind = "logo" | "favicon";
|
||||||
|
|
||||||
|
const ASSET_COLUMN: Record<AssetKind, "logo_path" | "favicon_path"> = {
|
||||||
|
logo: "logo_path",
|
||||||
|
favicon: "favicon_path",
|
||||||
|
};
|
||||||
|
|
||||||
export default function DesignEditor() {
|
export default function DesignEditor() {
|
||||||
const supabase = useMemo(() => createClient(), []);
|
const supabase = useMemo(() => createClient(), []);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [colors, setColors] = useState<Record<string, string>>(DEFAULT_COLORS);
|
const [colors, setColors] = useState<Record<string, string>>(DEFAULT_COLORS);
|
||||||
const [logoPath, setLogoPath] = useState<string | null>(null);
|
const [logoPath, setLogoPath] = useState<string | null>(null);
|
||||||
|
const [faviconPath, setFaviconPath] = useState<string | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [info, setInfo] = useState<string | null>(null);
|
const [info, setInfo] = useState<string | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
@@ -17,7 +25,7 @@ export default function DesignEditor() {
|
|||||||
const load = useCallback(async () => {
|
const load = useCallback(async () => {
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from("settings")
|
.from("settings")
|
||||||
.select("colors, logo_path")
|
.select("colors, logo_path, favicon_path")
|
||||||
.eq("id", 1)
|
.eq("id", 1)
|
||||||
.maybeSingle();
|
.maybeSingle();
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -26,6 +34,7 @@ export default function DesignEditor() {
|
|||||||
}
|
}
|
||||||
setColors({ ...DEFAULT_COLORS, ...(data?.colors ?? {}) });
|
setColors({ ...DEFAULT_COLORS, ...(data?.colors ?? {}) });
|
||||||
setLogoPath(data?.logo_path ?? null);
|
setLogoPath(data?.logo_path ?? null);
|
||||||
|
setFaviconPath(data?.favicon_path ?? null);
|
||||||
}, [supabase]);
|
}, [supabase]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -52,20 +61,21 @@ export default function DesignEditor() {
|
|||||||
setColors(DEFAULT_COLORS);
|
setColors(DEFAULT_COLORS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadLogo(e: React.ChangeEvent<HTMLInputElement>) {
|
async function uploadAsset(kind: AssetKind, e: React.ChangeEvent<HTMLInputElement>) {
|
||||||
const file = e.target.files?.[0];
|
const file = e.target.files?.[0];
|
||||||
e.target.value = "";
|
e.target.value = "";
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
if (!/^image\//.test(file.type)) {
|
if (!/^image\//.test(file.type)) {
|
||||||
setError("Bitte eine Bilddatei auswählen (PNG, JPG, SVG, WebP).");
|
setError("Bitte eine Bilddatei auswählen (PNG, JPG, SVG, WebP, ICO).");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
setInfo(null);
|
setInfo(null);
|
||||||
|
|
||||||
|
const oldPath = kind === "logo" ? logoPath : faviconPath;
|
||||||
const ext = file.name.split(".").pop()?.toLowerCase() ?? "png";
|
const ext = file.name.split(".").pop()?.toLowerCase() ?? "png";
|
||||||
const path = `logo-${Date.now()}.${ext}`;
|
const path = `${kind}-${Date.now()}.${ext}`;
|
||||||
const { error: uploadError } = await supabase.storage
|
const { error: uploadError } = await supabase.storage
|
||||||
.from("branding")
|
.from("branding")
|
||||||
.upload(path, file, { contentType: file.type });
|
.upload(path, file, { contentType: file.type });
|
||||||
@@ -75,46 +85,53 @@ export default function DesignEditor() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldPath = logoPath;
|
|
||||||
const { error: settingsError } = await supabase
|
const { error: settingsError } = await supabase
|
||||||
.from("settings")
|
.from("settings")
|
||||||
.update({ logo_path: path })
|
.update({ [ASSET_COLUMN[kind]]: path })
|
||||||
.eq("id", 1);
|
.eq("id", 1);
|
||||||
if (settingsError) {
|
if (settingsError) {
|
||||||
setError(`Speichern fehlgeschlagen: ${settingsError.message}`);
|
setError(`Speichern fehlgeschlagen: ${settingsError.message}`);
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (oldPath) {
|
if (oldPath) await supabase.storage.from("branding").remove([oldPath]);
|
||||||
await supabase.storage.from("branding").remove([oldPath]);
|
|
||||||
}
|
if (kind === "logo") setLogoPath(path);
|
||||||
setLogoPath(path);
|
else setFaviconPath(path);
|
||||||
setInfo("Logo aktualisiert.");
|
setInfo(kind === "logo" ? "Logo aktualisiert." : "Favicon aktualisiert.");
|
||||||
router.refresh();
|
router.refresh();
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeLogo() {
|
async function removeAsset(kind: AssetKind) {
|
||||||
if (!logoPath) return;
|
const path = kind === "logo" ? logoPath : faviconPath;
|
||||||
if (!window.confirm("Logo wirklich entfernen?")) return;
|
if (!path) return;
|
||||||
|
if (
|
||||||
|
!window.confirm(
|
||||||
|
`${kind === "logo" ? "Logo" : "Favicon"} wirklich entfernen?`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return;
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from("settings")
|
.from("settings")
|
||||||
.update({ logo_path: null })
|
.update({ [ASSET_COLUMN[kind]]: null })
|
||||||
.eq("id", 1);
|
.eq("id", 1);
|
||||||
if (error) {
|
if (error) {
|
||||||
setError(`Speichern fehlgeschlagen: ${error.message}`);
|
setError(`Speichern fehlgeschlagen: ${error.message}`);
|
||||||
} else {
|
} else {
|
||||||
await supabase.storage.from("branding").remove([logoPath]);
|
await supabase.storage.from("branding").remove([path]);
|
||||||
setLogoPath(null);
|
if (kind === "logo") setLogoPath(null);
|
||||||
setInfo("Logo entfernt.");
|
else setFaviconPath(null);
|
||||||
|
setInfo(kind === "logo" ? "Logo entfernt." : "Favicon entfernt.");
|
||||||
router.refresh();
|
router.refresh();
|
||||||
}
|
}
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentLogo = logoUrl(logoPath);
|
const currentLogo = logoUrl(logoPath);
|
||||||
|
const currentFavicon = faviconUrl(faviconPath);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-3xl space-y-6">
|
<div className="max-w-3xl space-y-6">
|
||||||
@@ -149,7 +166,7 @@ export default function DesignEditor() {
|
|||||||
type="file"
|
type="file"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
className="hidden"
|
className="hidden"
|
||||||
onChange={uploadLogo}
|
onChange={(e) => uploadAsset("logo", e)}
|
||||||
disabled={busy}
|
disabled={busy}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
@@ -157,7 +174,7 @@ export default function DesignEditor() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-del"
|
className="btn btn-del"
|
||||||
onClick={removeLogo}
|
onClick={() => removeAsset("logo")}
|
||||||
disabled={busy}
|
disabled={busy}
|
||||||
>
|
>
|
||||||
Logo entfernen
|
Logo entfernen
|
||||||
@@ -166,6 +183,48 @@ export default function DesignEditor() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section className="card">
|
||||||
|
<h2 className="font-semibold mb-3">Favicon</h2>
|
||||||
|
<p className="text-sm text-gray-600 mb-3">
|
||||||
|
Wird als Icon im Browser-Tab angezeigt. Ohne eigenes Favicon gilt
|
||||||
|
das Standard-Icon der Anwendung.
|
||||||
|
</p>
|
||||||
|
{currentFavicon ? (
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
|
<img
|
||||||
|
src={currentFavicon}
|
||||||
|
alt="Aktuelles Favicon"
|
||||||
|
className="h-10 w-10 object-contain mb-3 border border-gray-200 rounded p-1"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-gray-400 mb-3">
|
||||||
|
Kein eigenes Favicon hinterlegt.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<div className="flex gap-2 items-center">
|
||||||
|
<label className="btn btn-primary cursor-pointer">
|
||||||
|
Favicon hochladen
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
className="hidden"
|
||||||
|
onChange={(e) => uploadAsset("favicon", e)}
|
||||||
|
disabled={busy}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
{currentFavicon && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-del"
|
||||||
|
onClick={() => removeAsset("favicon")}
|
||||||
|
disabled={busy}
|
||||||
|
>
|
||||||
|
Favicon entfernen
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section className="card">
|
<section className="card">
|
||||||
<h2 className="font-semibold mb-3">Farbgebung</h2>
|
<h2 className="font-semibold mb-3">Farbgebung</h2>
|
||||||
<div className="grid gap-3 sm:grid-cols-2">
|
<div className="grid gap-3 sm:grid-cols-2">
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ services:
|
|||||||
# Wird für den CSRF-Origin-Check genutzt; dieselbe URL ist die
|
# Wird für den CSRF-Origin-Check genutzt; dieselbe URL ist die
|
||||||
# Passkey-Domain (siehe scripts/configure-passkeys.mjs).
|
# Passkey-Domain (siehe scripts/configure-passkeys.mjs).
|
||||||
APP_URL: ${APP_URL:-http://localhost:3000}
|
APP_URL: ${APP_URL:-http://localhost:3000}
|
||||||
|
# Titel im Browser-Tab und Überschrift, solange kein Logo hochgeladen ist.
|
||||||
|
SITE_TITLE: ${SITE_TITLE:-Canteen Menu}
|
||||||
ports:
|
ports:
|
||||||
- "0.0.0.0:3000:3000"
|
- "0.0.0.0:3000:3000"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -68,6 +70,7 @@ services:
|
|||||||
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${NEXT_PUBLIC_SUPABASE_ANON_KEY}
|
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${NEXT_PUBLIC_SUPABASE_ANON_KEY}
|
||||||
SUPABASE_SERVICE_ROLE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
|
SUPABASE_SERVICE_ROLE_KEY: ${SUPABASE_SERVICE_ROLE_KEY}
|
||||||
APP_URL: ${APP_URL:-http://localhost:3000}
|
APP_URL: ${APP_URL:-http://localhost:3000}
|
||||||
|
SITE_TITLE: ${SITE_TITLE:-Canteen Menu}
|
||||||
ports:
|
ports:
|
||||||
- "0.0.0.0:3000:3000"
|
- "0.0.0.0:3000:3000"
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Reference in New Issue
Block a user