mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-26 07:30:18 +09:00
perf: adapting safari theme-color
This commit is contained in:
parent
e20e7da3f4
commit
2a81f1aea0
@ -59,37 +59,6 @@ const Plugins = dynamic(async () => (await import("./plugin")).PluginPage, {
|
|||||||
loading: () => <Loading noLogo />,
|
loading: () => <Loading noLogo />,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function useSwitchTheme() {
|
|
||||||
const config = useAppConfig();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
document.body.classList.remove("light");
|
|
||||||
document.body.classList.remove("dark");
|
|
||||||
|
|
||||||
if (config.theme === "dark") {
|
|
||||||
document.body.classList.add("dark");
|
|
||||||
} else if (config.theme === "light") {
|
|
||||||
document.body.classList.add("light");
|
|
||||||
}
|
|
||||||
|
|
||||||
const metaDescriptionDark = document.querySelector(
|
|
||||||
'meta[name="theme-color"][media*="dark"]',
|
|
||||||
);
|
|
||||||
const metaDescriptionLight = document.querySelector(
|
|
||||||
'meta[name="theme-color"][media*="light"]',
|
|
||||||
);
|
|
||||||
|
|
||||||
if (config.theme === "auto") {
|
|
||||||
metaDescriptionDark?.setAttribute("content", "#151515");
|
|
||||||
metaDescriptionLight?.setAttribute("content", "#fafafa");
|
|
||||||
} else {
|
|
||||||
const themeColor = getCSSVar("--theme-color");
|
|
||||||
metaDescriptionDark?.setAttribute("content", themeColor);
|
|
||||||
metaDescriptionLight?.setAttribute("content", themeColor);
|
|
||||||
}
|
|
||||||
}, [config.theme]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function useHtmlLang() {
|
function useHtmlLang() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const lang = getISOLang();
|
const lang = getISOLang();
|
||||||
@ -139,6 +108,42 @@ function Screen() {
|
|||||||
loadAsyncGoogleFont();
|
loadAsyncGoogleFont();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// SwitchThemeColor
|
||||||
|
// Adapting Safari's theme-color and changing it according to the path
|
||||||
|
useEffect(() => {
|
||||||
|
document.body.classList.remove("light");
|
||||||
|
document.body.classList.remove("dark");
|
||||||
|
|
||||||
|
if (config.theme === "dark") {
|
||||||
|
document.body.classList.add("dark");
|
||||||
|
} else if (config.theme === "light") {
|
||||||
|
document.body.classList.add("light");
|
||||||
|
}
|
||||||
|
|
||||||
|
const metaDescriptionDark = document.querySelector(
|
||||||
|
'meta[name="theme-color"][media*="dark"]',
|
||||||
|
);
|
||||||
|
const metaDescriptionLight = document.querySelector(
|
||||||
|
'meta[name="theme-color"][media*="light"]',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isHome) {
|
||||||
|
if (config.theme === "auto") {
|
||||||
|
const themeColor = getCSSVar("--theme-color");
|
||||||
|
metaDescriptionDark?.setAttribute("content", themeColor);
|
||||||
|
metaDescriptionLight?.setAttribute("content", themeColor);
|
||||||
|
} else {
|
||||||
|
const themeColor = getCSSVar("--theme-color");
|
||||||
|
metaDescriptionDark?.setAttribute("content", themeColor);
|
||||||
|
metaDescriptionLight?.setAttribute("content", themeColor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const themeColor = getCSSVar("--white");
|
||||||
|
metaDescriptionDark?.setAttribute("content", themeColor);
|
||||||
|
metaDescriptionLight?.setAttribute("content", themeColor);
|
||||||
|
}
|
||||||
|
}, [config.theme, isHome]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
@ -191,7 +196,6 @@ export function useLoadData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Home() {
|
export function Home() {
|
||||||
useSwitchTheme();
|
|
||||||
useLoadData();
|
useLoadData();
|
||||||
useHtmlLang();
|
useHtmlLang();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user