-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathBaseLayout.astro
More file actions
646 lines (564 loc) · 19.5 KB
/
BaseLayout.astro
File metadata and controls
646 lines (564 loc) · 19.5 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
---
import Header from '../components/Header.tsx';
import Footer from '../components/Footer.tsx';
// import Sidebar from '../components/Sidebar';
import { ThemeProvider } from '../components/theme/ThemeContext.tsx';
import ToastProvider from '../components/ToastProvider.tsx';
import { GoogleTagManager } from 'astro-gtm';
import '../styles/global.css';
import SearchPage from '../components/SearchPage';
// Rest of imports and props remain the same
export interface Props {
// Basic SEO
name: string;
title: string;
path: string;
description?: string;
canonical?: string;
themeColor?: string;
keywords?: string[];
ogImage?: string;
twitterImage?: string;
// Layout
showSidebar?: boolean;
showHeader?: boolean;
// Content metadata
datePublished?: string;
dateModified?: string;
softwareVersion?: string;
features?: string[];
author?: string;
license?: string;
category?: string;
// Image/Media
imgWidth?: number;
imgHeight?: number;
thumbnailUrl?: string;
encodingFormat?: string;
// Hierarchical structure
partOf?: string;
partOfUrl?: string;
// Schema type override
pageType?: string;
// Collection/List specific
totalItems?: number;
itemsPerPage?: number;
currentPage?: number;
// Tool specific
toolType?: string;
toolCategory?: string;
// Icon specific
iconName?: string;
iconCategory?: string;
iconTags?: string[];
// Emoji specific
emojiCode?: string;
emojiCategory?: string;
// Command/Cheatsheet specific
commandName?: string;
platform?: string;
commandCategory?: string;
// MCP Repository specific
githubUrl?: string;
}
const {
// Basic SEO
name,
title,
description,
canonical,
themeColor = "#1e40af",
keywords = [],
ogImage = "https://hexmos.com/freedevtools/site-banner.png",
twitterImage = "https://hexmos.com/freedevtools/site-banner.png",
// Layout
showHeader = true,
showSidebar = false,
// Content metadata
datePublished,
dateModified,
softwareVersion = "1.0.0",
features = [],
author = "Free DevTools by Hexmos",
license = "MIT",
category,
// Image/Media
imgWidth = 1136,
imgHeight = 768,
thumbnailUrl,
encodingFormat = "text/html",
// Hierarchical structure
partOf = "Free DevTools",
partOfUrl = "https://hexmos.com/freedevtools/",
// Schema type override
pageType: customPageType,
// Collection/List specific
totalItems,
itemsPerPage,
currentPage = 1,
// Tool specific
toolType,
toolCategory,
// Icon specific
iconName,
iconCategory,
iconTags = [],
// Emoji specific
emojiCode,
emojiCategory,
// Command/Cheatsheet specific
commandName,
platform,
commandCategory,
// MCP Repository specific
githubUrl,
} = Astro.props;
const currentUrl = canonical || Astro.url.href;
const keywordsString = keywords.length > 0 ? keywords.join(', ') : '';
// Determine page type based on path and props
function determinePageType(path: string, props: any): string {
if (props.pageType) return props.pageType;
// SVG Icon pages
if (path.includes('/svg_icons/')) {
if (path.match(/\/svg_icons\/[^\/]+\/[^\/]+$/)) {
return 'ImageObject'; // Individual icon page
} else if (path.match(/\/svg_icons\/[^\/]+$/)) {
return 'CollectionPage'; // Category page
} else {
return 'CollectionPage'; // Main SVG icons page
}
}
// Tool pages
if (path.match(/\/t\/[^\/]+$/) || path.match(/\/t\/[^\/]+\/[^\/]+$/)) {
return 'SoftwareApplication';
}
// Cheatsheet pages
if (path.includes('/c/')) {
if (path.match(/\/c\/[^\/]+\/[^\/]+$/)) {
return 'TechArticle'; // Individual cheatsheet
} else if (path.match(/\/c\/[^\/]+$/)) {
return 'CollectionPage'; // Category page
} else {
return 'CollectionPage'; // Main cheatsheets page
}
}
// TLDR pages
if (path.includes('/tldr/')) {
if (path.match(/\/tldr\/[^\/]+\/[^\/]+$/)) {
return 'TechArticle'; // Individual command page
} else if (path.match(/\/tldr\/[^\/]+$/)) {
return 'CollectionPage'; // Platform page
} else {
return 'CollectionPage'; // Main TLDR page
}
}
// MCP pages
if (path.includes('/mcp/')) {
if (path.match(/\/mcp\/[^\/]+\/[^\/]+$/)) {
return 'SoftwareApplication'; // Individual MCP repository page
} else if (path.match(/\/mcp\/[^\/]+$/)) {
return 'CollectionPage'; // MCP category page
} else {
return 'CollectionPage'; // Main MCP page
}
}
// Emoji pages
if (path.includes('/emojis/')) {
if (path.match(/\/emojis\/[^\/]+$/)) {
return 'CollectionPage'; // Category page
} else {
return 'CollectionPage'; // Main emojis page
}
}
// Default
return 'WebPage';
}
// Generate base schema properties
function getBaseSchema(props: any) {
const currentDate = new Date().toISOString();
return {
"@context": "https://schema.org",
"url": props.canonical || currentUrl,
"inLanguage": "en",
"datePublished": props.datePublished || currentDate,
"dateModified": props.dateModified || currentDate,
"author": {
"@type": "Organization",
"name": props.author || "Free DevTools by Hexmos",
"url": "https://hexmos.com/freedevtools/"
},
"publisher": {
"@type": "Organization",
"name": "Free DevTools by Hexmos",
"url": "https://hexmos.com/freedevtools/"
},
"isPartOf": {
"@type": "Collection",
"name": props.partOf || "Free DevTools",
"url": props.partOfUrl || "https://hexmos.com/freedevtools/"
},
"license": props.license === "MIT" ? "https://opensource.org/licenses/MIT" : (props.license || "https://opensource.org/licenses/MIT"),
"mainEntityOfPage": {
"@type": "WebPage",
"@id": props.canonical || currentUrl
}
};
}
// Generate specific schema based on page type
function generatePageSpecificSchema(pageType: string, props: any) {
const baseSchema = getBaseSchema(props);
switch (pageType) {
case 'ImageObject': // Individual SVG icon
return {
...baseSchema,
"@type": "ImageObject",
"name": props.iconName || props.name,
"description": props.description,
"contentUrl": props.thumbnailUrl || props.ogImage,
"thumbnailUrl": props.thumbnailUrl || props.ogImage,
"image": props.thumbnailUrl || props.ogImage,
"encodingFormat": props.encodingFormat || "image/svg+xml",
"width": props.imgWidth,
"height": props.imgHeight,
"keywords": [...(props.keywords || []), ...(props.iconTags || [])].join(", "),
"about": {
"@type": "Thing",
"name": props.iconCategory || props.category
},
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD",
"availability": "https://schema.org/InStock"
},
"license": props.license === "MIT" ? "https://opensource.org/licenses/MIT" : (props.license || "https://opensource.org/licenses/MIT"),
"creator": {
"@type": "Organization",
"name": props.author || "Free DevTools by Hexmos",
"url": "https://hexmos.com/freedevtools/"
},
"copyrightHolder": {
"@type": "Organization",
"name": props.author || "Free DevTools by Hexmos"
},
"copyrightYear": new Date().getFullYear(),
"isAccessibleForFree": true,
"usageInfo": {
"@type": "CreativeWork",
"text": "Free to use under MIT license. No attribution required but appreciated."
}
};
case 'SoftwareApplication': // Tool page or MCP repository
const isMcpRepository = props.path?.includes('/mcp/');
if (isMcpRepository) {
return {
...baseSchema,
"@type": "SoftwareApplication",
"name": props.name,
"description": props.description,
"applicationCategory": "DeveloperTool",
"operatingSystem": "Any",
"browserRequirements": "Requires Node.js, MCP Client",
"softwareVersion": props.softwareVersion,
"featureList": props.features || [],
"keywords": props.keywords?.join(", ") || "",
"screenshot": props.ogImage,
"programmingLanguage": "TypeScript",
"runtimePlatform": "Node.js",
"softwareRequirements": "Model Context Protocol (MCP) compatible client",
"category": "Model Context Protocol Server",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD",
"availability": "https://schema.org/InStock"
},
"codeRepository": {
"@type": "SoftwareSourceCode",
"url": props.githubUrl || props.url,
"programmingLanguage": "TypeScript",
"license": props.license === "MIT" ? "https://opensource.org/licenses/MIT" : (props.license || "https://opensource.org/licenses/MIT")
}
};
} else {
return {
...baseSchema,
"@type": "SoftwareApplication",
"name": props.name,
"description": props.description,
"applicationCategory": "DeveloperTool",
"operatingSystem": "Any",
"browserRequirements": "Requires JavaScript. Requires HTML5.",
"softwareVersion": props.softwareVersion,
"featureList": props.features || [],
"keywords": props.keywords?.join(", ") || "",
"screenshot": props.ogImage,
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD",
"availability": "https://schema.org/InStock"
}
};
}
case 'TechArticle': // Command/Cheatsheet page
return {
...baseSchema,
"@type": "TechArticle",
"headline": props.name,
"description": props.description,
"articleBody": props.description,
"keywords": props.keywords?.join(", ") || "",
"about": {
"@type": "Thing",
"name": props.commandName || props.name
},
"mentions": props.platform ? {
"@type": "Thing",
"name": props.platform
} : undefined,
"articleSection": props.commandCategory || props.category
};
case 'CollectionPage': // Category/List pages
const collectionSchema: any = {
...baseSchema,
"@type": "CollectionPage",
"name": props.name,
"description": props.description,
"keywords": props.keywords?.join(", ") || "",
"mainEntity": {
"@type": "ItemList",
"numberOfItems": props.totalItems || 0,
"itemListElement": [] // This would be populated with actual items
}
};
// Add pagination info if available
if (props.totalItems && props.itemsPerPage) {
collectionSchema.mainEntity.numberOfItems = props.totalItems;
collectionSchema.mainEntity.numberOfPages = Math.ceil(props.totalItems / props.itemsPerPage);
collectionSchema.mainEntity.currentPage = props.currentPage;
}
return collectionSchema;
default: // WebPage
return {
...baseSchema,
"@type": "WebPage",
"name": props.name,
"description": props.description,
"keywords": props.keywords?.join(", ") || ""
};
}
}
// Generate the final schema
const detectedPageType = determinePageType(Astro.props.path, Astro.props);
const schema = generatePageSpecificSchema(detectedPageType, Astro.props);
// Debug: Print the final schema
// console.log('🔍 JSON-LD Schema for:', Astro.props.path);
// console.log('📄 Page Type:', detectedPageType);
// console.log('📋 Generated Schema:', JSON.stringify(schema, null, 2));
const GA_MEASUREMENT_ID = 'G-WXSDF484XZ';
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Basic SEO Meta Tags -->
<title>{title}</title>
{description && <meta name="description" content={description} />}
{keywordsString && <meta name="keywords" content={keywordsString} />}
<meta name="theme-color" content={themeColor} />
{canonical && <link rel="canonical" href={canonical} />}
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:title" content={title} />
{description && <meta property="og:description" content={description} />}
<meta property="og:url" content={currentUrl} />
<meta property="og:image" content={thumbnailUrl || ogImage} />
<meta property="og:site_name" content="Free DevTools by Hexmos" />
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title} />
{description && <meta name="twitter:description" content={description} />}
<meta name="twitter:image" content={thumbnailUrl || twitterImage} />
<!-- JSON-LD Structured Data -->
{schema && (
<script type="application/ld+json" set:html={JSON.stringify(schema)} />
)}
<!-- Additional SEO Meta Tags -->
<meta name="robots" content="index, follow" />
<meta name="author" content="Free DevTools by Hexmos" />
<meta name="generator" content="Astro" />
<!-- Image-specific meta tags for better SEO -->
{thumbnailUrl && (
<>
<meta name="image" content={thumbnailUrl} />
<meta property="og:image:width" content={imgWidth.toString()} />
<meta property="og:image:height" content={imgHeight.toString()} />
<meta property="og:image:type" content={encodingFormat} />
<meta property="og:image:alt" content={name} />
<meta name="twitter:image:alt" content={name} />
</>
)}
<!-- Favicon -->
<link rel="icon" type="image/png" href="/freedevtools/t/favicon.webp" />
<!-- Fonts -->
<!-- Preload critical fonts for faster loading -->
<link rel="preload" href="/freedevtools/fonts/Cal_Sans/CalSans-Regular.ttf" as="font" type="font/ttf" crossorigin>
<!-- <link rel="preload" href="/freedevtools/fonts/EB_Garamond/EBGaramond-VariableFont_wght.ttf" as="font" type="font/ttf" crossorigin> -->
<!-- Load local fonts CSS -->
<link rel="stylesheet" href="/freedevtools/fonts/fonts.css">
<!-- Critical CSS for Theme Switcher to prevent FOUC -->
<style>
/* Prevent theme toggle FOUC by inlining critical styles */
#theme-switcher-container {
display: grid;
grid-template-columns: 1fr;
}
#theme-switcher-container > div {
position: relative;
z-index: 0;
display: inline-grid;
gap: 0.125rem;
border-radius: 9999px;
background-color: rgba(0, 0, 0, 0.05);
padding: 0.125rem;
color: rgb(9, 9, 11);
}
.dark #theme-switcher-container > div {
background-color: rgba(255, 255, 255, 0.1);
color: rgb(255, 255, 255);
}
#theme-switcher-container button,
#theme-switcher-container > div > div {
position: relative;
border-radius: 9999px;
cursor: pointer;
transition: all 0.2s;
padding: 0.125rem;
}
#theme-switcher-container svg {
width: 1rem;
height: 1rem;
}
@media (min-width: 640px) {
#theme-switcher-container > div {
padding: 0.1875rem;
}
#theme-switcher-container button,
#theme-switcher-container > div > div {
padding: 0.25rem;
}
#theme-switcher-container svg {
width: 1.25rem;
height: 1.25rem;
}
}
@media (min-width: 1024px) {
#theme-switcher-container svg {
width: 1.5rem;
height: 1.5rem;
}
}
#theme-switcher-container .theme-active {
background-color: rgb(255, 255, 255);
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.dark #theme-switcher-container .theme-active {
background-color: rgb(75, 85, 99);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}
</style>
<!-- Theme initialization script -->
<script>
(function() {
const theme = localStorage.getItem('theme') || 'dark';
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
})();
</script>
<!-- Add global search state -->
<script>
// Add type definition for window
interface SearchState {
query: string;
setQuery: (query: string) => void;
getQuery: () => string;
}
// Extend Window interface
interface Window {
searchState?: SearchState;
}
// Initialize global search state
window.searchState = {
query: '',
setQuery: function(query) {
this.query = query;
// Dispatch an event when query changes
window.dispatchEvent(new CustomEvent('searchQueryChanged', {
detail: { query }
}));
},
getQuery: function() {
return this.query;
}
};
</script>
</head>
<body class="m-0 p-0 font-sans bg-slate-50 text-slate-800 leading-relaxed dark:bg-slate-900 dark:text-slate-200 min-h-screen flex flex-col">
<GoogleTagManager gtmId={GA_MEASUREMENT_ID} enableInDevMode={false} />
<div class="flex flex-1">
{showHeader && (
<ThemeProvider client:load>
<Header client:load />
</ThemeProvider>
)}
<main class="flex-1 overflow-auto bg-background" class:list={[
showHeader ? "pt-16 md:pt-16" : "pt-0 lg:pt-0"
]}>
<ThemeProvider client:load>
<ToastProvider client:load>
<div id="main-page" >
<div id="search-container" style="display: none;" class="max-w-6xl mx-auto px-2 md:px-6">
<SearchPage client:load />
</div>
<div id="slot-container">
<slot />
</div>
</div>
<script>
// Function to toggle visibility based on search query
function toggleSearchView() {
const searchContainer = document.getElementById('search-container');
const slotContainer = document.getElementById('slot-container');
// Handle the case where elements aren't found
if (!searchContainer || !slotContainer) return;
// Safely access window.searchState
const searchQuery = window.searchState?.getQuery?.() || '';
if (searchQuery.trim()) {
searchContainer.style.display = 'block';
slotContainer.style.display = 'none';
} else {
searchContainer.style.display = 'none';
slotContainer.style.display = 'block';
}
}
// Initialize and set up listener
document.addEventListener('DOMContentLoaded', function() {
// Initial toggle based on search state
toggleSearchView();
// Listen for search query changes
window.addEventListener('searchQueryChanged', toggleSearchView);
});
</script>
</ToastProvider>
<!-- Footer -->
<Footer client:load />
</ThemeProvider>
</main>
</div>
</body>
</html>