@umituz/web-seo 1.0.4 → 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.
Files changed (47) hide show
  1. package/README.md +433 -0
  2. package/dist/domains/seo/components/JsonLd.d.ts +17 -0
  3. package/dist/domains/seo/components/JsonLd.d.ts.map +1 -0
  4. package/dist/domains/seo/components/JsonLd.js +52 -0
  5. package/dist/domains/seo/components/SEO.d.ts +4 -0
  6. package/dist/domains/seo/components/SEO.d.ts.map +1 -0
  7. package/dist/domains/seo/components/SEO.js +48 -0
  8. package/dist/domains/seo/core/init.d.ts +16 -0
  9. package/dist/domains/seo/core/init.d.ts.map +1 -0
  10. package/dist/domains/seo/core/init.js +34 -0
  11. package/dist/domains/seo/hooks/useJsonLd.d.ts +19 -0
  12. package/dist/domains/seo/hooks/useJsonLd.d.ts.map +1 -0
  13. package/dist/domains/seo/hooks/useJsonLd.js +53 -0
  14. package/dist/domains/seo/hooks/useSEO.d.ts +3 -0
  15. package/dist/domains/seo/hooks/useSEO.d.ts.map +1 -0
  16. package/dist/domains/seo/hooks/useSEO.js +47 -0
  17. package/dist/domains/seo/index.d.ts +15 -0
  18. package/dist/domains/seo/index.d.ts.map +1 -0
  19. package/dist/domains/seo/index.js +21 -0
  20. package/dist/domains/seo/ssr/renderer.d.ts +58 -0
  21. package/dist/domains/seo/ssr/renderer.d.ts.map +1 -0
  22. package/dist/domains/seo/ssr/renderer.js +242 -0
  23. package/dist/domains/seo/ssr/serializer.d.ts +71 -0
  24. package/dist/domains/seo/ssr/serializer.d.ts.map +1 -0
  25. package/dist/domains/seo/ssr/serializer.js +175 -0
  26. package/dist/domains/seo/types/index.d.ts +190 -0
  27. package/dist/domains/seo/types/index.d.ts.map +1 -0
  28. package/dist/domains/seo/types/index.js +1 -0
  29. package/dist/domains/seo/types/schema.d.ts +212 -0
  30. package/dist/domains/seo/types/schema.d.ts.map +1 -0
  31. package/dist/domains/seo/types/schema.js +4 -0
  32. package/dist/domains/seo/utils/dom.d.ts +22 -0
  33. package/dist/domains/seo/utils/dom.d.ts.map +1 -0
  34. package/dist/domains/seo/utils/dom.js +537 -0
  35. package/dist/domains/seo/utils/schema.d.ts +135 -0
  36. package/dist/domains/seo/utils/schema.d.ts.map +1 -0
  37. package/dist/domains/seo/utils/schema.js +321 -0
  38. package/dist/domains/seo/utils/validators.d.ts +39 -0
  39. package/dist/domains/seo/utils/validators.d.ts.map +1 -0
  40. package/dist/domains/seo/utils/validators.js +364 -0
  41. package/dist/domains/seo/vite/plugin.d.ts +61 -0
  42. package/dist/domains/seo/vite/plugin.d.ts.map +1 -0
  43. package/dist/domains/seo/vite/plugin.js +215 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +6 -0
  47. package/package.json +34 -5
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Schema.org JSON-LD Generators
3
+ *
4
+ * Helper functions to generate valid Schema.org structured data
5
+ * for various content types like articles, products, organizations, etc.
6
+ */
7
+ const DEFAULT_CONTEXT = "https://schema.org";
8
+ // ============================================================================
9
+ // Validation Helpers
10
+ // ============================================================================
11
+ const validateRequired = (value, fieldName, strict = false) => {
12
+ if (!value) {
13
+ const message = `[SEO] Schema validation: Required field "${fieldName}" is missing or empty`;
14
+ if (strict) {
15
+ throw new Error(message);
16
+ }
17
+ if (typeof console !== "undefined" && console.warn) {
18
+ console.warn(message);
19
+ }
20
+ return false;
21
+ }
22
+ return true;
23
+ };
24
+ export const generateArticleSchema = (input, options) => {
25
+ const { strict, validate = true } = options || {};
26
+ if (validate) {
27
+ validateRequired(input.headline, "headline", strict);
28
+ validateRequired(input.image, "image", strict);
29
+ validateRequired(input.datePublished, "datePublished", strict);
30
+ validateRequired(input.authorName, "authorName", strict);
31
+ validateRequired(input.publisherName, "publisherName", strict);
32
+ validateRequired(input.publisherLogo, "publisherLogo", strict);
33
+ }
34
+ return {
35
+ "@context": DEFAULT_CONTEXT,
36
+ "@type": input.type || "Article",
37
+ headline: input.headline,
38
+ name: input.headline, // Required by Thing
39
+ description: input.description,
40
+ image: input.image,
41
+ datePublished: input.datePublished,
42
+ dateModified: input.dateModified,
43
+ author: {
44
+ "@type": input.authorType || "Person",
45
+ name: input.authorName,
46
+ url: input.authorUrl,
47
+ },
48
+ publisher: {
49
+ "@context": DEFAULT_CONTEXT,
50
+ "@type": "Organization",
51
+ name: input.publisherName,
52
+ logo: input.publisherLogo,
53
+ url: input.publisherUrl,
54
+ },
55
+ url: input.url,
56
+ articleSection: input.articleSection,
57
+ wordCount: input.wordCount,
58
+ keywords: Array.isArray(input.keywords) ? input.keywords.join(", ") : input.keywords,
59
+ inLanguage: input.inLanguage,
60
+ mainEntityOfPage: {
61
+ "@type": "WebPage",
62
+ "@id": input.url,
63
+ },
64
+ };
65
+ };
66
+ export const generateProductSchema = (input, options) => {
67
+ const { strict, validate = true } = options || {};
68
+ if (validate) {
69
+ validateRequired(input.name, "name", strict);
70
+ validateRequired(input.image, "image", strict);
71
+ validateRequired(input.price, "price", strict);
72
+ validateRequired(input.priceCurrency, "priceCurrency", strict);
73
+ }
74
+ const schema = {
75
+ "@context": DEFAULT_CONTEXT,
76
+ "@type": "Product",
77
+ name: input.name,
78
+ description: input.description,
79
+ image: input.image,
80
+ offers: {
81
+ "@type": "Offer",
82
+ price: input.price.toString(),
83
+ priceCurrency: input.priceCurrency,
84
+ availability: input.availability
85
+ ? `https://schema.org/${input.availability}`
86
+ : undefined,
87
+ url: input.url,
88
+ },
89
+ };
90
+ if (input.brandName) {
91
+ schema.brand = {
92
+ "@type": "Brand",
93
+ name: input.brandName,
94
+ };
95
+ }
96
+ if (input.sku)
97
+ schema.sku = input.sku;
98
+ if (input.gtin)
99
+ schema.gtin = input.gtin;
100
+ if (input.aggregateRating) {
101
+ schema.aggregateRating = {
102
+ "@type": "AggregateRating",
103
+ ratingValue: input.aggregateRating.ratingValue,
104
+ reviewCount: input.aggregateRating.reviewCount,
105
+ bestRating: 5,
106
+ worstRating: 1,
107
+ };
108
+ }
109
+ return schema;
110
+ };
111
+ export const generateOrganizationSchema = (input, options) => {
112
+ const { strict, validate = true } = options || {};
113
+ if (validate) {
114
+ validateRequired(input.name, "name", strict);
115
+ }
116
+ const schema = {
117
+ "@context": DEFAULT_CONTEXT,
118
+ "@type": "Organization",
119
+ name: input.name,
120
+ description: input.description,
121
+ url: input.url,
122
+ logo: input.logo,
123
+ sameAs: input.sameAs,
124
+ };
125
+ if (input.contactPoint) {
126
+ schema.contactPoint = input.contactPoint.map((cp) => ({
127
+ "@type": "ContactPoint",
128
+ telephone: cp.telephone,
129
+ contactType: cp.contactType,
130
+ email: cp.email,
131
+ }));
132
+ }
133
+ if (input.address) {
134
+ schema.address = {
135
+ "@type": "PostalAddress",
136
+ ...input.address,
137
+ };
138
+ }
139
+ return schema;
140
+ };
141
+ export const generateLocalBusinessSchema = (input, options) => {
142
+ const { strict, validate = true } = options || {};
143
+ if (validate) {
144
+ validateRequired(input.name, "name", strict);
145
+ validateRequired(input.address, "address", strict);
146
+ }
147
+ const schema = {
148
+ "@context": DEFAULT_CONTEXT,
149
+ "@type": input.type || "LocalBusiness",
150
+ name: input.name,
151
+ description: input.description,
152
+ url: input.url,
153
+ logo: input.logo,
154
+ address: {
155
+ "@type": "PostalAddress",
156
+ ...input.address,
157
+ },
158
+ priceRange: input.priceRange,
159
+ };
160
+ if (input.geo) {
161
+ schema.geo = {
162
+ "@type": "GeoCoordinates",
163
+ latitude: input.geo.latitude,
164
+ longitude: input.geo.longitude,
165
+ };
166
+ }
167
+ if (input.openingHours) {
168
+ schema.openingHoursSpecification = input.openingHours.map((oh) => ({
169
+ "@type": "OpeningHoursSpecification",
170
+ dayOfWeek: oh.dayOfWeek,
171
+ opens: oh.opens,
172
+ closes: oh.closes,
173
+ }));
174
+ }
175
+ if (input.contactPoint) {
176
+ schema.contactPoint = input.contactPoint.map((cp) => ({
177
+ "@type": "ContactPoint",
178
+ telephone: cp.telephone,
179
+ contactType: cp.contactType,
180
+ email: cp.email,
181
+ }));
182
+ }
183
+ if (input.sameAs) {
184
+ schema.sameAs = input.sameAs;
185
+ }
186
+ return schema;
187
+ };
188
+ // ============================================================================
189
+ // Breadcrumb Schema Generator
190
+ // ============================================================================
191
+ export const generateBreadcrumbSchema = (items, options) => {
192
+ const { strict, validate = true } = options || {};
193
+ if (validate && items.length === 0) {
194
+ const message = "[SEO] Breadcrumb schema requires at least one item";
195
+ if (strict) {
196
+ throw new Error(message);
197
+ }
198
+ console.warn(message);
199
+ }
200
+ return {
201
+ "@context": DEFAULT_CONTEXT,
202
+ "@type": "BreadcrumbList",
203
+ itemListElement: items.map((item, index) => ({
204
+ "@type": "ListItem",
205
+ position: item.position || index + 1,
206
+ name: item.name,
207
+ item: item.item,
208
+ })),
209
+ };
210
+ };
211
+ export const generateFAQSchema = (faqs, options) => {
212
+ const { strict, validate = true } = options || {};
213
+ if (validate) {
214
+ validateRequired(faqs, "faqs", strict);
215
+ if (faqs.length === 0) {
216
+ const message = "[SEO] FAQ schema requires at least one FAQ item";
217
+ if (strict) {
218
+ throw new Error(message);
219
+ }
220
+ console.warn(message);
221
+ }
222
+ }
223
+ return {
224
+ "@context": DEFAULT_CONTEXT,
225
+ "@type": "FAQPage",
226
+ mainEntity: faqs.map((faq) => ({
227
+ "@type": "Question",
228
+ name: faq.question,
229
+ acceptedAnswer: {
230
+ "@type": "Answer",
231
+ text: faq.answer,
232
+ },
233
+ })),
234
+ };
235
+ };
236
+ export const generateWebSiteSchema = (input, options) => {
237
+ const { strict, validate = true } = options || {};
238
+ if (validate) {
239
+ validateRequired(input.name, "name", strict);
240
+ validateRequired(input.url, "url", strict);
241
+ }
242
+ const schema = {
243
+ "@context": DEFAULT_CONTEXT,
244
+ "@type": "WebSite",
245
+ name: input.name,
246
+ url: input.url,
247
+ description: input.description,
248
+ };
249
+ if (input.searchTarget) {
250
+ schema.potentialAction = {
251
+ "@type": "SearchAction",
252
+ target: input.searchTarget,
253
+ "query-input": input.searchQueryParam || "required name=search_term_string",
254
+ };
255
+ }
256
+ if (input.publisher) {
257
+ schema.publisher = {
258
+ "@context": DEFAULT_CONTEXT,
259
+ "@type": "Organization",
260
+ name: input.publisher.name,
261
+ logo: input.publisher.logo,
262
+ };
263
+ }
264
+ return schema;
265
+ };
266
+ export const generatePersonSchema = (input, options) => {
267
+ const { strict, validate = true } = options || {};
268
+ if (validate) {
269
+ validateRequired(input.name, "name", strict);
270
+ }
271
+ const schema = {
272
+ "@context": DEFAULT_CONTEXT,
273
+ "@type": "Person",
274
+ name: input.name,
275
+ givenName: input.givenName,
276
+ familyName: input.familyName,
277
+ jobTitle: input.jobTitle,
278
+ description: input.description,
279
+ image: input.image,
280
+ url: input.url,
281
+ sameAs: input.sameAs,
282
+ email: input.email,
283
+ telephone: input.telephone,
284
+ };
285
+ if (input.worksFor) {
286
+ schema.worksFor = {
287
+ "@context": DEFAULT_CONTEXT,
288
+ "@type": "Organization",
289
+ name: input.worksFor.name,
290
+ url: input.worksFor.url,
291
+ };
292
+ }
293
+ return schema;
294
+ };
295
+ export const generateVideoSchema = (input, options) => {
296
+ const { strict, validate = true } = options || {};
297
+ if (validate) {
298
+ validateRequired(input.name, "name", strict);
299
+ validateRequired(input.thumbnailUrl, "thumbnailUrl", strict);
300
+ validateRequired(input.uploadDate, "uploadDate", strict);
301
+ }
302
+ const schema = {
303
+ "@context": DEFAULT_CONTEXT,
304
+ "@type": "VideoObject",
305
+ name: input.name,
306
+ description: input.description,
307
+ thumbnailUrl: input.thumbnailUrl,
308
+ uploadDate: input.uploadDate,
309
+ duration: input.duration,
310
+ };
311
+ if (input.viewCount) {
312
+ schema.interactionStatistic = {
313
+ "@type": "InteractionCounter",
314
+ interactionType: {
315
+ "@type": "WatchAction",
316
+ },
317
+ userInteractionCount: input.viewCount,
318
+ };
319
+ }
320
+ return schema;
321
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * SEO Validators
3
+ *
4
+ * Validation utilities for SEO configuration and content.
5
+ * Helps catch common SEO issues before they affect search rankings.
6
+ */
7
+ import type { SEOptions, SEOValidationResult, JsonLdTypes } from "../types/index.js";
8
+ export declare const isValidUrl: (url: string) => boolean;
9
+ export declare const validateUrl: (url: string, fieldName?: string) => string | null;
10
+ export declare const TITLE_MIN_LENGTH = 30;
11
+ export declare const TITLE_MAX_LENGTH = 60;
12
+ export declare const DESCRIPTION_MIN_LENGTH = 120;
13
+ export declare const DESCRIPTION_MAX_LENGTH = 160;
14
+ export declare const validateTitleLength: (title: string) => string | null;
15
+ export declare const validateDescriptionLength: (description: string) => string | null;
16
+ export declare const OG_IMAGE_MIN_WIDTH = 1200;
17
+ export declare const OG_IMAGE_MIN_HEIGHT = 630;
18
+ export declare const OG_IMAGE_MAX_SIZE: number;
19
+ export declare const validateOpenGraphImage: (imageUrl: string, width?: number, height?: number, size?: number) => string | null;
20
+ export declare const isValidLanguageCode: (code: string) => boolean;
21
+ export declare const validateHreflangEntry: (entry: {
22
+ lang: string;
23
+ url: string;
24
+ }) => string | null;
25
+ export declare const validateJsonLd: (jsonLd: JsonLdTypes) => string[];
26
+ export declare const validateSEO: (options: SEOptions) => SEOValidationResult;
27
+ export declare const auditSEO: (options: SEOptions) => SEOValidationResult;
28
+ /**
29
+ * Truncate text to fit within SEO best practices
30
+ */
31
+ export declare const truncateForSEO: {
32
+ title: (text: string) => string;
33
+ description: (text: string) => string;
34
+ };
35
+ /**
36
+ * Generate a slug from text for URL-friendly content
37
+ */
38
+ export declare const generateSlug: (text: string) => string;
39
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/utils/validators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrF,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OASxC,CAAC;AAEF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