85 lines
3.2 KiB
TypeScript
85 lines
3.2 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Script from "next/script";
|
|
import { AppShell } from "@/components/layout/AppShell";
|
|
import { getRequestOrigin, OG_DEFAULT_IMAGE, SITE_NAME } from "@/lib/seo";
|
|
import "./globals.css";
|
|
|
|
export const instant = false;
|
|
|
|
const GTM_ID = process.env.NEXT_PUBLIC_GTM_ID?.trim() || "";
|
|
const YANDEX_METRIKA_ID = process.env.NEXT_PUBLIC_YANDEX_METRIKA_ID?.trim() || "";
|
|
|
|
/** metadataBase 随请求 Host 变化,保证 og:image 为绝对地址 */
|
|
export async function generateMetadata(): Promise<Metadata> {
|
|
const origin = await getRequestOrigin();
|
|
return {
|
|
metadataBase: new URL(origin),
|
|
title: {
|
|
default: "黄果短剧",
|
|
template: "%s",
|
|
},
|
|
description: "黄果短剧,发现值得一看的短剧。",
|
|
applicationName: SITE_NAME,
|
|
openGraph: {
|
|
type: "website",
|
|
locale: "zh_CN",
|
|
siteName: SITE_NAME,
|
|
images: [{ url: OG_DEFAULT_IMAGE, alt: SITE_NAME, width: 700, height: 400 }],
|
|
},
|
|
twitter: {
|
|
card: "summary_large_image",
|
|
images: [OG_DEFAULT_IMAGE],
|
|
},
|
|
icons: { icon: "/favicon.png" },
|
|
verification: {
|
|
yandex: "2cd6a987a1bb3b58",
|
|
other: {
|
|
"msvalidate.01": "431F89B229D3A00661DAF708E5C24BC0",
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
return (
|
|
<html lang="zh-CN" className="dark" data-theme="dark" data-scroll-behavior="smooth">
|
|
<body>
|
|
<AppShell>{children}</AppShell>
|
|
{GTM_ID ? (
|
|
<>
|
|
<Script id="gtm-init" strategy="afterInteractive">
|
|
{`
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(){dataLayer.push(arguments);}
|
|
gtag('js', new Date());
|
|
dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
|
|
`}
|
|
</Script>
|
|
<Script id="gtm-tag" src={`https://www.googletagmanager.com/gtm.js?id=${GTM_ID}`} strategy="afterInteractive" />
|
|
</>
|
|
) : null}
|
|
{YANDEX_METRIKA_ID ? (
|
|
<>
|
|
<Script id="yandex-metrika" strategy="afterInteractive">
|
|
{`
|
|
(function(m,e,t,r,i,k,a){
|
|
m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
|
m[i].l=1*new Date();
|
|
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
|
|
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
|
|
})(window, document, 'script', 'https://mc.yandex.ru/metrika/tag.js?id=${YANDEX_METRIKA_ID}', 'ym');
|
|
ym(${YANDEX_METRIKA_ID}, 'init', {ssr:true, webvisor:true, clickmap:true, ecommerce:"dataLayer", referrer: document.referrer, url: location.href, accurateTrackBounce:true, trackLinks:true});
|
|
`}
|
|
</Script>
|
|
<noscript>
|
|
<div>
|
|
<img src={`https://mc.yandex.ru/watch/${YANDEX_METRIKA_ID}`} style={{ position: "absolute", left: "-9999px" }} alt="" />
|
|
</div>
|
|
</noscript>
|
|
</>
|
|
) : null}
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|