-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseLayout.astro
More file actions
189 lines (168 loc) · 5.35 KB
/
Copy pathBaseLayout.astro
File metadata and controls
189 lines (168 loc) · 5.35 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
import BaseHead from '../components/BaseHead.astro';
import BackToTop from '../components/BackToTop.astro';
import ReadingProgress from '../components/ReadingProgress.astro';
import StructuredData from '../components/StructuredData.astro';
import PerformanceMonitor from '../components/PerformanceMonitor.astro';
import ServiceWorkerRegistration from '../components/ServiceWorkerRegistration.astro';
import ReadStateServiceInit from '../components/ReadStateServiceInit.astro';
import { getSearchData } from '../data/searchIndex';
import { SITE_DESCRIPTION, AUTHOR } from '../consts';
import { generateKeywords, generateImageAlt } from '../utils/seo';
import { generateStructuredData } from '../utils/structuredData';
import SpeedInsights from '@vercel/speed-insights/astro';
import Analytics from '@vercel/analytics/astro';
import type { BaseLayoutProps } from '../types/layout';
interface Props extends BaseLayoutProps {}
const searchData = await getSearchData();
const {
title,
description = SITE_DESCRIPTION,
pubDate,
updatedDate,
heroImage,
minutesRead,
tags,
category = [],
path,
imageAlt,
author = AUTHOR.name,
keywords,
type,
structuredDataType = 'website',
structuredDataIdentifier,
posts = [],
postId,
hasComments = false,
featured = false,
draft = false,
tableOfContents,
robots,
hreflangAlternates,
htmlLang = 'en',
locale,
inLanguage = 'en-US',
wordCount,
} = Astro.props;
// Auto-generate keywords if not provided
const finalKeywords = keywords || generateKeywords(tags, category);
// Auto-generate image alt text if not provided
const finalImageAlt = imageAlt || generateImageAlt(title);
// Auto-generate structured data
const structuredData = generateStructuredData({
title,
description,
path: path || Astro.url.pathname,
posts,
type: structuredDataType,
identifier: structuredDataIdentifier,
pubDate,
updatedDate,
heroImage,
keywords: finalKeywords,
minutesRead,
category,
tags,
tableOfContents: Array.isArray(tableOfContents) ? tableOfContents.length > 0 : !!tableOfContents,
hasComments,
featured,
draft,
inLanguage,
wordCount,
});
---
<!doctype html>
<html lang={htmlLang} class="scroll-smooth">
<head>
<BaseHead
title={title}
description={description}
path={path}
heroImage={heroImage}
imageAlt={finalImageAlt}
pubDate={pubDate}
updatedDate={updatedDate}
author={author}
keywords={finalKeywords}
type={type}
robots={robots}
hreflangAlternates={hreflangAlternates}
locale={locale}
htmlLang={htmlLang}
/>
<!-- Load Speed Insights asynchronously -->
<SpeedInsights />
</head>
<body
class="flex min-h-screen flex-col bg-[rgb(var(--color-bg))] text-[rgb(var(--color-text))] antialiased"
>
<script>
// Prevent FOUC in Firefox
document.documentElement.classList.add('ready');
</script>
<a
href="#main-content"
class="sr-only focus:not-sr-only focus:absolute focus:top-4 focus:left-4 focus:z-50 focus:rounded-sm focus:bg-[rgb(var(--color-bg))] focus:px-4 focus:py-2 focus:shadow-lg focus:ring-2 focus:ring-[rgb(var(--color-accent))] focus:ring-offset-2"
>Skip to main content</a
>
<ReadStateServiceInit />
<Header searchData={searchData} />
<ReadingProgress postId={postId} />
<main id="main-content" role="main" class="animate-fade-in grow">
<!-- Structured Data -->
<StructuredData data={structuredData} />
<slot />
</main>
<Footer />
<BackToTop />
<Analytics />
<!-- Performance Monitoring (development only) -->
{import.meta.env.DEV && <PerformanceMonitor />}
<!-- Service Worker Registration -->
<ServiceWorkerRegistration />
<!-- Image Modal -->
<div id="imageModal" class="image-modal">
<button class="close-btn" onclick="closeImageModal()">×</button>
<img id="modalImage" src="" alt="" />
</div>
<script is:inline>
// Image modal functionality
function openImageModal(imageSrc, imageAlt) {
const modal = document.getElementById('imageModal');
const modalImage = document.getElementById('modalImage');
modalImage.src = imageSrc;
modalImage.alt = imageAlt;
modal.classList.add('show');
document.body.style.overflow = 'hidden';
}
function closeImageModal() {
const modal = document.getElementById('imageModal');
modal.classList.remove('show');
document.body.style.overflow = 'auto';
}
// Close modal when clicking outside the image
document.getElementById('imageModal').addEventListener('click', function (e) {
if (e.target === this) {
closeImageModal();
}
});
// Close modal with Escape key
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') {
closeImageModal();
}
});
// Make blog post images clickable for modal
document.addEventListener('DOMContentLoaded', function () {
const proseImages = document.querySelectorAll('.prose img');
proseImages.forEach(function (img) {
img.addEventListener('click', function () {
openImageModal(this.src, this.alt);
});
});
});
</script>
</body>
</html>