Merge pull request #1492 from Yidadaa/bugfix-0514

fix: #1444 async load google fonts
This commit is contained in:
Yifei Zhang 2023-05-14 23:29:01 +08:00 committed by GitHub
commit b5b8593e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -23,7 +23,6 @@ import {
} from "react-router-dom"; } from "react-router-dom";
import { SideBar } from "./sidebar"; import { SideBar } from "./sidebar";
import { useAppConfig } from "../store/config"; import { useAppConfig } from "../store/config";
import { useMaskStore } from "../store/mask";
export function Loading(props: { noLogo?: boolean }) { export function Loading(props: { noLogo?: boolean }) {
return ( return (
@ -91,12 +90,24 @@ const useHasHydrated = () => {
return hasHydrated; return hasHydrated;
}; };
const loadAsyncGoogleFont = () => {
const linkEl = document.createElement("link");
linkEl.rel = "stylesheet";
linkEl.href =
"/google-fonts/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap";
document.head.appendChild(linkEl);
};
function Screen() { function Screen() {
const config = useAppConfig(); const config = useAppConfig();
const location = useLocation(); const location = useLocation();
const isHome = location.pathname === Path.Home; const isHome = location.pathname === Path.Home;
const isMobileScreen = useMobileScreen(); const isMobileScreen = useMobileScreen();
useEffect(() => {
loadAsyncGoogleFont();
}, []);
return ( return (
<div <div
className={ className={

View File

@ -34,11 +34,6 @@ export default function RootLayout({
<head> <head>
<meta name="version" content={buildConfig.commitId} /> <meta name="version" content={buildConfig.commitId} />
<link rel="manifest" href="/site.webmanifest"></link> <link rel="manifest" href="/site.webmanifest"></link>
<link rel="preconnect" href="https://fonts.proxy.ustclug.org"></link>
<link
rel="stylesheet"
href="https://fonts.proxy.ustclug.org/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap"
></link>
<script src="/serviceWorkerRegister.js" defer></script> <script src="/serviceWorkerRegister.js" defer></script>
</head> </head>
<body>{children}</body> <body>{children}</body>

View File

@ -10,6 +10,10 @@ const nextConfig = {
source: "/api/proxy/:path*", source: "/api/proxy/:path*",
destination: "https://api.openai.com/:path*", destination: "https://api.openai.com/:path*",
}, },
{
source: "/google-fonts/:path*",
destination: "https://fonts.googleapis.com/:path*",
},
]; ];
const apiUrl = process.env.API_URL; const apiUrl = process.env.API_URL;