mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
8fbb0b4d85
- Add author profile to SITE variables - Add JSON-LD to Layout.astro
140 lines
3.7 KiB
Plaintext
140 lines
3.7 KiB
Plaintext
---
|
|
import { LOCALE, SITE } from "@config";
|
|
import "@styles/base.css";
|
|
import { ViewTransitions } from "astro:transitions";
|
|
|
|
const googleSiteVerification = import.meta.env.PUBLIC_GOOGLE_SITE_VERIFICATION;
|
|
|
|
export interface Props {
|
|
title?: string;
|
|
author?: string;
|
|
profile?: string;
|
|
description?: string;
|
|
ogImage?: string;
|
|
canonicalURL?: string;
|
|
pubDatetime?: Date;
|
|
modDatetime?: Date | null;
|
|
scrollSmooth?: boolean;
|
|
}
|
|
|
|
const {
|
|
title = SITE.title,
|
|
author = SITE.author,
|
|
profile = SITE.profile,
|
|
description = SITE.desc,
|
|
ogImage = SITE.ogImage,
|
|
canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
|
|
pubDatetime,
|
|
modDatetime,
|
|
scrollSmooth = false,
|
|
} = Astro.props;
|
|
|
|
const socialImageURL = new URL(
|
|
ogImage ?? SITE.ogImage ?? "og.png",
|
|
Astro.url.origin
|
|
).href;
|
|
|
|
const structuredData = {
|
|
"@context": "https://schema.org",
|
|
"@type": "BlogPosting",
|
|
headline: `${title}`,
|
|
image: `${socialImageURL}`,
|
|
datePublished: `${pubDatetime?.toISOString()}`,
|
|
...(modDatetime && { dateModified: modDatetime.toISOString() }),
|
|
author: [
|
|
{
|
|
"@type": "Person",
|
|
name: `${author}`,
|
|
url: `${profile}`,
|
|
},
|
|
],
|
|
};
|
|
---
|
|
|
|
<!doctype html>
|
|
<html
|
|
lang=`${LOCALE.lang ?? "en"}`
|
|
class={`${scrollSmooth && "scroll-smooth"}`}
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width" />
|
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
<link rel="canonical" href={canonicalURL} />
|
|
<meta name="generator" content={Astro.generator} />
|
|
|
|
<!-- General Meta Tags -->
|
|
<title>{title}</title>
|
|
<meta name="title" content={title} />
|
|
<meta name="description" content={description} />
|
|
<meta name="author" content={author} />
|
|
<link rel="sitemap" href="/sitemap-index.xml" />
|
|
|
|
<!-- Open Graph / Facebook -->
|
|
<meta property="og:title" content={title} />
|
|
<meta property="og:description" content={description} />
|
|
<meta property="og:url" content={canonicalURL} />
|
|
<meta property="og:image" content={socialImageURL} />
|
|
|
|
<!-- Article Published/Modified time -->
|
|
{
|
|
pubDatetime && (
|
|
<meta
|
|
property="article:published_time"
|
|
content={pubDatetime.toISOString()}
|
|
/>
|
|
)
|
|
}
|
|
{
|
|
modDatetime && (
|
|
<meta
|
|
property="article:modified_time"
|
|
content={modDatetime.toISOString()}
|
|
/>
|
|
)
|
|
}
|
|
|
|
<!-- Twitter -->
|
|
<meta property="twitter:card" content="summary_large_image" />
|
|
<meta property="twitter:url" content={canonicalURL} />
|
|
<meta property="twitter:title" content={title} />
|
|
<meta property="twitter:description" content={description} />
|
|
<meta property="twitter:image" content={socialImageURL} />
|
|
|
|
<!-- Google JSON-LD Structured data -->
|
|
<script
|
|
type="application/ld+json"
|
|
set:html={JSON.stringify(structuredData)}
|
|
/>
|
|
|
|
<!-- Google Font -->
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
<link
|
|
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400;1,600&display=swap"
|
|
rel="stylesheet"
|
|
/>
|
|
|
|
<meta name="theme-color" content="" />
|
|
|
|
{
|
|
// If PUBLIC_GOOGLE_SITE_VERIFICATION is set in the environment variable,
|
|
// include google-site-verification tag in the heading
|
|
// Learn more: https://support.google.com/webmasters/answer/9008080#meta_tag_verification&zippy=%2Chtml-tag
|
|
googleSiteVerification && (
|
|
<meta
|
|
name="google-site-verification"
|
|
content={googleSiteVerification}
|
|
/>
|
|
)
|
|
}
|
|
|
|
<ViewTransitions />
|
|
|
|
<script is:inline src="/toggle-theme.js"></script>
|
|
</head>
|
|
<body>
|
|
<slot />
|
|
</body>
|
|
</html>
|