mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
108 lines
3.2 KiB
Plaintext
108 lines
3.2 KiB
Plaintext
---
|
|
import { SITE } from "src/config";
|
|
import "../styles/base.css";
|
|
|
|
export interface Props {
|
|
title?: string;
|
|
author?: string;
|
|
description?: string;
|
|
ogImage?: string;
|
|
}
|
|
|
|
const {
|
|
title = SITE.title,
|
|
author = SITE.author,
|
|
description = SITE.desc,
|
|
ogImage = SITE.ogImage,
|
|
} = Astro.props;
|
|
|
|
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
|
|
const socialImageURL = new URL(
|
|
ogImage ? ogImage : SITE.ogImage,
|
|
Astro.url.origin
|
|
);
|
|
---
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<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} />
|
|
|
|
<!-- 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} />
|
|
|
|
<!-- 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 Font -->
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
<link
|
|
rel="preload"
|
|
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"
|
|
as="style"
|
|
onload="this.onload=null;this.rel='stylesheet'"
|
|
/>
|
|
|
|
<script is:inline>
|
|
const primaryColorScheme = "none"; // "light" | "dark" | "none"
|
|
|
|
const darkModeMediaQuery = window.matchMedia(
|
|
"(prefers-color-scheme: dark)"
|
|
).matches;
|
|
|
|
// Get theme data from local storage
|
|
const currentTheme = localStorage.getItem("theme");
|
|
|
|
let theme;
|
|
|
|
// Set theme to 'theme-dark' if currentTheme is 'dark'
|
|
if (currentTheme) {
|
|
theme = currentTheme === "dark" ? "theme-dark" : "";
|
|
} else {
|
|
// If primary color scheme is dark
|
|
// or primary color scheme is not set and prefers-color-scheme is dark
|
|
// choose dark mode
|
|
if (
|
|
primaryColorScheme === "dark" ||
|
|
(primaryColorScheme === "none" && darkModeMediaQuery)
|
|
) {
|
|
theme = "theme-dark";
|
|
}
|
|
// If primary color scheme is light
|
|
// choose light mode
|
|
else if (primaryColorScheme === "light") {
|
|
theme = "";
|
|
}
|
|
// fallback to prefers-color-scheme
|
|
else {
|
|
theme = darkModeMediaQuery ? "theme-dark" : "";
|
|
}
|
|
}
|
|
|
|
// Put dark class on html tag to enable dark mode
|
|
document.querySelector("html").className = theme;
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<slot />
|
|
</body>
|
|
</html>
|