Repository navigation
Expand file tree
/
Copy pathSiteLayout.astro
More file actions
113 lines (110 loc) · 4.7 KB
/
Copy pathSiteLayout.astro
File metadata and controls
113 lines (110 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
import { seriesSlugs } from '../lib/posts';
import { shareImageFor } from '../lib/share-image';
import '../styles/global.css';
interface Props {
title?: string;
description?: string;
article?: boolean;
home?: boolean;
noindex?: boolean;
canonicalPath?: string;
post?: {
title: string;
date: string;
updated?: string;
series?: string;
tags?: string[];
image?: string;
};
}
const {
title = 'SpriCoder 的博客',
description = '记录关于数据库、时序数据、人工智能与软件工程的学习、研究和实践。',
article = false,
home = false,
noindex = false,
canonicalPath = Astro.url.pathname,
post,
} = Astro.props;
const pageTitle = title.startsWith('SpriCoder') ? title : `${title} · SpriCoder`;
const site = Astro.site ?? new URL('https://spricoder.github.io/');
const canonical = new URL(canonicalPath, site);
const pageSeries = post?.series ?? Object.entries(seriesSlugs).find(([, slug]) => Astro.url.pathname === `/series/${slug}/`)?.[0];
const shareImage = shareImageFor(pageSeries);
const shareImageUrl = new URL(shareImage.path, site).href;
const structuredData = post ? JSON.stringify({
'@context': 'https://schema.org',
'@type': 'BlogPosting',
headline: post.title,
description,
author: { '@type': 'Person', name: 'SpriCoder', url: new URL('/about/', site).href },
datePublished: post.date,
...(post.updated ? { dateModified: post.updated } : {}),
mainEntityOfPage: { '@type': 'WebPage', '@id': canonical.href },
url: canonical.href,
inLanguage: 'zh-CN',
...(post.series ? { articleSection: post.series } : {}),
...(post.tags?.length ? { keywords: post.tags } : {}),
...(post.image ? { image: new URL(post.image, site).href } : {}),
}).replaceAll('<', '\\u003c') : undefined;
---
<!doctype html>
<html lang="zh-CN" class:list={[{ 'home-page': home }]}>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content={Astro.generator} />
<meta name="description" content={description} />
<meta name="theme-color" content="#f3f7fc" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#0b1324" media="(prefers-color-scheme: dark)" />
{noindex && <meta name="robots" content="noindex, follow" />}
<link rel="canonical" href={canonical} />
<link rel="alternate" type="application/atom+xml" title="SpriCoder 订阅" href="/atom.xml" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
{article && <link rel="stylesheet" href="/vendor/katex/katex.min.css" />}
<meta property="og:locale" content="zh_CN" />
<meta property="og:site_name" content="SpriCoder" />
<meta property="og:type" content={article ? 'article' : 'website'} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />
<meta property="og:url" content={canonical} />
<meta property="og:image" content={shareImageUrl} />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content={String(shareImage.width)} />
<meta property="og:image:height" content={String(shareImage.height)} />
<meta property="og:image:alt" content={shareImage.alt} />
{post && <meta property="article:published_time" content={post.date} />}
{post?.updated && <meta property="article:modified_time" content={post.updated} />}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
<meta name="twitter:image" content={shareImageUrl} />
<meta name="twitter:image:alt" content={shareImage.alt} />
{structuredData && <script is:inline type="application/ld+json" set:html={structuredData} />}
<title>{pageTitle}</title>
<script is:inline>
(() => {
let theme;
try { theme = localStorage.getItem('spricoder-theme'); } catch {}
if (theme !== 'light' && theme !== 'dark') {
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
document.documentElement.dataset.theme = theme;
document.documentElement.style.colorScheme = theme;
})();
</script>
</head>
<body class:list={[{ 'article-page': article }]}>
<a class="skip-link" href={home ? '#home-content' : '#main-content'}>跳到正文</a>
<Header />
<main id="main-content" tabindex="-1">
<slot />
</main>
<Footer />
<script is:inline src="/js/analytics.js" defer></script>
<script is:inline src="/js/duration.js" defer></script>
</body>
</html>