@masters-ws/react-seo 1.0.0 → 1.2.0

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.
@@ -0,0 +1,362 @@
1
+ interface SiteConfig {
2
+ name: string;
3
+ description: string;
4
+ url: string;
5
+ logo?: string;
6
+ publisher?: string;
7
+ twitterHandle?: string;
8
+ facebookAppId?: string;
9
+ language?: string;
10
+ socialLinks?: string[];
11
+ googleAnalyticsId?: string;
12
+ gtmId?: string;
13
+ facebookPixelId?: string;
14
+ yandexMetricaId?: string;
15
+ themeColor?: string;
16
+ manifest?: string;
17
+ }
18
+ interface SEOData {
19
+ title?: string;
20
+ description?: string;
21
+ image?: string;
22
+ canonical?: string;
23
+ type?: 'website' | 'article' | 'product' | 'profile' | 'video' | 'faq';
24
+ robots?: string;
25
+ noindex?: boolean;
26
+ keywords?: string[];
27
+ prev?: string;
28
+ next?: string;
29
+ alternates?: Array<{
30
+ hreflang: string;
31
+ href: string;
32
+ }>;
33
+ ogTitle?: string;
34
+ ogDescription?: string;
35
+ ogImage?: string;
36
+ ogType?: string;
37
+ ogLocale?: string;
38
+ twitterCard?: 'summary' | 'summary_large_image' | 'app' | 'player';
39
+ twitterTitle?: string;
40
+ twitterDescription?: string;
41
+ twitterImage?: string;
42
+ publishedTime?: string;
43
+ modifiedTime?: string;
44
+ author?: {
45
+ name: string;
46
+ url?: string;
47
+ image?: string;
48
+ };
49
+ tags?: string[];
50
+ section?: string;
51
+ readingTime?: number;
52
+ product?: {
53
+ sku?: string;
54
+ brand?: string;
55
+ price?: number;
56
+ currency?: string;
57
+ availability?: string;
58
+ rating?: number;
59
+ reviewCount?: number;
60
+ };
61
+ dnsPrefetch?: string[];
62
+ preconnect?: string[];
63
+ prefetch?: string[];
64
+ preload?: Array<{
65
+ href: string;
66
+ as: string;
67
+ type?: string;
68
+ }>;
69
+ whatsappImage?: string;
70
+ whatsappDescription?: string;
71
+ schema?: any;
72
+ }
73
+ interface BreadcrumbItem {
74
+ name: string;
75
+ item: string;
76
+ }
77
+
78
+ /**
79
+ * Generate Organization Schema
80
+ */
81
+ declare function generateOrganizationSchema(config: SiteConfig): {
82
+ "@context": string;
83
+ "@type": string;
84
+ name: string;
85
+ url: string;
86
+ logo: string | undefined;
87
+ sameAs: string[];
88
+ };
89
+ /**
90
+ * Generate WebSite Schema with SearchAction
91
+ */
92
+ declare function generateWebSiteSchema(config: SiteConfig): {
93
+ "@context": string;
94
+ "@type": string;
95
+ name: string;
96
+ url: string;
97
+ potentialAction: {
98
+ "@type": string;
99
+ target: string;
100
+ "query-input": string;
101
+ };
102
+ };
103
+ /**
104
+ * Generate NewsArticle Schema
105
+ */
106
+ declare function generateArticleSchema(data: {
107
+ title: string;
108
+ description: string;
109
+ image?: string;
110
+ publishedTime?: string;
111
+ modifiedTime?: string;
112
+ author?: {
113
+ name: string;
114
+ url?: string;
115
+ };
116
+ url?: string;
117
+ }, config: SiteConfig): {
118
+ "@context": string;
119
+ "@type": string;
120
+ headline: string;
121
+ description: string;
122
+ image: string | undefined;
123
+ datePublished: string | undefined;
124
+ dateModified: string | undefined;
125
+ mainEntityOfPage: string | undefined;
126
+ author: {
127
+ "@context": string;
128
+ "@type": string;
129
+ name: string;
130
+ url: string;
131
+ logo: string | undefined;
132
+ sameAs: string[];
133
+ } | {
134
+ "@type": string;
135
+ name: string;
136
+ url: string | undefined;
137
+ };
138
+ publisher: {
139
+ "@context": string;
140
+ "@type": string;
141
+ name: string;
142
+ url: string;
143
+ logo: string | undefined;
144
+ sameAs: string[];
145
+ };
146
+ };
147
+ /**
148
+ * Generate Product Schema
149
+ */
150
+ declare function generateProductSchema(data: {
151
+ name: string;
152
+ description: string;
153
+ image?: string;
154
+ sku?: string;
155
+ brand?: string;
156
+ price?: number;
157
+ currency?: string;
158
+ availability?: string;
159
+ rating?: number;
160
+ reviewCount?: number;
161
+ url?: string;
162
+ }): {
163
+ "@context": string;
164
+ "@type": string;
165
+ name: string;
166
+ description: string;
167
+ image: string | undefined;
168
+ sku: string | undefined;
169
+ brand: {
170
+ "@type": string;
171
+ name: string;
172
+ } | undefined;
173
+ offers: {
174
+ "@type": string;
175
+ url: string | undefined;
176
+ priceCurrency: string;
177
+ price: number | undefined;
178
+ availability: string;
179
+ };
180
+ aggregateRating: {
181
+ "@type": string;
182
+ ratingValue: number;
183
+ reviewCount: number;
184
+ } | undefined;
185
+ };
186
+ /**
187
+ * Generate FAQ Schema
188
+ */
189
+ declare function generateFAQSchema(questions: Array<{
190
+ q: string;
191
+ a: string;
192
+ }>): {
193
+ "@context": string;
194
+ "@type": string;
195
+ mainEntity: {
196
+ "@type": string;
197
+ name: string;
198
+ acceptedAnswer: {
199
+ "@type": string;
200
+ text: string;
201
+ };
202
+ }[];
203
+ };
204
+ /**
205
+ * Generate Breadcrumb Schema
206
+ */
207
+ declare function generateBreadcrumbSchema(items: Array<{
208
+ name: string;
209
+ item: string;
210
+ }>): {
211
+ "@context": string;
212
+ "@type": string;
213
+ itemListElement: {
214
+ "@type": string;
215
+ position: number;
216
+ name: string;
217
+ item: string;
218
+ }[];
219
+ };
220
+ /**
221
+ * Generate Video Schema
222
+ */
223
+ declare function generateVideoSchema(data: {
224
+ name: string;
225
+ description: string;
226
+ thumbnailUrl: string;
227
+ uploadDate: string;
228
+ duration?: string;
229
+ contentUrl?: string;
230
+ embedUrl?: string;
231
+ }): {
232
+ "@context": string;
233
+ "@type": string;
234
+ name: string;
235
+ description: string;
236
+ thumbnailUrl: string;
237
+ uploadDate: string;
238
+ duration: string | undefined;
239
+ contentUrl: string | undefined;
240
+ embedUrl: string | undefined;
241
+ };
242
+ /**
243
+ * Generate Event Schema
244
+ */
245
+ declare function generateEventSchema(data: {
246
+ name: string;
247
+ description: string;
248
+ startDate: string;
249
+ endDate?: string;
250
+ location?: {
251
+ name: string;
252
+ address: string;
253
+ } | {
254
+ url: string;
255
+ };
256
+ image?: string;
257
+ offers?: {
258
+ price: number;
259
+ currency: string;
260
+ url: string;
261
+ };
262
+ }): {
263
+ "@context": string;
264
+ "@type": string;
265
+ name: string;
266
+ description: string;
267
+ startDate: string;
268
+ endDate: string | undefined;
269
+ eventAttendanceMode: string;
270
+ location: {
271
+ "@type": string;
272
+ url: string;
273
+ name?: undefined;
274
+ address?: undefined;
275
+ } | {
276
+ "@type": string;
277
+ name: string;
278
+ address: string;
279
+ url?: undefined;
280
+ } | undefined;
281
+ image: string | undefined;
282
+ offers: {
283
+ "@type": string;
284
+ price: number;
285
+ priceCurrency: string;
286
+ url: string;
287
+ } | undefined;
288
+ };
289
+ /**
290
+ * Generate LocalBusiness Schema
291
+ */
292
+ declare function generateLocalBusinessSchema(data: {
293
+ name: string;
294
+ description: string;
295
+ image?: string;
296
+ telephone?: string;
297
+ address: {
298
+ street: string;
299
+ city: string;
300
+ region?: string;
301
+ postalCode?: string;
302
+ country: string;
303
+ };
304
+ geo?: {
305
+ lat: number;
306
+ lng: number;
307
+ };
308
+ openingHours?: string[];
309
+ priceRange?: string;
310
+ }): {
311
+ "@context": string;
312
+ "@type": string;
313
+ name: string;
314
+ description: string;
315
+ image: string | undefined;
316
+ telephone: string | undefined;
317
+ address: {
318
+ "@type": string;
319
+ streetAddress: string;
320
+ addressLocality: string;
321
+ addressRegion: string | undefined;
322
+ postalCode: string | undefined;
323
+ addressCountry: string;
324
+ };
325
+ geo: {
326
+ "@type": string;
327
+ latitude: number;
328
+ longitude: number;
329
+ } | undefined;
330
+ openingHours: string[] | undefined;
331
+ priceRange: string | undefined;
332
+ };
333
+
334
+ /**
335
+ * Converts SEOData and SiteConfig to a Next.js compatible Metadata object.
336
+ * This is designed to be used in Server Components (App Router).
337
+ *
338
+ * @example
339
+ * // In page.tsx
340
+ * import { toNextMetadata } from '@masters-ws/react-seo';
341
+ *
342
+ * export async function generateMetadata({ params }) {
343
+ * const post = await getPost(params.id);
344
+ * return toNextMetadata({ title: post.title, ... }, siteConfig);
345
+ * }
346
+ */
347
+ declare function toNextMetadata(props: SEOData, config: SiteConfig): any;
348
+ /**
349
+ * Generates pagination links for category/tag pages.
350
+ * Returns { prev, next, canonical } URLs.
351
+ */
352
+ declare function generatePaginationLinks(baseUrl: string, currentPage: number, totalPages: number): {
353
+ next: string | undefined;
354
+ prev: string | undefined;
355
+ canonical: string;
356
+ };
357
+ /**
358
+ * Generates title with page number suffix for paginated pages.
359
+ */
360
+ declare function generatePaginatedTitle(title: string, page: number, suffix?: string): string;
361
+
362
+ export { type BreadcrumbItem as B, type SiteConfig as S, type SEOData as a, generateBreadcrumbSchema as b, generateEventSchema as c, generateFAQSchema as d, generateLocalBusinessSchema as e, generateOrganizationSchema as f, generateArticleSchema as g, generatePaginatedTitle as h, generatePaginationLinks as i, generateProductSchema as j, generateVideoSchema as k, generateWebSiteSchema as l, toNextMetadata as t };
@@ -0,0 +1,362 @@
1
+ interface SiteConfig {
2
+ name: string;
3
+ description: string;
4
+ url: string;
5
+ logo?: string;
6
+ publisher?: string;
7
+ twitterHandle?: string;
8
+ facebookAppId?: string;
9
+ language?: string;
10
+ socialLinks?: string[];
11
+ googleAnalyticsId?: string;
12
+ gtmId?: string;
13
+ facebookPixelId?: string;
14
+ yandexMetricaId?: string;
15
+ themeColor?: string;
16
+ manifest?: string;
17
+ }
18
+ interface SEOData {
19
+ title?: string;
20
+ description?: string;
21
+ image?: string;
22
+ canonical?: string;
23
+ type?: 'website' | 'article' | 'product' | 'profile' | 'video' | 'faq';
24
+ robots?: string;
25
+ noindex?: boolean;
26
+ keywords?: string[];
27
+ prev?: string;
28
+ next?: string;
29
+ alternates?: Array<{
30
+ hreflang: string;
31
+ href: string;
32
+ }>;
33
+ ogTitle?: string;
34
+ ogDescription?: string;
35
+ ogImage?: string;
36
+ ogType?: string;
37
+ ogLocale?: string;
38
+ twitterCard?: 'summary' | 'summary_large_image' | 'app' | 'player';
39
+ twitterTitle?: string;
40
+ twitterDescription?: string;
41
+ twitterImage?: string;
42
+ publishedTime?: string;
43
+ modifiedTime?: string;
44
+ author?: {
45
+ name: string;
46
+ url?: string;
47
+ image?: string;
48
+ };
49
+ tags?: string[];
50
+ section?: string;
51
+ readingTime?: number;
52
+ product?: {
53
+ sku?: string;
54
+ brand?: string;
55
+ price?: number;
56
+ currency?: string;
57
+ availability?: string;
58
+ rating?: number;
59
+ reviewCount?: number;
60
+ };
61
+ dnsPrefetch?: string[];
62
+ preconnect?: string[];
63
+ prefetch?: string[];
64
+ preload?: Array<{
65
+ href: string;
66
+ as: string;
67
+ type?: string;
68
+ }>;
69
+ whatsappImage?: string;
70
+ whatsappDescription?: string;
71
+ schema?: any;
72
+ }
73
+ interface BreadcrumbItem {
74
+ name: string;
75
+ item: string;
76
+ }
77
+
78
+ /**
79
+ * Generate Organization Schema
80
+ */
81
+ declare function generateOrganizationSchema(config: SiteConfig): {
82
+ "@context": string;
83
+ "@type": string;
84
+ name: string;
85
+ url: string;
86
+ logo: string | undefined;
87
+ sameAs: string[];
88
+ };
89
+ /**
90
+ * Generate WebSite Schema with SearchAction
91
+ */
92
+ declare function generateWebSiteSchema(config: SiteConfig): {
93
+ "@context": string;
94
+ "@type": string;
95
+ name: string;
96
+ url: string;
97
+ potentialAction: {
98
+ "@type": string;
99
+ target: string;
100
+ "query-input": string;
101
+ };
102
+ };
103
+ /**
104
+ * Generate NewsArticle Schema
105
+ */
106
+ declare function generateArticleSchema(data: {
107
+ title: string;
108
+ description: string;
109
+ image?: string;
110
+ publishedTime?: string;
111
+ modifiedTime?: string;
112
+ author?: {
113
+ name: string;
114
+ url?: string;
115
+ };
116
+ url?: string;
117
+ }, config: SiteConfig): {
118
+ "@context": string;
119
+ "@type": string;
120
+ headline: string;
121
+ description: string;
122
+ image: string | undefined;
123
+ datePublished: string | undefined;
124
+ dateModified: string | undefined;
125
+ mainEntityOfPage: string | undefined;
126
+ author: {
127
+ "@context": string;
128
+ "@type": string;
129
+ name: string;
130
+ url: string;
131
+ logo: string | undefined;
132
+ sameAs: string[];
133
+ } | {
134
+ "@type": string;
135
+ name: string;
136
+ url: string | undefined;
137
+ };
138
+ publisher: {
139
+ "@context": string;
140
+ "@type": string;
141
+ name: string;
142
+ url: string;
143
+ logo: string | undefined;
144
+ sameAs: string[];
145
+ };
146
+ };
147
+ /**
148
+ * Generate Product Schema
149
+ */
150
+ declare function generateProductSchema(data: {
151
+ name: string;
152
+ description: string;
153
+ image?: string;
154
+ sku?: string;
155
+ brand?: string;
156
+ price?: number;
157
+ currency?: string;
158
+ availability?: string;
159
+ rating?: number;
160
+ reviewCount?: number;
161
+ url?: string;
162
+ }): {
163
+ "@context": string;
164
+ "@type": string;
165
+ name: string;
166
+ description: string;
167
+ image: string | undefined;
168
+ sku: string | undefined;
169
+ brand: {
170
+ "@type": string;
171
+ name: string;
172
+ } | undefined;
173
+ offers: {
174
+ "@type": string;
175
+ url: string | undefined;
176
+ priceCurrency: string;
177
+ price: number | undefined;
178
+ availability: string;
179
+ };
180
+ aggregateRating: {
181
+ "@type": string;
182
+ ratingValue: number;
183
+ reviewCount: number;
184
+ } | undefined;
185
+ };
186
+ /**
187
+ * Generate FAQ Schema
188
+ */
189
+ declare function generateFAQSchema(questions: Array<{
190
+ q: string;
191
+ a: string;
192
+ }>): {
193
+ "@context": string;
194
+ "@type": string;
195
+ mainEntity: {
196
+ "@type": string;
197
+ name: string;
198
+ acceptedAnswer: {
199
+ "@type": string;
200
+ text: string;
201
+ };
202
+ }[];
203
+ };
204
+ /**
205
+ * Generate Breadcrumb Schema
206
+ */
207
+ declare function generateBreadcrumbSchema(items: Array<{
208
+ name: string;
209
+ item: string;
210
+ }>): {
211
+ "@context": string;
212
+ "@type": string;
213
+ itemListElement: {
214
+ "@type": string;
215
+ position: number;
216
+ name: string;
217
+ item: string;
218
+ }[];
219
+ };
220
+ /**
221
+ * Generate Video Schema
222
+ */
223
+ declare function generateVideoSchema(data: {
224
+ name: string;
225
+ description: string;
226
+ thumbnailUrl: string;
227
+ uploadDate: string;
228
+ duration?: string;
229
+ contentUrl?: string;
230
+ embedUrl?: string;
231
+ }): {
232
+ "@context": string;
233
+ "@type": string;
234
+ name: string;
235
+ description: string;
236
+ thumbnailUrl: string;
237
+ uploadDate: string;
238
+ duration: string | undefined;
239
+ contentUrl: string | undefined;
240
+ embedUrl: string | undefined;
241
+ };
242
+ /**
243
+ * Generate Event Schema
244
+ */
245
+ declare function generateEventSchema(data: {
246
+ name: string;
247
+ description: string;
248
+ startDate: string;
249
+ endDate?: string;
250
+ location?: {
251
+ name: string;
252
+ address: string;
253
+ } | {
254
+ url: string;
255
+ };
256
+ image?: string;
257
+ offers?: {
258
+ price: number;
259
+ currency: string;
260
+ url: string;
261
+ };
262
+ }): {
263
+ "@context": string;
264
+ "@type": string;
265
+ name: string;
266
+ description: string;
267
+ startDate: string;
268
+ endDate: string | undefined;
269
+ eventAttendanceMode: string;
270
+ location: {
271
+ "@type": string;
272
+ url: string;
273
+ name?: undefined;
274
+ address?: undefined;
275
+ } | {
276
+ "@type": string;
277
+ name: string;
278
+ address: string;
279
+ url?: undefined;
280
+ } | undefined;
281
+ image: string | undefined;
282
+ offers: {
283
+ "@type": string;
284
+ price: number;
285
+ priceCurrency: string;
286
+ url: string;
287
+ } | undefined;
288
+ };
289
+ /**
290
+ * Generate LocalBusiness Schema
291
+ */
292
+ declare function generateLocalBusinessSchema(data: {
293
+ name: string;
294
+ description: string;
295
+ image?: string;
296
+ telephone?: string;
297
+ address: {
298
+ street: string;
299
+ city: string;
300
+ region?: string;
301
+ postalCode?: string;
302
+ country: string;
303
+ };
304
+ geo?: {
305
+ lat: number;
306
+ lng: number;
307
+ };
308
+ openingHours?: string[];
309
+ priceRange?: string;
310
+ }): {
311
+ "@context": string;
312
+ "@type": string;
313
+ name: string;
314
+ description: string;
315
+ image: string | undefined;
316
+ telephone: string | undefined;
317
+ address: {
318
+ "@type": string;
319
+ streetAddress: string;
320
+ addressLocality: string;
321
+ addressRegion: string | undefined;
322
+ postalCode: string | undefined;
323
+ addressCountry: string;
324
+ };
325
+ geo: {
326
+ "@type": string;
327
+ latitude: number;
328
+ longitude: number;
329
+ } | undefined;
330
+ openingHours: string[] | undefined;
331
+ priceRange: string | undefined;
332
+ };
333
+
334
+ /**
335
+ * Converts SEOData and SiteConfig to a Next.js compatible Metadata object.
336
+ * This is designed to be used in Server Components (App Router).
337
+ *
338
+ * @example
339
+ * // In page.tsx
340
+ * import { toNextMetadata } from '@masters-ws/react-seo';
341
+ *
342
+ * export async function generateMetadata({ params }) {
343
+ * const post = await getPost(params.id);
344
+ * return toNextMetadata({ title: post.title, ... }, siteConfig);
345
+ * }
346
+ */
347
+ declare function toNextMetadata(props: SEOData, config: SiteConfig): any;
348
+ /**
349
+ * Generates pagination links for category/tag pages.
350
+ * Returns { prev, next, canonical } URLs.
351
+ */
352
+ declare function generatePaginationLinks(baseUrl: string, currentPage: number, totalPages: number): {
353
+ next: string | undefined;
354
+ prev: string | undefined;
355
+ canonical: string;
356
+ };
357
+ /**
358
+ * Generates title with page number suffix for paginated pages.
359
+ */
360
+ declare function generatePaginatedTitle(title: string, page: number, suffix?: string): string;
361
+
362
+ export { type BreadcrumbItem as B, type SiteConfig as S, type SEOData as a, generateBreadcrumbSchema as b, generateEventSchema as c, generateFAQSchema as d, generateLocalBusinessSchema as e, generateOrganizationSchema as f, generateArticleSchema as g, generatePaginatedTitle as h, generatePaginationLinks as i, generateProductSchema as j, generateVideoSchema as k, generateWebSiteSchema as l, toNextMetadata as t };