Add admin site settings sections and locale defaults

This commit is contained in:
MOH
2026-03-15 04:06:33 +01:00
parent 3e9edc5873
commit 5d3f77962a
21 changed files with 993 additions and 456 deletions
+9 -9
View File
@@ -11,7 +11,7 @@ import {
getSiteSettings,
getSiteSettingsMediaBindings,
} from "./app-config";
import { AppLocale, getLocalizedPath, resolveLocale } from "./locale";
import { AppLocale, getLocalizedPath, getLocalizedPathWithDefault, resolveLocale } from "./locale";
import { buildSiteIconUrls } from "./site-icons";
function getSiteUrl(): URL {
@@ -22,16 +22,16 @@ function toAbsoluteUrl(pathname: string): string {
return new URL(pathname, getSiteUrl()).toString();
}
export function buildLocaleAlternates(pathname: string) {
export function buildLocaleAlternates(pathname: string, defaultLocale = routing.defaultLocale) {
const languages = Object.fromEntries(
routing.locales.map((locale) => [locale, toAbsoluteUrl(getLocalizedPath(locale, pathname))]),
routing.locales.map((locale) => [locale, toAbsoluteUrl(getLocalizedPathWithDefault(locale, pathname, defaultLocale))]),
) as Record<AppLocale, string>;
return {
canonical: toAbsoluteUrl(getLocalizedPath(routing.defaultLocale, pathname)),
canonical: toAbsoluteUrl(getLocalizedPathWithDefault(defaultLocale, pathname, defaultLocale)),
languages: {
...languages,
"x-default": toAbsoluteUrl(getLocalizedPath(routing.defaultLocale, pathname)),
"x-default": toAbsoluteUrl(getLocalizedPathWithDefault(defaultLocale, pathname, defaultLocale)),
},
};
}
@@ -68,7 +68,7 @@ export function buildAppMetadataFromConfig(
settings: SiteSettings,
bindings: SiteSettingsMediaBindings,
): Metadata {
const defaultLocaleSettings = settings.locales[routing.defaultLocale];
const defaultLocaleSettings = settings.locales[settings.defaultLocale];
const openGraphImages = buildMetadataImages(bindings.defaultOgImage?.url);
const siteIconUrls = buildSiteIconUrls({
siteName: defaultLocaleSettings.siteName,
@@ -90,9 +90,9 @@ export function buildAppMetadataFromConfig(
openGraph: {
title: defaultLocaleSettings.siteName,
description: defaultLocaleSettings.siteDescription,
url: toAbsoluteUrl(getLocalizedPath(routing.defaultLocale, "/")),
url: toAbsoluteUrl(getLocalizedPathWithDefault(settings.defaultLocale, "/", settings.defaultLocale)),
siteName: defaultLocaleSettings.siteName,
locale: routing.defaultLocale,
locale: settings.defaultLocale,
type: "website",
images: openGraphImages,
},
@@ -163,7 +163,7 @@ export function buildLocalizedMetadataFromConfig(input: {
return {
title: resolvedTitle,
description: resolvedDescription,
alternates: buildLocaleAlternates(pathname),
alternates: buildLocaleAlternates(pathname, settings.defaultLocale),
openGraph: {
title: resolvedTitle,
description: resolvedDescription,