@masters-ws/react-seo 1.0.0 → 1.1.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,272 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core/index.ts
21
+ var core_exports = {};
22
+ __export(core_exports, {
23
+ generateArticleSchema: () => generateArticleSchema,
24
+ generateBreadcrumbSchema: () => generateBreadcrumbSchema,
25
+ generateEventSchema: () => generateEventSchema,
26
+ generateFAQSchema: () => generateFAQSchema,
27
+ generateLocalBusinessSchema: () => generateLocalBusinessSchema,
28
+ generateOrganizationSchema: () => generateOrganizationSchema,
29
+ generatePaginatedTitle: () => generatePaginatedTitle,
30
+ generatePaginationLinks: () => generatePaginationLinks,
31
+ generateProductSchema: () => generateProductSchema,
32
+ generateVideoSchema: () => generateVideoSchema,
33
+ generateWebSiteSchema: () => generateWebSiteSchema,
34
+ toNextMetadata: () => toNextMetadata
35
+ });
36
+ module.exports = __toCommonJS(core_exports);
37
+
38
+ // src/core/schemas.ts
39
+ function generateOrganizationSchema(config) {
40
+ return {
41
+ "@context": "https://schema.org",
42
+ "@type": "Organization",
43
+ "name": config.name,
44
+ "url": config.url,
45
+ "logo": config.logo,
46
+ "sameAs": config.socialLinks || []
47
+ };
48
+ }
49
+ function generateWebSiteSchema(config) {
50
+ return {
51
+ "@context": "https://schema.org",
52
+ "@type": "WebSite",
53
+ "name": config.name,
54
+ "url": config.url,
55
+ "potentialAction": {
56
+ "@type": "SearchAction",
57
+ "target": `${config.url}/search?q={search_term_string}`,
58
+ "query-input": "required name=search_term_string"
59
+ }
60
+ };
61
+ }
62
+ function generateArticleSchema(data, config) {
63
+ const org = generateOrganizationSchema(config);
64
+ return {
65
+ "@context": "https://schema.org",
66
+ "@type": "NewsArticle",
67
+ "headline": data.title,
68
+ "description": data.description,
69
+ "image": data.image || config.logo,
70
+ "datePublished": data.publishedTime,
71
+ "dateModified": data.modifiedTime || data.publishedTime,
72
+ "mainEntityOfPage": data.url,
73
+ "author": data.author ? {
74
+ "@type": "Person",
75
+ "name": data.author.name,
76
+ "url": data.author.url
77
+ } : org,
78
+ "publisher": org
79
+ };
80
+ }
81
+ function generateProductSchema(data) {
82
+ return {
83
+ "@context": "https://schema.org",
84
+ "@type": "Product",
85
+ "name": data.name,
86
+ "description": data.description,
87
+ "image": data.image,
88
+ "sku": data.sku,
89
+ "brand": data.brand ? { "@type": "Brand", "name": data.brand } : void 0,
90
+ "offers": {
91
+ "@type": "Offer",
92
+ "url": data.url,
93
+ "priceCurrency": data.currency || "USD",
94
+ "price": data.price,
95
+ "availability": data.availability || "https://schema.org/InStock"
96
+ },
97
+ "aggregateRating": data.rating ? {
98
+ "@type": "AggregateRating",
99
+ "ratingValue": data.rating,
100
+ "reviewCount": data.reviewCount || 1
101
+ } : void 0
102
+ };
103
+ }
104
+ function generateFAQSchema(questions) {
105
+ return {
106
+ "@context": "https://schema.org",
107
+ "@type": "FAQPage",
108
+ "mainEntity": questions.map((item) => ({
109
+ "@type": "Question",
110
+ "name": item.q,
111
+ "acceptedAnswer": {
112
+ "@type": "Answer",
113
+ "text": item.a
114
+ }
115
+ }))
116
+ };
117
+ }
118
+ function generateBreadcrumbSchema(items) {
119
+ return {
120
+ "@context": "https://schema.org",
121
+ "@type": "BreadcrumbList",
122
+ "itemListElement": items.map((item, index) => ({
123
+ "@type": "ListItem",
124
+ "position": index + 1,
125
+ "name": item.name,
126
+ "item": item.item
127
+ }))
128
+ };
129
+ }
130
+ function generateVideoSchema(data) {
131
+ return {
132
+ "@context": "https://schema.org",
133
+ "@type": "VideoObject",
134
+ "name": data.name,
135
+ "description": data.description,
136
+ "thumbnailUrl": data.thumbnailUrl,
137
+ "uploadDate": data.uploadDate,
138
+ "duration": data.duration,
139
+ "contentUrl": data.contentUrl,
140
+ "embedUrl": data.embedUrl
141
+ };
142
+ }
143
+ function generateEventSchema(data) {
144
+ const isOnline = data.location && "url" in data.location;
145
+ return {
146
+ "@context": "https://schema.org",
147
+ "@type": "Event",
148
+ "name": data.name,
149
+ "description": data.description,
150
+ "startDate": data.startDate,
151
+ "endDate": data.endDate,
152
+ "eventAttendanceMode": isOnline ? "https://schema.org/OnlineEventAttendanceMode" : "https://schema.org/OfflineEventAttendanceMode",
153
+ "location": isOnline ? {
154
+ "@type": "VirtualLocation",
155
+ "url": data.location.url
156
+ } : data.location ? {
157
+ "@type": "Place",
158
+ "name": data.location.name,
159
+ "address": data.location.address
160
+ } : void 0,
161
+ "image": data.image,
162
+ "offers": data.offers ? {
163
+ "@type": "Offer",
164
+ "price": data.offers.price,
165
+ "priceCurrency": data.offers.currency,
166
+ "url": data.offers.url
167
+ } : void 0
168
+ };
169
+ }
170
+ function generateLocalBusinessSchema(data) {
171
+ return {
172
+ "@context": "https://schema.org",
173
+ "@type": "LocalBusiness",
174
+ "name": data.name,
175
+ "description": data.description,
176
+ "image": data.image,
177
+ "telephone": data.telephone,
178
+ "address": {
179
+ "@type": "PostalAddress",
180
+ "streetAddress": data.address.street,
181
+ "addressLocality": data.address.city,
182
+ "addressRegion": data.address.region,
183
+ "postalCode": data.address.postalCode,
184
+ "addressCountry": data.address.country
185
+ },
186
+ "geo": data.geo ? {
187
+ "@type": "GeoCoordinates",
188
+ "latitude": data.geo.lat,
189
+ "longitude": data.geo.lng
190
+ } : void 0,
191
+ "openingHours": data.openingHours,
192
+ "priceRange": data.priceRange
193
+ };
194
+ }
195
+
196
+ // src/core/metadata.ts
197
+ function toNextMetadata(props, config) {
198
+ const title = props.title ? `${props.title} | ${config.name}` : config.name;
199
+ const description = props.description || config.description;
200
+ const url = props.canonical || config.url;
201
+ const image = props.image || config.logo;
202
+ const metadata = {
203
+ title,
204
+ description,
205
+ keywords: props.keywords,
206
+ robots: props.noindex ? "noindex, nofollow" : props.robots || "index, follow",
207
+ alternates: {
208
+ canonical: props.noindex ? void 0 : url
209
+ },
210
+ openGraph: {
211
+ title: props.ogTitle || title,
212
+ description: props.ogDescription || description,
213
+ url,
214
+ siteName: config.name,
215
+ images: props.ogImage || image ? [{ url: props.ogImage || image }] : [],
216
+ type: props.ogType || (props.type === "article" ? "article" : "website"),
217
+ locale: props.ogLocale || config.language || "ar_SA"
218
+ },
219
+ twitter: {
220
+ card: props.twitterCard || "summary_large_image",
221
+ title: props.twitterTitle || title,
222
+ description: props.twitterDescription || description,
223
+ images: props.twitterImage || image ? [props.twitterImage || image] : [],
224
+ site: config.twitterHandle,
225
+ creator: config.twitterHandle
226
+ },
227
+ other: {}
228
+ };
229
+ if (props.alternates && props.alternates.length > 0) {
230
+ const languages = {};
231
+ props.alternates.forEach((alt) => {
232
+ languages[alt.hreflang] = alt.href;
233
+ });
234
+ metadata.alternates.languages = languages;
235
+ }
236
+ metadata.appleWebApp = {
237
+ capable: true,
238
+ title: config.name,
239
+ statusBarStyle: "default"
240
+ };
241
+ if (config.themeColor) metadata.themeColor = config.themeColor;
242
+ if (config.manifest) metadata.manifest = config.manifest;
243
+ return metadata;
244
+ }
245
+ function generatePaginationLinks(baseUrl, currentPage, totalPages) {
246
+ const hasNext = currentPage < totalPages;
247
+ const hasPrev = currentPage > 1;
248
+ const cleanBase = baseUrl.split("?")[0];
249
+ return {
250
+ next: hasNext ? `${cleanBase}?page=${currentPage + 1}` : void 0,
251
+ prev: hasPrev ? currentPage === 2 ? cleanBase : `${cleanBase}?page=${currentPage - 1}` : void 0,
252
+ canonical: currentPage === 1 ? cleanBase : `${cleanBase}?page=${currentPage}`
253
+ };
254
+ }
255
+ function generatePaginatedTitle(title, page, suffix = "\u0635\u0641\u062D\u0629") {
256
+ return page > 1 ? `${title} - ${suffix} ${page}` : title;
257
+ }
258
+ // Annotate the CommonJS export names for ESM import in node:
259
+ 0 && (module.exports = {
260
+ generateArticleSchema,
261
+ generateBreadcrumbSchema,
262
+ generateEventSchema,
263
+ generateFAQSchema,
264
+ generateLocalBusinessSchema,
265
+ generateOrganizationSchema,
266
+ generatePaginatedTitle,
267
+ generatePaginationLinks,
268
+ generateProductSchema,
269
+ generateVideoSchema,
270
+ generateWebSiteSchema,
271
+ toNextMetadata
272
+ });
@@ -0,0 +1,28 @@
1
+ import {
2
+ generateArticleSchema,
3
+ generateBreadcrumbSchema,
4
+ generateEventSchema,
5
+ generateFAQSchema,
6
+ generateLocalBusinessSchema,
7
+ generateOrganizationSchema,
8
+ generatePaginatedTitle,
9
+ generatePaginationLinks,
10
+ generateProductSchema,
11
+ generateVideoSchema,
12
+ generateWebSiteSchema,
13
+ toNextMetadata
14
+ } from "../chunk-AAN7NRZE.mjs";
15
+ export {
16
+ generateArticleSchema,
17
+ generateBreadcrumbSchema,
18
+ generateEventSchema,
19
+ generateFAQSchema,
20
+ generateLocalBusinessSchema,
21
+ generateOrganizationSchema,
22
+ generatePaginatedTitle,
23
+ generatePaginationLinks,
24
+ generateProductSchema,
25
+ generateVideoSchema,
26
+ generateWebSiteSchema,
27
+ toNextMetadata
28
+ };
@@ -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 };