Skip to content

Commit 04cf458

Browse files
committed
fix: 修复 themeColor 被放置错误配置中的问题
1 parent 3fe9fe7 commit 04cf458

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

apps/web/src/app/layout.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import "server-only";
33

44
import { Suspense } from "react";
5+
import type { Viewport } from "next";
56
import { cacheLife, cacheTag } from "next/cache";
67
// Fonts
78
import { Inter } from "next/font/google";
@@ -22,9 +23,10 @@ import Footer from "@/components/server/layout/Footer";
2223
// Server Componments
2324
import Header from "@/components/server/layout/Header";
2425
import { ConfigProvider } from "@/context/ConfigContext";
25-
import { getConfigs } from "@/lib/server/config-cache";
26+
import { getConfig, getConfigs } from "@/lib/server/config-cache";
2627
// lib
2728
import { getActiveMenusForClient } from "@/lib/server/menu-cache";
29+
import { normalizeSiteColorConfig } from "@/lib/shared/site-color";
2830
// Types
2931
import { ToastProvider } from "@/ui/Toast";
3032

@@ -39,6 +41,25 @@ const ibmPlexMono = IBM_Plex_Mono({
3941
variable: "--font-mono",
4042
});
4143

44+
export async function generateViewport(): Promise<Viewport> {
45+
const siteColor = await getConfig("site.color");
46+
const normalizedColor = normalizeSiteColorConfig(siteColor);
47+
48+
return {
49+
colorScheme: "light dark",
50+
themeColor: [
51+
{
52+
media: "(prefers-color-scheme: light)",
53+
color: normalizedColor.light.primary,
54+
},
55+
{
56+
media: "(prefers-color-scheme: dark)",
57+
color: normalizedColor.dark.primary,
58+
},
59+
],
60+
};
61+
}
62+
4263
export default async function RootLayout({
4364
children,
4465
modal,

apps/web/src/lib/server/seo.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { unstable_cache } from "next/cache";
55
import { findCategoryByPath } from "@/lib/server/category-utils";
66
import { getRawConfig } from "@/lib/server/config-cache";
77
import prisma from "@/lib/server/prisma";
8-
import { normalizeSiteColorConfig } from "@/lib/shared/site-color";
98

109
// 基础静态配置(不依赖数据库的固定值)
1110
const STATIC_METADATA = {
@@ -79,7 +78,6 @@ const seoConfigMap = {
7978
applicationName: "site.title",
8079
keywords: "seo.keywords",
8180
author: "author.name",
82-
themeColor: "site.color",
8381
twitterSite: "seo.twitter_site",
8482
twitterCreator: "seo.twitter_creator",
8583
googleVerification: "seo.google_verification",
@@ -434,9 +432,6 @@ export async function generateMetadata(
434432
true,
435433
);
436434

437-
const siteColor = normalizeSiteColorConfig(
438-
configValues[seoConfigMap.themeColor]?.default,
439-
);
440435
const metadataBase = parseMetadataBase(url);
441436
const normalizedPathname = normalizePathname(options?.pathname);
442437
const openGraphUrl = buildOpenGraphUrl(metadataBase, normalizedPathname);
@@ -517,16 +512,6 @@ export async function generateMetadata(
517512
description: description || undefined,
518513
applicationName: appName || title || undefined,
519514
...STATIC_METADATA,
520-
themeColor: [
521-
{
522-
media: "(prefers-color-scheme: light)",
523-
color: siteColor.light.primary,
524-
},
525-
{
526-
media: "(prefers-color-scheme: dark)",
527-
color: siteColor.dark.primary,
528-
},
529-
],
530515
authors: author ? [{ name: author }] : undefined,
531516
creator: author || undefined,
532517
publisher: author || undefined,

0 commit comments

Comments
 (0)