Browse Source

fix:链接显示预览图

XianCH 4 months ago
parent
commit
f1502a62ad
1 changed files with 41 additions and 1 deletions
  1. 41 1
      src/app/[locale]/layout.tsx

+ 41 - 1
src/app/[locale]/layout.tsx

@@ -8,6 +8,8 @@ import { notFound } from "next/navigation";
 import { ReactNode } from "react";
 import "../globals.scss";
 import { Providers } from "./providers";
+import { server } from "@/utils/server";
+import { ConfigType } from "@/api/config";
 
 // 加载字体
 const fontSans = FontSans({
@@ -37,10 +39,27 @@ export const metadata: Metadata = {
     other: {
         viewport: [
             "width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0," +
-                " viewport-fit=cover ",
+            " viewport-fit=cover ",
         ],
     },
 };
+
+interface Og {
+    description: string;
+    keywords: string;
+    title: string;
+    url: string;
+    address: string
+}
+interface System extends ConfigType {
+    og: Og
+}
+const getSystemReq = () => {
+    return server.request<System>({
+        url: '/v1/api/front/system/configs',
+        method: 'POST'
+    })
+}
 export default async function LocaleLayout({
     children,
     params: { locale },
@@ -53,8 +72,29 @@ export default async function LocaleLayout({
     }
     const messages = await getMessages();
 
+    const { data } = await getSystemReq()
     return (
         <html lang={locale} suppressHydrationWarning>
+            <head>
+                {/* <!-- SEO Metadata --> */}
+                {/* <meta name="description" content="{{ .Description }}" />
+                <meta name="keywords" content="{{ .Keywords }}" />
+                <meta name="author" content="Besoft" />
+                <meta name="viewport" content="width=device-width, initial-scale=1.0" /> */}
+
+                {/* <!-- Open Graph Metadata --> */}
+                <meta property="og:title" content={data.og.title} />
+                <meta property="og:description" content={data.og.description} />
+                <meta property="og:image" content={data.og.url} />
+                <meta property="og:url" content={data.og.address} />
+                <meta property="og:type" content="website" />
+
+                {/* <!-- Twitter Card Metadata --> */}
+                <meta name="twitter:card" content={data.og.address} />
+                <meta name="twitter:title" content={data.og.title} />
+                <meta name="twitter:description" content={data.og.description} />
+                <meta name="twitter:image" content={data.og.url} />
+            </head>
             <body className={clsx("font-sans", fontSans.variable)}>
                 <NextIntlClientProvider messages={messages}>
                     <Providers themeProps={{ attribute: "class" }}>{children}</Providers>