@umituz/web-seo 1.0.5 β 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +433 -0
- package/dist/domains/seo/components/JsonLd.d.ts +17 -0
- package/dist/domains/seo/components/JsonLd.d.ts.map +1 -0
- package/dist/domains/seo/components/JsonLd.js +52 -0
- package/dist/domains/seo/components/SEO.d.ts +4 -0
- package/dist/domains/seo/components/SEO.d.ts.map +1 -0
- package/dist/domains/seo/components/SEO.js +48 -0
- package/dist/domains/seo/core/init.d.ts +16 -0
- package/dist/domains/seo/core/init.d.ts.map +1 -0
- package/dist/domains/seo/core/init.js +34 -0
- package/dist/domains/seo/hooks/useJsonLd.d.ts +19 -0
- package/dist/domains/seo/hooks/useJsonLd.d.ts.map +1 -0
- package/dist/domains/seo/hooks/useJsonLd.js +53 -0
- package/dist/domains/seo/hooks/useSEO.d.ts +3 -0
- package/dist/domains/seo/hooks/useSEO.d.ts.map +1 -0
- package/dist/domains/seo/hooks/useSEO.js +47 -0
- package/dist/domains/seo/index.d.ts +15 -0
- package/dist/domains/seo/index.d.ts.map +1 -0
- package/dist/domains/seo/index.js +21 -0
- package/dist/domains/seo/ssr/renderer.d.ts +58 -0
- package/dist/domains/seo/ssr/renderer.d.ts.map +1 -0
- package/dist/domains/seo/ssr/renderer.js +242 -0
- package/dist/domains/seo/ssr/serializer.d.ts +71 -0
- package/dist/domains/seo/ssr/serializer.d.ts.map +1 -0
- package/dist/domains/seo/ssr/serializer.js +175 -0
- package/dist/domains/seo/types/index.d.ts +190 -0
- package/dist/domains/seo/types/index.d.ts.map +1 -0
- package/dist/domains/seo/types/index.js +1 -0
- package/dist/domains/seo/types/schema.d.ts +212 -0
- package/dist/domains/seo/types/schema.d.ts.map +1 -0
- package/dist/domains/seo/types/schema.js +4 -0
- package/dist/domains/seo/utils/dom.d.ts +22 -0
- package/dist/domains/seo/utils/dom.d.ts.map +1 -0
- package/dist/domains/seo/utils/dom.js +537 -0
- package/dist/domains/seo/utils/schema.d.ts +135 -0
- package/dist/domains/seo/utils/schema.d.ts.map +1 -0
- package/dist/domains/seo/utils/schema.js +321 -0
- package/dist/domains/seo/utils/validators.d.ts +39 -0
- package/dist/domains/seo/utils/validators.d.ts.map +1 -0
- package/dist/domains/seo/utils/validators.js +364 -0
- package/dist/domains/seo/vite/plugin.d.ts +61 -0
- package/dist/domains/seo/vite/plugin.d.ts.map +1 -0
- package/dist/domains/seo/vite/plugin.js +215 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/package.json +34 -5
package/README.md
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
# @umituz/web-seo
|
|
2
|
+
|
|
3
|
+
> Comprehensive SEO solution for React Vite applications with Domain-Driven Design architecture
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### β
Core SEO
|
|
8
|
+
- π Dynamic meta tag management
|
|
9
|
+
- π Open Graph support
|
|
10
|
+
- π¦ Twitter Card support
|
|
11
|
+
- π Canonical URL management
|
|
12
|
+
- π hreflang support for international SEO
|
|
13
|
+
- π€ Robots meta control (noindex, nofollow, etc.)
|
|
14
|
+
- π¨ Theme color and favicon management
|
|
15
|
+
- π± Viewport configuration
|
|
16
|
+
|
|
17
|
+
### π Structured Data (JSON-LD)
|
|
18
|
+
- π° Article/News/Blog schema
|
|
19
|
+
- π Product schema
|
|
20
|
+
- π’ Organization schema
|
|
21
|
+
- πͺ Local Business schema
|
|
22
|
+
- π Breadcrumb schema
|
|
23
|
+
- β FAQ schema
|
|
24
|
+
- π WebSite schema
|
|
25
|
+
- π€ Person schema
|
|
26
|
+
- π₯ Video schema
|
|
27
|
+
|
|
28
|
+
### β‘ Performance Optimization
|
|
29
|
+
- β‘ Preload hints for critical resources
|
|
30
|
+
- π Preconnect to external origins
|
|
31
|
+
- π DNS prefetch for performance
|
|
32
|
+
- π― Resource priority management
|
|
33
|
+
|
|
34
|
+
### π οΈ Build-time SEO (Vite Plugin)
|
|
35
|
+
- πΊοΈ Automatic sitemap.xml generation
|
|
36
|
+
- π€ Automatic robots.txt generation
|
|
37
|
+
- π Route discovery
|
|
38
|
+
- π SEO audit at build time
|
|
39
|
+
|
|
40
|
+
### π₯οΈ SSR Support
|
|
41
|
+
- π Server-side rendering utilities
|
|
42
|
+
- π Hydration support
|
|
43
|
+
- π¦ Serialization/deserialization
|
|
44
|
+
- π― Helmet-like API compatibility
|
|
45
|
+
|
|
46
|
+
### β
Validation & Dev Tools
|
|
47
|
+
- βοΈ URL validation
|
|
48
|
+
- π Content length checking
|
|
49
|
+
- πΌοΈ Image dimension validation
|
|
50
|
+
- π Schema validation
|
|
51
|
+
- π SEO audit functionality
|
|
52
|
+
- π‘ Development warnings
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @umituz/web-seo
|
|
58
|
+
# or
|
|
59
|
+
yarn add @umituz/web-seo
|
|
60
|
+
# or
|
|
61
|
+
pnpm add @umituz/web-seo
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
65
|
+
|
|
66
|
+
### Basic Usage
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { SEO } from "@umituz/web-seo";
|
|
70
|
+
|
|
71
|
+
function App() {
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<SEO
|
|
75
|
+
title="My Awesome Website"
|
|
76
|
+
description="A comprehensive description of my website"
|
|
77
|
+
canonical="https://example.com"
|
|
78
|
+
openGraph={{
|
|
79
|
+
type: "website",
|
|
80
|
+
url: "https://example.com",
|
|
81
|
+
title: "My Awesome Website",
|
|
82
|
+
description: "A comprehensive description of my website",
|
|
83
|
+
image: "https://example.com/og-image.jpg",
|
|
84
|
+
}}
|
|
85
|
+
twitter={{
|
|
86
|
+
cardType: "summary_large_image",
|
|
87
|
+
site: "@yourhandle",
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
<YourAppContent />
|
|
91
|
+
</>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Using the Hook
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { useSEO } from "@umituz/web-seo";
|
|
100
|
+
|
|
101
|
+
function BlogPost({ post }) {
|
|
102
|
+
useSEO({
|
|
103
|
+
title: post.title,
|
|
104
|
+
description: post.excerpt,
|
|
105
|
+
canonical: `https://example.com/blog/${post.slug}`,
|
|
106
|
+
openGraph: {
|
|
107
|
+
type: "article",
|
|
108
|
+
title: post.title,
|
|
109
|
+
description: post.excerpt,
|
|
110
|
+
image: post.coverImage,
|
|
111
|
+
article: {
|
|
112
|
+
publishedTime: post.publishedAt,
|
|
113
|
+
author: post.author.name,
|
|
114
|
+
section: post.category,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return <article>{/* Your post content */}</article>;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Structured Data (JSON-LD)
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import { JsonLd, generateArticleSchema } from "@umituz/web-seo";
|
|
127
|
+
|
|
128
|
+
function ArticlePage({ article }) {
|
|
129
|
+
const schema = generateArticleSchema({
|
|
130
|
+
headline: article.title,
|
|
131
|
+
description: article.excerpt,
|
|
132
|
+
image: article.coverImage,
|
|
133
|
+
datePublished: article.publishedAt,
|
|
134
|
+
authorName: article.author.name,
|
|
135
|
+
publisherName: "Your Publisher",
|
|
136
|
+
publisherLogo: "https://example.com/logo.png",
|
|
137
|
+
url: `https://example.com/articles/${article.slug}`,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<>
|
|
142
|
+
<SEO title={article.title} description={article.excerpt} />
|
|
143
|
+
<JsonLd data={schema} />
|
|
144
|
+
<article>{/* Your article content */}</article>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### International SEO (hreflang)
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { SEO } from "@umituz/web-seo";
|
|
154
|
+
|
|
155
|
+
function LocalizedPage() {
|
|
156
|
+
return (
|
|
157
|
+
<SEO
|
|
158
|
+
title="My Page"
|
|
159
|
+
hreflang={[
|
|
160
|
+
{ lang: "en", url: "https://example.com/en/page" },
|
|
161
|
+
{ lang: "tr", url: "https://example.com/tr/page" },
|
|
162
|
+
{ lang: "de", url: "https://example.com/de/page" },
|
|
163
|
+
{ lang: "x-default", url: "https://example.com/en/page" },
|
|
164
|
+
]}
|
|
165
|
+
/>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Performance Hints
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { SEO } from "@umituz/web-seo";
|
|
174
|
+
|
|
175
|
+
function PerformanceOptimizedPage() {
|
|
176
|
+
return (
|
|
177
|
+
<SEO
|
|
178
|
+
title="My Page"
|
|
179
|
+
preload={[
|
|
180
|
+
{ href: "/fonts/main.woff2", as: "font", type: "font/woff2", crossOrigin: "anonymous" },
|
|
181
|
+
{ href: "/images/hero.jpg", as: "image" },
|
|
182
|
+
]}
|
|
183
|
+
preconnect={[
|
|
184
|
+
{ href: "https://cdn.example.com", crossOrigin: "anonymous" },
|
|
185
|
+
]}
|
|
186
|
+
dnsPrefetch={[
|
|
187
|
+
{ href: "https://analytics.example.com" },
|
|
188
|
+
]}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Vite Plugin Setup
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
// vite.config.ts
|
|
198
|
+
import { defineConfig } from "vite";
|
|
199
|
+
import { viteSEOPlugin } from "@umituz/web-seo";
|
|
200
|
+
|
|
201
|
+
export default defineConfig({
|
|
202
|
+
plugins: [
|
|
203
|
+
viteSEOPlugin({
|
|
204
|
+
siteUrl: "https://example.com",
|
|
205
|
+
discoverRoutes: true,
|
|
206
|
+
sitemap: {
|
|
207
|
+
changefreq: "weekly",
|
|
208
|
+
priority: 0.8,
|
|
209
|
+
},
|
|
210
|
+
robotsTxt: {
|
|
211
|
+
disallow: ["/api", "/admin"],
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### SSR Usage
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { renderSEO, generateHead } from "@umituz/web-seo";
|
|
222
|
+
|
|
223
|
+
// On server
|
|
224
|
+
const seoOptions = {
|
|
225
|
+
title: "My Page",
|
|
226
|
+
description: "My description",
|
|
227
|
+
// ... other options
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Generate HTML head
|
|
231
|
+
const headHTML = generateHead(seoOptions);
|
|
232
|
+
|
|
233
|
+
// Or just the SEO tags
|
|
234
|
+
const seoHTML = renderSEO(seoOptions).toHTML();
|
|
235
|
+
|
|
236
|
+
// Hydrate on client
|
|
237
|
+
import { hydrateSEO } from "@umituz/web-seo";
|
|
238
|
+
hydrateSEO(JSON.stringify(seoOptions));
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Validation
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
import { validateSEO, auditSEO } from "@umituz/web-seo";
|
|
245
|
+
|
|
246
|
+
function MyPage() {
|
|
247
|
+
const seoOptions = {
|
|
248
|
+
title: "My Page",
|
|
249
|
+
description: "My description",
|
|
250
|
+
// ... other options
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// Validate in development
|
|
254
|
+
if (import.meta.env.DEV) {
|
|
255
|
+
auditSEO(seoOptions);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return <SEO {...seoOptions} />;
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## API Reference
|
|
263
|
+
|
|
264
|
+
### Components
|
|
265
|
+
|
|
266
|
+
#### `<SEO />`
|
|
267
|
+
Main SEO component for managing meta tags and SEO elements.
|
|
268
|
+
|
|
269
|
+
**Props:** `SEOptions` (see types below)
|
|
270
|
+
|
|
271
|
+
#### `<JsonLd />`
|
|
272
|
+
Component for injecting JSON-LD structured data.
|
|
273
|
+
|
|
274
|
+
**Props:**
|
|
275
|
+
- `data`: `JsonLdTypes | JsonLdTypes[]` - Schema.org data
|
|
276
|
+
- `id?`: `string` - Unique identifier
|
|
277
|
+
- `strategy?`: `"afterInteractive" | "beforeInteractive" | "idle"` - Injection strategy
|
|
278
|
+
|
|
279
|
+
### Hooks
|
|
280
|
+
|
|
281
|
+
#### `useSEO(options: SEOptions)`
|
|
282
|
+
Hook for programmatically managing SEO.
|
|
283
|
+
|
|
284
|
+
#### `useJsonLd(data: JsonLdTypes | JsonLdTypes[], options?)`
|
|
285
|
+
Hook for managing JSON-LD structured data.
|
|
286
|
+
|
|
287
|
+
### Schema Generators
|
|
288
|
+
|
|
289
|
+
- `generateArticleSchema(input)` - Article/News/Blog schema
|
|
290
|
+
- `generateProductSchema(input)` - Product schema
|
|
291
|
+
- `generateOrganizationSchema(input)` - Organization schema
|
|
292
|
+
- `generateLocalBusinessSchema(input)` - Local business schema
|
|
293
|
+
- `generateBreadcrumbSchema(items)` - Breadcrumb schema
|
|
294
|
+
- `generateFAQSchema(faqs)` - FAQ schema
|
|
295
|
+
- `generateWebSiteSchema(input)` - Website schema
|
|
296
|
+
- `generatePersonSchema(input)` - Person schema
|
|
297
|
+
- `generateVideoSchema(input)` - Video schema
|
|
298
|
+
|
|
299
|
+
### Validators
|
|
300
|
+
|
|
301
|
+
- `validateSEO(options)` - Comprehensive SEO validation
|
|
302
|
+
- `auditSEO(options)` - SEO audit with console output
|
|
303
|
+
- `isValidUrl(url)` - URL validation
|
|
304
|
+
- `validateTitleLength(title)` - Title length check
|
|
305
|
+
- `validateDescriptionLength(description)` - Description length check
|
|
306
|
+
- `validateOpenGraphImage(image, width, height, size)` - OG image validation
|
|
307
|
+
|
|
308
|
+
### SSR Functions
|
|
309
|
+
|
|
310
|
+
- `renderSEO(options)` - Render SEO to HTML strings
|
|
311
|
+
- `generateHead(options)` - Generate complete HTML head
|
|
312
|
+
- `extractSEOData(options)` - Extract data for hydration
|
|
313
|
+
- `hydrateSEO(data)` - Hydrate on client side
|
|
314
|
+
|
|
315
|
+
### Vite Plugin
|
|
316
|
+
|
|
317
|
+
#### `viteSEOPlugin(options)`
|
|
318
|
+
Vite plugin for build-time SEO optimization.
|
|
319
|
+
|
|
320
|
+
**Options:**
|
|
321
|
+
- `siteUrl`: `string` - Base URL of your site
|
|
322
|
+
- `routes?`: `string[]` - Routes to include in sitemap
|
|
323
|
+
- `discoverRoutes?`: `boolean` - Auto-discover routes
|
|
324
|
+
- `sitemap?`: `object` - Sitemap configuration
|
|
325
|
+
- `robotsTxt?`: `object` - robots.txt configuration
|
|
326
|
+
|
|
327
|
+
#### `quickSEOSetup`
|
|
328
|
+
Convenience presets:
|
|
329
|
+
- `quickSEOSetup.basic(siteUrl, routes?)`
|
|
330
|
+
- `quickSEOSetup.blog(siteUrl, routes?)`
|
|
331
|
+
- `quickSEOSetup.ecommerce(siteUrl, routes?)`
|
|
332
|
+
|
|
333
|
+
## Type Definitions
|
|
334
|
+
|
|
335
|
+
### SEOptions
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
interface SEOptions {
|
|
339
|
+
// Basic
|
|
340
|
+
title?: string;
|
|
341
|
+
titleTemplate?: string;
|
|
342
|
+
description?: string;
|
|
343
|
+
lang?: string;
|
|
344
|
+
canonical?: string;
|
|
345
|
+
|
|
346
|
+
// Robots
|
|
347
|
+
robots?: RobotsMeta | RobotsDirective[];
|
|
348
|
+
|
|
349
|
+
// Meta Tags
|
|
350
|
+
meta?: MetaTag[];
|
|
351
|
+
link?: LinkTag[];
|
|
352
|
+
|
|
353
|
+
// Open Graph
|
|
354
|
+
openGraph?: {
|
|
355
|
+
type?: "website" | "article" | "product" | "profile" | "music" | "video" | "book";
|
|
356
|
+
url?: string;
|
|
357
|
+
title?: string;
|
|
358
|
+
description?: string;
|
|
359
|
+
image?: string | OpenGraphImage[];
|
|
360
|
+
// ... more options
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// Twitter Card
|
|
364
|
+
twitter?: {
|
|
365
|
+
cardType?: "summary" | "summary_large_image" | "app" | "player";
|
|
366
|
+
site?: string;
|
|
367
|
+
handle?: string;
|
|
368
|
+
// ... more options
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// Structured Data
|
|
372
|
+
jsonLd?: JsonLdTypes[];
|
|
373
|
+
|
|
374
|
+
// International SEO
|
|
375
|
+
hreflang?: HreflangEntry[];
|
|
376
|
+
|
|
377
|
+
// Performance Hints
|
|
378
|
+
preload?: PreloadHint[];
|
|
379
|
+
preconnect?: PreconnectOrigin[];
|
|
380
|
+
dnsPrefetch?: DnsPrefetchDomain[];
|
|
381
|
+
|
|
382
|
+
// Breadcrumb
|
|
383
|
+
breadcrumbs?: BreadcrumbItem[];
|
|
384
|
+
|
|
385
|
+
// Favicon
|
|
386
|
+
favicon?: string;
|
|
387
|
+
appleTouchIcon?: string;
|
|
388
|
+
maskIcon?: string;
|
|
389
|
+
themeColor?: string;
|
|
390
|
+
|
|
391
|
+
// Viewport
|
|
392
|
+
viewport?: string;
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## Architecture
|
|
397
|
+
|
|
398
|
+
This package follows Domain-Driven Design (DDD) principles:
|
|
399
|
+
|
|
400
|
+
```
|
|
401
|
+
src/
|
|
402
|
+
βββ domains/
|
|
403
|
+
βββ seo/
|
|
404
|
+
βββ components/ # React components
|
|
405
|
+
βββ hooks/ # React hooks
|
|
406
|
+
βββ utils/ # Utility functions
|
|
407
|
+
βββ core/ # Core functionality
|
|
408
|
+
βββ types/ # TypeScript types
|
|
409
|
+
βββ vite/ # Vite plugin
|
|
410
|
+
βββ ssr/ # SSR utilities
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Examples
|
|
414
|
+
|
|
415
|
+
See the `/examples` directory for complete examples:
|
|
416
|
+
|
|
417
|
+
- Basic website
|
|
418
|
+
- Blog with structured data
|
|
419
|
+
- E-commerce site
|
|
420
|
+
- Multi-language site
|
|
421
|
+
- SSR integration
|
|
422
|
+
|
|
423
|
+
## Contributing
|
|
424
|
+
|
|
425
|
+
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
|
|
426
|
+
|
|
427
|
+
## License
|
|
428
|
+
|
|
429
|
+
MIT Β© umituz
|
|
430
|
+
|
|
431
|
+
## Support
|
|
432
|
+
|
|
433
|
+
For issues and questions, please use the GitHub issue tracker.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JsonLd Component
|
|
3
|
+
*
|
|
4
|
+
* React component for injecting JSON-LD structured data into the page.
|
|
5
|
+
* Supports all Schema.org types with automatic validation.
|
|
6
|
+
*/
|
|
7
|
+
import type { JsonLdTypes } from "../types/schema.js";
|
|
8
|
+
interface JsonLdProps {
|
|
9
|
+
data: JsonLdTypes | JsonLdTypes[];
|
|
10
|
+
/** Strategy for when to inject the script tag */
|
|
11
|
+
strategy?: "afterInteractive" | "beforeInteractive" | "idle";
|
|
12
|
+
/** Unique identifier for this JSON-LD block (for debugging) */
|
|
13
|
+
id?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const JsonLd: React.FC<JsonLdProps>;
|
|
16
|
+
export default JsonLd;
|
|
17
|
+
//# sourceMappingURL=JsonLd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonLd.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/components/JsonLd.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,UAAU,WAAW;IACnB,IAAI,EAAE,WAAW,GAAG,WAAW,EAAE,CAAC;IAClC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,MAAM,CAAC;IAC7D,+DAA+D;IAC/D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAuDxC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JsonLd Component
|
|
3
|
+
*
|
|
4
|
+
* React component for injecting JSON-LD structured data into the page.
|
|
5
|
+
* Supports all Schema.org types with automatic validation.
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
export const JsonLd = ({ data, strategy = "afterInteractive", id }) => {
|
|
9
|
+
const scriptRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (typeof document === "undefined")
|
|
12
|
+
return;
|
|
13
|
+
// Convert single object to array for uniform handling
|
|
14
|
+
const dataArray = Array.isArray(data) ? data : [data];
|
|
15
|
+
// Remove existing scripts with the same data to avoid duplicates
|
|
16
|
+
dataArray.forEach((jsonData) => {
|
|
17
|
+
const existingScript = document.querySelector(`script[type="application/ld+json"][data-seo-id="${id || JSON.stringify(jsonData)}"]`);
|
|
18
|
+
if (existingScript) {
|
|
19
|
+
existingScript.remove();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
// Create and inject new script(s)
|
|
23
|
+
dataArray.forEach((jsonData, index) => {
|
|
24
|
+
const script = document.createElement("script");
|
|
25
|
+
script.type = "application/ld+json";
|
|
26
|
+
script.textContent = JSON.stringify(jsonData);
|
|
27
|
+
// Add identifier for duplicate detection and debugging
|
|
28
|
+
if (id) {
|
|
29
|
+
script.setAttribute("data-seo-id", `${id}-${index}`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
script.setAttribute("data-seo-id", JSON.stringify(jsonData));
|
|
33
|
+
}
|
|
34
|
+
script.setAttribute("data-seo-strategy", strategy);
|
|
35
|
+
document.head.appendChild(script);
|
|
36
|
+
if (index === 0) {
|
|
37
|
+
scriptRef.current = script;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
// Cleanup function
|
|
41
|
+
return () => {
|
|
42
|
+
dataArray.forEach((jsonData, _index) => {
|
|
43
|
+
const script = document.querySelector(`script[type="application/ld+json"][data-seo-id="${id || JSON.stringify(jsonData)}"]`);
|
|
44
|
+
if (script) {
|
|
45
|
+
script.remove();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}, [data, strategy, id]);
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
export default JsonLd;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SEO.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/components/SEO.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,eAAO,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA+CnC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
2
|
+
import { updateSEO } from "../utils/dom.js";
|
|
3
|
+
export const SEO = (props) => {
|
|
4
|
+
// Memoize dependencies for better performance
|
|
5
|
+
const dependencies = useMemo(() => [
|
|
6
|
+
props.title,
|
|
7
|
+
props.description,
|
|
8
|
+
props.lang,
|
|
9
|
+
props.canonical,
|
|
10
|
+
props.themeColor,
|
|
11
|
+
props.favicon,
|
|
12
|
+
JSON.stringify(props.meta),
|
|
13
|
+
JSON.stringify(props.link),
|
|
14
|
+
JSON.stringify(props.openGraph),
|
|
15
|
+
JSON.stringify(props.twitter),
|
|
16
|
+
JSON.stringify(props.jsonLd),
|
|
17
|
+
JSON.stringify(props.hreflang),
|
|
18
|
+
JSON.stringify(props.preload),
|
|
19
|
+
JSON.stringify(props.preconnect),
|
|
20
|
+
JSON.stringify(props.dnsPrefetch),
|
|
21
|
+
JSON.stringify(props.robots),
|
|
22
|
+
JSON.stringify(props.breadcrumbs),
|
|
23
|
+
props.viewport,
|
|
24
|
+
], [
|
|
25
|
+
props.title,
|
|
26
|
+
props.description,
|
|
27
|
+
props.lang,
|
|
28
|
+
props.canonical,
|
|
29
|
+
props.themeColor,
|
|
30
|
+
props.favicon,
|
|
31
|
+
props.meta,
|
|
32
|
+
props.link,
|
|
33
|
+
props.openGraph,
|
|
34
|
+
props.twitter,
|
|
35
|
+
props.jsonLd,
|
|
36
|
+
props.hreflang,
|
|
37
|
+
props.preload,
|
|
38
|
+
props.preconnect,
|
|
39
|
+
props.dnsPrefetch,
|
|
40
|
+
props.robots,
|
|
41
|
+
props.breadcrumbs,
|
|
42
|
+
props.viewport,
|
|
43
|
+
]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
updateSEO(props);
|
|
46
|
+
}, dependencies);
|
|
47
|
+
return null; // Component does not render anything
|
|
48
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface I18nInstance {
|
|
2
|
+
language?: string;
|
|
3
|
+
t: (key: string) => string;
|
|
4
|
+
on: (event: string, callback: () => void) => void;
|
|
5
|
+
}
|
|
6
|
+
interface SEOConfig {
|
|
7
|
+
i18n?: I18nInstance;
|
|
8
|
+
titleKey?: string;
|
|
9
|
+
descriptionKey?: string;
|
|
10
|
+
defaultImage?: string;
|
|
11
|
+
canonicalPrefix?: string;
|
|
12
|
+
twitterHandle?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const initSEO: (config: SEOConfig) => void;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/core/init.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CACnD;AAED,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,OAAO,GAAI,QAAQ,SAAS,SAmCxC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { updateSEO } from "../utils/dom.js";
|
|
2
|
+
export const initSEO = (config) => {
|
|
3
|
+
if (typeof window === "undefined")
|
|
4
|
+
return;
|
|
5
|
+
const update = () => {
|
|
6
|
+
const lang = config.i18n?.language?.split("-")[0] || "en";
|
|
7
|
+
const title = config.i18n ? config.i18n.t(config.titleKey || "app.title") : document.title;
|
|
8
|
+
const description = config.i18n ? config.i18n.t(config.descriptionKey || "app.description") : "";
|
|
9
|
+
const canonical = config.canonicalPrefix ? `${config.canonicalPrefix}/${lang}` : undefined;
|
|
10
|
+
updateSEO({
|
|
11
|
+
title,
|
|
12
|
+
description,
|
|
13
|
+
lang,
|
|
14
|
+
canonical,
|
|
15
|
+
openGraph: {
|
|
16
|
+
title,
|
|
17
|
+
description,
|
|
18
|
+
type: "website",
|
|
19
|
+
image: config.defaultImage,
|
|
20
|
+
url: canonical,
|
|
21
|
+
},
|
|
22
|
+
twitter: {
|
|
23
|
+
cardType: "summary_large_image",
|
|
24
|
+
site: config.twitterHandle,
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
// Initial call
|
|
29
|
+
update();
|
|
30
|
+
// Listen for language changes if i18next is provided
|
|
31
|
+
if (config.i18n && typeof config.i18n.on === "function") {
|
|
32
|
+
config.i18n.on("languageChanged", update);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useJsonLd Hook
|
|
3
|
+
*
|
|
4
|
+
* React hook for managing JSON-LD structured data.
|
|
5
|
+
* Provides a programmatic way to add/update/remove structured data.
|
|
6
|
+
*/
|
|
7
|
+
import type { JsonLdTypes } from "../types/schema.js";
|
|
8
|
+
interface UseJsonLdOptions {
|
|
9
|
+
/** Strategy for when to inject the script tag */
|
|
10
|
+
strategy?: "afterInteractive" | "beforeInteractive" | "idle";
|
|
11
|
+
/** Unique identifier for this JSON-LD block */
|
|
12
|
+
id?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const useJsonLd: (data: JsonLdTypes | JsonLdTypes[], options?: UseJsonLdOptions) => {
|
|
15
|
+
injectJsonLd: (jsonData: JsonLdTypes | JsonLdTypes[]) => void;
|
|
16
|
+
removeJsonLd: () => void;
|
|
17
|
+
};
|
|
18
|
+
export default useJsonLd;
|
|
19
|
+
//# sourceMappingURL=useJsonLd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useJsonLd.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/hooks/useJsonLd.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,UAAU,gBAAgB;IACxB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,kBAAkB,GAAG,mBAAmB,GAAG,MAAM,CAAC;IAC7D,+CAA+C;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,SAAS,GAAI,MAAM,WAAW,GAAG,WAAW,EAAE,EAAE,UAAU,gBAAgB;6BAGzC,WAAW,GAAG,WAAW,EAAE;;CAqDxE,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useJsonLd Hook
|
|
3
|
+
*
|
|
4
|
+
* React hook for managing JSON-LD structured data.
|
|
5
|
+
* Provides a programmatic way to add/update/remove structured data.
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useCallback } from "react";
|
|
8
|
+
export const useJsonLd = (data, options) => {
|
|
9
|
+
const { strategy = "afterInteractive", id } = options || {};
|
|
10
|
+
const injectJsonLd = useCallback((jsonData) => {
|
|
11
|
+
if (typeof document === "undefined")
|
|
12
|
+
return;
|
|
13
|
+
const dataArray = Array.isArray(jsonData) ? jsonData : [jsonData];
|
|
14
|
+
dataArray.forEach((item, index) => {
|
|
15
|
+
// Remove existing script if present
|
|
16
|
+
const existingScript = document.querySelector(`script[type="application/ld+json"][data-seo-id="${id || JSON.stringify(item)}"]`);
|
|
17
|
+
if (existingScript) {
|
|
18
|
+
existingScript.remove();
|
|
19
|
+
}
|
|
20
|
+
// Create and inject new script
|
|
21
|
+
const script = document.createElement("script");
|
|
22
|
+
script.type = "application/ld+json";
|
|
23
|
+
script.textContent = JSON.stringify(item);
|
|
24
|
+
if (id) {
|
|
25
|
+
script.setAttribute("data-seo-id", `${id}-${index}`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
script.setAttribute("data-seo-id", JSON.stringify(item));
|
|
29
|
+
}
|
|
30
|
+
script.setAttribute("data-seo-strategy", strategy);
|
|
31
|
+
document.head.appendChild(script);
|
|
32
|
+
});
|
|
33
|
+
}, [id, strategy]);
|
|
34
|
+
const removeJsonLd = useCallback(() => {
|
|
35
|
+
if (typeof document === "undefined")
|
|
36
|
+
return;
|
|
37
|
+
const scripts = document.querySelectorAll(`script[type="application/ld+json"][data-seo-id*="${id || ''}"]`);
|
|
38
|
+
scripts.forEach((script) => script.remove());
|
|
39
|
+
}, [id]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (data) {
|
|
42
|
+
injectJsonLd(data);
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
removeJsonLd();
|
|
46
|
+
};
|
|
47
|
+
}, [data, injectJsonLd, removeJsonLd]);
|
|
48
|
+
return {
|
|
49
|
+
injectJsonLd,
|
|
50
|
+
removeJsonLd,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export default useJsonLd;
|