-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathLayout.astro
More file actions
312 lines (277 loc) · 9.11 KB
/
Layout.astro
File metadata and controls
312 lines (277 loc) · 9.11 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
---
import './styles/global.css'
import { Font } from 'astro:assets'
import Navigation from './components/Navigation.astro'
import ThemeSelector from './components/ThemeSelector.astro'
import {
SITE_TITLE,
SITE_DESCRIPTION,
SITE_URL,
OG_TITLE,
OG_DESCRIPTION,
OG_TYPE,
OG_IMAGE,
OG_IMAGE_ALT,
TWITTER_CARD,
TWITTER_SITE,
TWITTER_CREATOR,
BOOK_AUTHORS,
THEME_COLOR,
} from '@lib/const'
export interface Props {
title?: string
description?: string
ogTitle?: string
ogDescription?: string
ogImage?: string
canonical?: string
additionalSchema?: object | object[]
noindex?: boolean
}
const {
title = SITE_TITLE,
description = SITE_DESCRIPTION,
ogTitle = OG_TITLE,
ogDescription = OG_DESCRIPTION,
ogImage = OG_IMAGE,
canonical,
additionalSchema,
noindex = false,
} = Astro.props
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-title" content="Node.js Design Patterns" />
<link rel="manifest" href="/site.webmanifest" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content={Astro.generator} />
<!-- Primary Meta Tags -->
<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />
<meta name="author" content={BOOK_AUTHORS} />
<meta
name="keywords"
content="Node.js, Design Patterns, JavaScript, Backend Development, Software Architecture, Programming, Web Development, Scalable Applications"
/>
{
noindex ? (
<meta name="robots" content="noindex, nofollow" />
) : (
<meta name="robots" content="index, follow" />
)
}
<meta name="theme-color" content={THEME_COLOR} />
<!-- Canonical URL -->
{canonical && <link rel="canonical" href={canonical} />}
<!-- RSS Feed -->
<link
rel="alternate"
type="application/rss+xml"
title="Node.js Design Patterns - Blog"
href="/rss.xml"
/>
<!-- Sitemap -->
<link rel="sitemap" href="/sitemap-index.xml" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content={OG_TYPE} />
<meta property="og:url" content={canonical} />
<meta property="og:title" content={ogTitle} />
<meta property="og:description" content={ogDescription} />
<meta property="og:image" content={new URL(ogImage, SITE_URL)} />
<meta property="og:image:alt" content={OG_IMAGE_ALT} />
<meta property="og:site_name" content="Node.js Design Patterns" />
<meta property="og:locale" content="en_US" />
<!-- Twitter -->
<meta property="twitter:card" content={TWITTER_CARD} />
<meta property="twitter:url" content={canonical} />
<meta property="twitter:title" content={ogTitle} />
<meta property="twitter:description" content={ogDescription} />
<meta property="twitter:image" content={new URL(ogImage, SITE_URL)} />
<meta property="twitter:image:alt" content={OG_IMAGE_ALT} />
<meta property="twitter:site" content={TWITTER_SITE} />
<meta property="twitter:creator" content={TWITTER_CREATOR} />
<!-- Book-specific structured data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Book",
"name": "Node.js Design Patterns",
"edition": "Fourth Edition",
"author": [
{
"@type": "Person",
"name": "Mario Casciaro"
},
{
"@type": "Person",
"name": "Luciano Mammino"
}
],
"publisher": {
"@type": "Organization",
"name": "Packt Publishing"
},
"datePublished": "2024-07-31",
"isbn": "9781803238944",
"numberOfPages": 660,
"description": "The definitive guide to Node.js patterns and best practices. Learn proven techniques for building scalable, maintainable applications.",
"url": "https://nodejsdesignpatterns.com",
"image": "https://nodejsdesignpatterns.com/images/og-image.png",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": 4.6,
"bestRating": 5,
"ratingCount": 780
}
}
</script>
{
additionalSchema &&
(Array.isArray(additionalSchema) ? (
additionalSchema.map((schema) => (
<script
type="application/ld+json"
set:html={JSON.stringify(schema)}
/>
))
) : (
<script
type="application/ld+json"
set:html={JSON.stringify(additionalSchema)}
/>
))
}
<script>
import { initTheme } from './lib/theme.ts'
initTheme()
</script>
<!-- Global Analytics: Outbound Link Tracking -->
<script>
import {
trackClickOutboundLink,
isExternalUrl,
extractDomain,
getPagePath,
} from './lib/analytics.ts'
function initOutboundLinkTracking() {
document.addEventListener('click', (event) => {
const target = event.target as HTMLElement
const link = target.closest('a')
if (!link) return
const href = link.getAttribute('href')
if (!href) return
// Only track external links
if (!isExternalUrl(href)) return
// Don't track if it's a buy button (already tracked separately)
if (link.hasAttribute('data-analytics-format')) return
trackClickOutboundLink({
link_url: href,
link_domain: extractDomain(href),
link_text: link.textContent?.trim().slice(0, 100) || '',
source_page: getPagePath(),
})
})
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initOutboundLinkTracking)
} else {
initOutboundLinkTracking()
}
</script>
<!-- Global Analytics: Internal Navigation Tracking -->
<script>
import {
trackInternalNavigation,
isExternalUrl,
getPagePath,
type NavigationType,
} from './lib/analytics.ts'
function initInternalNavigationTracking() {
const currentPath = getPagePath()
document.addEventListener('click', (event) => {
const target = event.target as HTMLElement
const link = target.closest('a')
if (!link) return
const href = link.getAttribute('href')
if (!href) return
// Only track internal links
if (isExternalUrl(href)) return
// Skip anchor links on same page
if (href.startsWith('#')) return
// Skip if it's a buy button (already tracked)
if (link.hasAttribute('data-analytics-format')) return
// Determine navigation type based on element location
let navigationType: NavigationType = 'inline_link'
const nav = link.closest('nav')
const header = link.closest('header')
const footer = link.closest('footer')
if (nav || header) {
navigationType = 'header_link'
} else if (footer) {
navigationType = 'footer_link'
}
// Get the destination path
let toPage = href
try {
const url = new URL(href, window.location.origin)
toPage = url.pathname
} catch {
// Keep original href if URL parsing fails
}
trackInternalNavigation({
from_page: currentPath,
to_page: toPage,
navigation_type: navigationType,
})
})
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener(
'DOMContentLoaded',
initInternalNavigationTracking,
)
} else {
initInternalNavigationTracking()
}
</script>
<Font cssVariable="--font-base-sans" preload />
<Font cssVariable="--font-base-serif" preload />
<Font cssVariable="--font-base-mono" preload />
<!-- Google tag (gtag.js) -->
<script
is:inline
type="text/partytown"
src="https://www.googletagmanager.com/gtag/js?id=G-NFE37ZH2W3"></script>
<script is:inline type="text/partytown">
window.dataLayer = window.dataLayer || []
function gtag() {
// eslint-disable-next-line no-undef
dataLayer.push(arguments)
}
gtag('js', new Date())
// Disable all tracking by default
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
// analytics_storage: 'denied',
})
gtag('config', 'G-NFE37ZH2W3')
</script>
</head>
<body
class="antialiased transition-colors duration-300 bg-base-100 text-base-content"
>
<Navigation />
<ThemeSelector />
<slot />
</body>
</html>