@rankcli/agent-runtime 0.0.14 → 0.0.16

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 (199) hide show
  1. package/dist/index.d.mts +77 -393
  2. package/dist/index.d.ts +77 -393
  3. package/dist/index.js +417 -6443
  4. package/dist/index.mjs +296 -6313
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  28. package/src/audit/checks/ai-content-structure.ts +0 -325
  29. package/src/audit/checks/ai-readiness.ts +0 -339
  30. package/src/audit/checks/anchor-text.ts +0 -179
  31. package/src/audit/checks/answer-conciseness.ts +0 -322
  32. package/src/audit/checks/asset-minification.ts +0 -270
  33. package/src/audit/checks/bing-optimization.ts +0 -206
  34. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  35. package/src/audit/checks/caching-headers.ts +0 -305
  36. package/src/audit/checks/canonical-advanced.ts +0 -150
  37. package/src/audit/checks/canonical-domain.ts +0 -196
  38. package/src/audit/checks/citation-quality.ts +0 -358
  39. package/src/audit/checks/client-rendering.ts +0 -542
  40. package/src/audit/checks/color-contrast.ts +0 -342
  41. package/src/audit/checks/content-freshness.ts +0 -170
  42. package/src/audit/checks/content-science.ts +0 -589
  43. package/src/audit/checks/conversion-elements.ts +0 -526
  44. package/src/audit/checks/crawlability.ts +0 -220
  45. package/src/audit/checks/directory-listing.ts +0 -172
  46. package/src/audit/checks/dom-analysis.ts +0 -191
  47. package/src/audit/checks/dom-size.ts +0 -246
  48. package/src/audit/checks/duplicate-content.ts +0 -194
  49. package/src/audit/checks/eeat-signals.ts +0 -990
  50. package/src/audit/checks/entity-seo.ts +0 -396
  51. package/src/audit/checks/featured-snippet.ts +0 -473
  52. package/src/audit/checks/freshness-signals.ts +0 -443
  53. package/src/audit/checks/funnel-intent.ts +0 -463
  54. package/src/audit/checks/hreflang.ts +0 -174
  55. package/src/audit/checks/html-compliance.ts +0 -302
  56. package/src/audit/checks/image-dimensions.ts +0 -167
  57. package/src/audit/checks/images.ts +0 -160
  58. package/src/audit/checks/indexnow.ts +0 -275
  59. package/src/audit/checks/interactive-tools.ts +0 -475
  60. package/src/audit/checks/internal-link-graph.ts +0 -436
  61. package/src/audit/checks/keyword-analysis.ts +0 -239
  62. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  63. package/src/audit/checks/keyword-placement.ts +0 -471
  64. package/src/audit/checks/links.ts +0 -273
  65. package/src/audit/checks/llms-txt.ts +0 -224
  66. package/src/audit/checks/local-seo.ts +0 -296
  67. package/src/audit/checks/mobile.ts +0 -167
  68. package/src/audit/checks/modern-images.ts +0 -226
  69. package/src/audit/checks/navboost-signals.ts +0 -395
  70. package/src/audit/checks/on-page.ts +0 -209
  71. package/src/audit/checks/page-resources.ts +0 -285
  72. package/src/audit/checks/pagination.ts +0 -180
  73. package/src/audit/checks/performance.ts +0 -153
  74. package/src/audit/checks/platform-presence.ts +0 -580
  75. package/src/audit/checks/redirect-analysis.ts +0 -153
  76. package/src/audit/checks/redirect-chain.ts +0 -389
  77. package/src/audit/checks/resource-hints.ts +0 -420
  78. package/src/audit/checks/responsive-css.ts +0 -247
  79. package/src/audit/checks/responsive-images.ts +0 -396
  80. package/src/audit/checks/review-ecosystem.ts +0 -415
  81. package/src/audit/checks/robots-validation.ts +0 -373
  82. package/src/audit/checks/security-headers.ts +0 -188
  83. package/src/audit/checks/security.ts +0 -144
  84. package/src/audit/checks/serp-preview.ts +0 -251
  85. package/src/audit/checks/site-maturity.ts +0 -453
  86. package/src/audit/checks/social-meta.test.ts +0 -275
  87. package/src/audit/checks/social-meta.ts +0 -134
  88. package/src/audit/checks/soft-404.ts +0 -151
  89. package/src/audit/checks/structured-data.ts +0 -238
  90. package/src/audit/checks/tech-detection.ts +0 -496
  91. package/src/audit/checks/topical-clusters.ts +0 -435
  92. package/src/audit/checks/tracker-bloat.ts +0 -462
  93. package/src/audit/checks/tracking-verification.test.ts +0 -371
  94. package/src/audit/checks/tracking-verification.ts +0 -636
  95. package/src/audit/checks/url-safety.ts +0 -682
  96. package/src/audit/deno-entry.ts +0 -66
  97. package/src/audit/discovery/index.ts +0 -15
  98. package/src/audit/discovery/link-crawler.ts +0 -233
  99. package/src/audit/discovery/repo-routes.ts +0 -347
  100. package/src/audit/engine.ts +0 -627
  101. package/src/audit/fixes/index.ts +0 -209
  102. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  103. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  104. package/src/audit/index.ts +0 -74
  105. package/src/audit/runner.test.ts +0 -299
  106. package/src/audit/runner.ts +0 -130
  107. package/src/audit/types.ts +0 -1963
  108. package/src/content/featured-snippet.ts +0 -367
  109. package/src/content/generator.test.ts +0 -534
  110. package/src/content/generator.ts +0 -501
  111. package/src/content/headline.ts +0 -317
  112. package/src/content/index.ts +0 -62
  113. package/src/content/intent.ts +0 -258
  114. package/src/content/keyword-density.ts +0 -349
  115. package/src/content/readability.ts +0 -262
  116. package/src/executor.ts +0 -336
  117. package/src/fixer/framework-fixes.test.ts +0 -489
  118. package/src/fixer/framework-fixes.ts +0 -5287
  119. package/src/fixer/index.ts +0 -6
  120. package/src/fixer/schemas.ts +0 -971
  121. package/src/fixer.ts +0 -642
  122. package/src/frameworks/detector.test.ts +0 -248
  123. package/src/frameworks/detector.ts +0 -899
  124. package/src/frameworks/index.ts +0 -68
  125. package/src/frameworks/recipes/angular.yaml +0 -171
  126. package/src/frameworks/recipes/astro.yaml +0 -206
  127. package/src/frameworks/recipes/django.yaml +0 -180
  128. package/src/frameworks/recipes/laravel.yaml +0 -137
  129. package/src/frameworks/recipes/nextjs.yaml +0 -268
  130. package/src/frameworks/recipes/nuxt.yaml +0 -175
  131. package/src/frameworks/recipes/rails.yaml +0 -188
  132. package/src/frameworks/recipes/react.yaml +0 -202
  133. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  134. package/src/frameworks/recipes/vue.yaml +0 -137
  135. package/src/frameworks/recipes/wordpress.yaml +0 -209
  136. package/src/frameworks/suggestion-engine.ts +0 -357
  137. package/src/geo/geo-content.test.ts +0 -305
  138. package/src/geo/geo-content.ts +0 -266
  139. package/src/geo/geo-history.test.ts +0 -473
  140. package/src/geo/geo-history.ts +0 -433
  141. package/src/geo/geo-tracker.test.ts +0 -359
  142. package/src/geo/geo-tracker.ts +0 -411
  143. package/src/geo/index.ts +0 -11
  144. package/src/geo/llm-citation-checker.ts +0 -188
  145. package/src/git/commit-helper.test.ts +0 -261
  146. package/src/git/commit-helper.ts +0 -329
  147. package/src/git/index.ts +0 -12
  148. package/src/git/pr-helper.test.ts +0 -284
  149. package/src/git/pr-helper.ts +0 -307
  150. package/src/index.ts +0 -76
  151. package/src/keywords/ai-keyword-engine.ts +0 -1062
  152. package/src/keywords/ai-summarizer.ts +0 -387
  153. package/src/keywords/ci-mode.ts +0 -555
  154. package/src/keywords/engine.ts +0 -359
  155. package/src/keywords/index.ts +0 -151
  156. package/src/keywords/llm-judge.ts +0 -357
  157. package/src/keywords/nlp-analysis.ts +0 -706
  158. package/src/keywords/prioritizer.ts +0 -295
  159. package/src/keywords/site-crawler.ts +0 -342
  160. package/src/keywords/sources/autocomplete.ts +0 -139
  161. package/src/keywords/sources/competitive-search.ts +0 -450
  162. package/src/keywords/sources/competitor-analysis.ts +0 -374
  163. package/src/keywords/sources/dataforseo.ts +0 -206
  164. package/src/keywords/sources/free-sources.ts +0 -294
  165. package/src/keywords/sources/gsc.ts +0 -123
  166. package/src/keywords/topic-grouping.ts +0 -327
  167. package/src/keywords/types.ts +0 -144
  168. package/src/keywords/wizard.ts +0 -457
  169. package/src/loader.ts +0 -40
  170. package/src/ranking/index.ts +0 -5
  171. package/src/ranking/serp-client.ts +0 -348
  172. package/src/ranking/tracker.ts +0 -380
  173. package/src/ranking/types.ts +0 -123
  174. package/src/reports/index.ts +0 -7
  175. package/src/reports/report-generator.test.ts +0 -293
  176. package/src/reports/report-generator.ts +0 -713
  177. package/src/scheduler/alerts.test.ts +0 -458
  178. package/src/scheduler/alerts.ts +0 -328
  179. package/src/scheduler/index.ts +0 -8
  180. package/src/scheduler/scheduled-audit.test.ts +0 -377
  181. package/src/scheduler/scheduled-audit.ts +0 -149
  182. package/src/test/integration-test.ts +0 -325
  183. package/src/tools/analyzer.ts +0 -373
  184. package/src/tools/crawl.ts +0 -293
  185. package/src/tools/files.ts +0 -301
  186. package/src/tools/h1-fixer.ts +0 -249
  187. package/src/tools/index.ts +0 -67
  188. package/src/tracking/github-action.ts +0 -326
  189. package/src/tracking/google-analytics.ts +0 -265
  190. package/src/tracking/index.ts +0 -45
  191. package/src/tracking/report-generator.ts +0 -386
  192. package/src/tracking/search-console.ts +0 -335
  193. package/src/types.ts +0 -148
  194. package/src/utils/http.ts +0 -302
  195. package/src/wasm-adapter.ts +0 -297
  196. package/src/wasm-entry.ts +0 -14
  197. package/tsconfig.json +0 -17
  198. package/tsup.wasm.config.ts +0 -26
  199. package/vitest.config.ts +0 -15
@@ -1,590 +0,0 @@
1
- /**
2
- * Structured Data / Schema.org Analyzer
3
- *
4
- * Validates JSON-LD structured data for SEO and AI search optimization.
5
- * Checks for common schema types, required properties, and best practices.
6
- */
7
-
8
- import * as cheerio from 'cheerio';
9
- import type { AuditIssue } from '../audit/types.js';
10
-
11
- export interface StructuredDataResult {
12
- score: number;
13
- schemas: SchemaItem[];
14
- hasOrganization: boolean;
15
- hasWebSite: boolean;
16
- hasWebPage: boolean;
17
- hasBreadcrumb: boolean;
18
- hasArticle: boolean;
19
- hasProduct: boolean;
20
- hasFAQ: boolean;
21
- hasHowTo: boolean;
22
- hasLocalBusiness: boolean;
23
- hasEvent: boolean;
24
- hasReview: boolean;
25
- issues: AuditIssue[];
26
- recommendations: string[];
27
- }
28
-
29
- export interface SchemaItem {
30
- type: string;
31
- isValid: boolean;
32
- errors: string[];
33
- warnings: string[];
34
- properties: string[];
35
- }
36
-
37
- // Required and recommended properties for common schema types
38
- const SCHEMA_REQUIREMENTS: Record<string, { required: string[]; recommended: string[] }> = {
39
- 'Organization': {
40
- required: ['name', 'url'],
41
- recommended: ['logo', 'sameAs', 'contactPoint', 'address'],
42
- },
43
- 'WebSite': {
44
- required: ['name', 'url'],
45
- recommended: ['potentialAction', 'publisher'],
46
- },
47
- 'WebPage': {
48
- required: ['name'],
49
- recommended: ['description', 'url', 'breadcrumb', 'mainEntity'],
50
- },
51
- 'Article': {
52
- required: ['headline', 'author', 'datePublished'],
53
- recommended: ['image', 'dateModified', 'publisher', 'description', 'mainEntityOfPage'],
54
- },
55
- 'BlogPosting': {
56
- required: ['headline', 'author', 'datePublished'],
57
- recommended: ['image', 'dateModified', 'publisher', 'description'],
58
- },
59
- 'NewsArticle': {
60
- required: ['headline', 'author', 'datePublished', 'image'],
61
- recommended: ['dateModified', 'publisher', 'description'],
62
- },
63
- 'Product': {
64
- required: ['name'],
65
- recommended: ['image', 'description', 'offers', 'brand', 'sku', 'aggregateRating', 'review'],
66
- },
67
- 'Offer': {
68
- required: ['price', 'priceCurrency'],
69
- recommended: ['availability', 'url', 'priceValidUntil'],
70
- },
71
- 'FAQPage': {
72
- required: ['mainEntity'],
73
- recommended: [],
74
- },
75
- 'Question': {
76
- required: ['name', 'acceptedAnswer'],
77
- recommended: [],
78
- },
79
- 'HowTo': {
80
- required: ['name', 'step'],
81
- recommended: ['image', 'totalTime', 'estimatedCost', 'supply', 'tool'],
82
- },
83
- 'BreadcrumbList': {
84
- required: ['itemListElement'],
85
- recommended: [],
86
- },
87
- 'LocalBusiness': {
88
- required: ['name', 'address'],
89
- recommended: ['telephone', 'openingHours', 'geo', 'image', 'priceRange'],
90
- },
91
- 'Event': {
92
- required: ['name', 'startDate', 'location'],
93
- recommended: ['endDate', 'description', 'image', 'offers', 'performer', 'organizer'],
94
- },
95
- 'Review': {
96
- required: ['itemReviewed', 'reviewRating', 'author'],
97
- recommended: ['reviewBody', 'datePublished'],
98
- },
99
- 'AggregateRating': {
100
- required: ['ratingValue', 'reviewCount'],
101
- recommended: ['bestRating', 'worstRating'],
102
- },
103
- 'Person': {
104
- required: ['name'],
105
- recommended: ['url', 'image', 'jobTitle', 'sameAs'],
106
- },
107
- 'VideoObject': {
108
- required: ['name', 'thumbnailUrl', 'uploadDate'],
109
- recommended: ['description', 'contentUrl', 'duration', 'embedUrl'],
110
- },
111
- 'ImageObject': {
112
- required: ['contentUrl'],
113
- recommended: ['caption', 'creditText', 'creator'],
114
- },
115
- 'SoftwareApplication': {
116
- required: ['name'],
117
- recommended: ['operatingSystem', 'applicationCategory', 'offers', 'aggregateRating'],
118
- },
119
- 'Recipe': {
120
- required: ['name', 'recipeIngredient', 'recipeInstructions'],
121
- recommended: ['image', 'author', 'prepTime', 'cookTime', 'totalTime', 'nutrition'],
122
- },
123
- 'Course': {
124
- required: ['name', 'provider'],
125
- recommended: ['description', 'offers'],
126
- },
127
- };
128
-
129
- /**
130
- * Parse and validate JSON-LD structured data
131
- */
132
- function parseJsonLd(script: string): { data: any; error?: string } {
133
- try {
134
- const data = JSON.parse(script);
135
- return { data };
136
- } catch (e) {
137
- return { data: null, error: `Invalid JSON: ${(e as Error).message}` };
138
- }
139
- }
140
-
141
- /**
142
- * Get all types from a schema object (handles @graph and nested types)
143
- */
144
- function extractTypes(data: any): string[] {
145
- const types: string[] = [];
146
-
147
- if (!data) return types;
148
-
149
- if (Array.isArray(data)) {
150
- for (const item of data) {
151
- types.push(...extractTypes(item));
152
- }
153
- } else if (typeof data === 'object') {
154
- if (data['@type']) {
155
- const schemaType = Array.isArray(data['@type']) ? data['@type'] : [data['@type']];
156
- types.push(...schemaType);
157
- }
158
- if (data['@graph']) {
159
- types.push(...extractTypes(data['@graph']));
160
- }
161
- }
162
-
163
- return types;
164
- }
165
-
166
- /**
167
- * Validate a schema object against requirements
168
- */
169
- function validateSchema(data: any, type: string): SchemaItem {
170
- const errors: string[] = [];
171
- const warnings: string[] = [];
172
- const properties: string[] = [];
173
-
174
- if (!data || typeof data !== 'object') {
175
- return { type, isValid: false, errors: ['Invalid schema object'], warnings, properties };
176
- }
177
-
178
- // Extract properties
179
- for (const key of Object.keys(data)) {
180
- if (!key.startsWith('@')) {
181
- properties.push(key);
182
- }
183
- }
184
-
185
- // Check requirements
186
- const requirements = SCHEMA_REQUIREMENTS[type];
187
- if (requirements) {
188
- // Check required properties
189
- for (const prop of requirements.required) {
190
- if (!data[prop]) {
191
- errors.push(`Missing required property: ${prop}`);
192
- }
193
- }
194
-
195
- // Check recommended properties
196
- for (const prop of requirements.recommended) {
197
- if (!data[prop]) {
198
- warnings.push(`Missing recommended property: ${prop}`);
199
- }
200
- }
201
- }
202
-
203
- // Type-specific validations
204
- if (type === 'Article' || type === 'BlogPosting' || type === 'NewsArticle') {
205
- // Check for proper author format
206
- if (data.author && typeof data.author === 'string') {
207
- warnings.push('author should be a Person or Organization object, not a string');
208
- }
209
- // Check for proper publisher format
210
- if (data.publisher && typeof data.publisher === 'string') {
211
- warnings.push('publisher should be an Organization object, not a string');
212
- }
213
- // Check date format
214
- if (data.datePublished && !/^\d{4}-\d{2}-\d{2}/.test(data.datePublished)) {
215
- warnings.push('datePublished should be in ISO 8601 format (YYYY-MM-DD)');
216
- }
217
- }
218
-
219
- if (type === 'Product') {
220
- // Check for offers
221
- if (!data.offers) {
222
- warnings.push('Product without offers/price - may not show rich results');
223
- }
224
- }
225
-
226
- if (type === 'FAQPage') {
227
- // Check for valid Q&A structure
228
- if (data.mainEntity) {
229
- const questions = Array.isArray(data.mainEntity) ? data.mainEntity : [data.mainEntity];
230
- for (let i = 0; i < questions.length; i++) {
231
- const q = questions[i];
232
- if (!q.name && !q['@type']?.includes('Question')) {
233
- errors.push(`FAQ item ${i + 1} is not a valid Question`);
234
- }
235
- if (!q.acceptedAnswer) {
236
- errors.push(`FAQ item ${i + 1} missing acceptedAnswer`);
237
- }
238
- }
239
- }
240
- }
241
-
242
- if (type === 'BreadcrumbList') {
243
- // Check for proper item list
244
- if (data.itemListElement) {
245
- const items = Array.isArray(data.itemListElement) ? data.itemListElement : [data.itemListElement];
246
- items.forEach((item: Record<string, unknown>, i: number) => {
247
- if (!item.position) {
248
- errors.push(`Breadcrumb item ${i + 1} missing position`);
249
- }
250
- if (!item.name && !(item.item as Record<string, unknown>)?.name) {
251
- errors.push(`Breadcrumb item ${i + 1} missing name`);
252
- }
253
- });
254
- }
255
- }
256
-
257
- if (type === 'LocalBusiness') {
258
- // Check for geo coordinates
259
- if (data.geo) {
260
- if (!data.geo.latitude || !data.geo.longitude) {
261
- warnings.push('geo should include latitude and longitude');
262
- }
263
- }
264
- // Check opening hours format
265
- if (data.openingHours && typeof data.openingHours === 'string') {
266
- warnings.push('openingHours should be an array of OpeningHoursSpecification objects for rich results');
267
- }
268
- }
269
-
270
- return {
271
- type,
272
- isValid: errors.length === 0,
273
- errors,
274
- warnings,
275
- properties,
276
- };
277
- }
278
-
279
- /**
280
- * Analyze all structured data on a page
281
- */
282
- export function analyzeStructuredData(html: string, url: string): StructuredDataResult {
283
- const $ = cheerio.load(html);
284
- const schemas: SchemaItem[] = [];
285
- const issues: AuditIssue[] = [];
286
- const recommendations: string[] = [];
287
- let score = 100;
288
-
289
- // Track schema types
290
- const foundTypes = new Set<string>();
291
-
292
- // Parse all JSON-LD scripts
293
- $('script[type="application/ld+json"]').each((_, el) => {
294
- const content = $(el).html();
295
- if (!content) return;
296
-
297
- const { data, error } = parseJsonLd(content);
298
-
299
- if (error) {
300
- issues.push({
301
- code: 'SCHEMA_INVALID_JSON',
302
- severity: 'critical',
303
- category: 'technical',
304
- title: 'Invalid JSON-LD syntax',
305
- description: error,
306
- impact: 'Schema will not be parsed by search engines',
307
- howToFix: 'Fix JSON syntax errors. Use a JSON validator.',
308
- affectedUrls: [url],
309
- });
310
- score -= 20;
311
- return;
312
- }
313
-
314
- // Extract and validate all types
315
- const types = extractTypes(data);
316
-
317
- // Process each schema item
318
- const processItem = (item: any) => {
319
- if (!item || typeof item !== 'object') return;
320
-
321
- let itemType = item['@type'];
322
- if (Array.isArray(itemType)) itemType = itemType[0];
323
-
324
- if (itemType) {
325
- foundTypes.add(itemType);
326
- const validation = validateSchema(item, itemType);
327
- schemas.push(validation);
328
-
329
- if (!validation.isValid) {
330
- for (const err of validation.errors) {
331
- issues.push({
332
- code: 'SCHEMA_VALIDATION_ERROR',
333
- severity: 'warning',
334
- category: 'technical',
335
- title: `${itemType} schema error: ${err}`,
336
- description: `The ${itemType} schema is missing required properties or has invalid data.`,
337
- impact: 'May not qualify for rich results',
338
- howToFix: `Add the missing property: ${err.replace('Missing required property: ', '')}`,
339
- affectedUrls: [url],
340
- });
341
- score -= 5;
342
- }
343
- }
344
- }
345
-
346
- // Process @graph
347
- if (item['@graph'] && Array.isArray(item['@graph'])) {
348
- item['@graph'].forEach(processItem);
349
- }
350
- };
351
-
352
- if (Array.isArray(data)) {
353
- data.forEach(processItem);
354
- } else {
355
- processItem(data);
356
- }
357
- });
358
-
359
- // Check for essential schemas
360
- const hasOrganization = foundTypes.has('Organization');
361
- const hasWebSite = foundTypes.has('WebSite');
362
- const hasWebPage = foundTypes.has('WebPage');
363
- const hasBreadcrumb = foundTypes.has('BreadcrumbList');
364
- const hasArticle = foundTypes.has('Article') || foundTypes.has('BlogPosting') || foundTypes.has('NewsArticle');
365
- const hasProduct = foundTypes.has('Product');
366
- const hasFAQ = foundTypes.has('FAQPage');
367
- const hasHowTo = foundTypes.has('HowTo');
368
- const hasLocalBusiness = foundTypes.has('LocalBusiness');
369
- const hasEvent = foundTypes.has('Event');
370
- const hasReview = foundTypes.has('Review') || foundTypes.has('AggregateRating');
371
-
372
- // Generate recommendations
373
- if (!hasOrganization) {
374
- recommendations.push('Add Organization schema for brand knowledge panel');
375
- score -= 5;
376
- }
377
-
378
- if (!hasWebSite) {
379
- recommendations.push('Add WebSite schema with SearchAction for sitelinks search box');
380
- score -= 3;
381
- }
382
-
383
- if (!hasBreadcrumb) {
384
- recommendations.push('Add BreadcrumbList schema for breadcrumb rich results');
385
- score -= 3;
386
- }
387
-
388
- // Check for page-type specific schemas
389
- if (!hasArticle && !hasProduct && !hasFAQ && !hasHowTo && !hasLocalBusiness && !hasEvent) {
390
- recommendations.push('Add page-specific schema (Article, Product, FAQ, HowTo, etc.)');
391
- score -= 10;
392
-
393
- issues.push({
394
- code: 'SCHEMA_NO_RICH_RESULT_TYPE',
395
- severity: 'warning',
396
- category: 'technical',
397
- title: 'No rich result schema found',
398
- description: 'Page lacks schema types that enable rich results (Article, Product, FAQ, etc.)',
399
- impact: 'Missing opportunity for enhanced search results',
400
- howToFix: 'Add appropriate schema type for your content (e.g., Article for blog posts, Product for products, FAQ for Q&A)',
401
- affectedUrls: [url],
402
- });
403
- }
404
-
405
- // Check for no schema at all
406
- if (schemas.length === 0) {
407
- score -= 20;
408
- issues.push({
409
- code: 'SCHEMA_NONE_FOUND',
410
- severity: 'warning',
411
- category: 'technical',
412
- title: 'No structured data found',
413
- description: 'No JSON-LD structured data detected on the page.',
414
- impact: 'Missing rich results, reduced AI understanding, lower search visibility',
415
- howToFix: 'Add JSON-LD structured data. At minimum, include Organization and WebPage schemas.',
416
- affectedUrls: [url],
417
- });
418
- }
419
-
420
- // AI-specific recommendations
421
- if (schemas.length > 0 && !hasFAQ) {
422
- recommendations.push('Consider adding FAQPage schema - excellent for AI search citations');
423
- }
424
-
425
- if (!foundTypes.has('Person') && hasArticle) {
426
- recommendations.push('Use Person schema for authors to improve E-E-A-T signals');
427
- }
428
-
429
- return {
430
- score: Math.max(0, Math.min(100, score)),
431
- schemas,
432
- hasOrganization,
433
- hasWebSite,
434
- hasWebPage,
435
- hasBreadcrumb,
436
- hasArticle,
437
- hasProduct,
438
- hasFAQ,
439
- hasHowTo,
440
- hasLocalBusiness,
441
- hasEvent,
442
- hasReview,
443
- issues,
444
- recommendations,
445
- };
446
- }
447
-
448
- /**
449
- * Generate recommended schema for a page type
450
- */
451
- export function generateSchemaTemplate(pageType: 'article' | 'product' | 'faq' | 'local-business' | 'website', options: {
452
- siteName: string;
453
- siteUrl: string;
454
- authorName?: string;
455
- organizationName?: string;
456
- }): string {
457
- const { siteName, siteUrl, authorName, organizationName } = options;
458
-
459
- const baseSchemas = [
460
- {
461
- '@context': 'https://schema.org',
462
- '@type': 'Organization',
463
- name: organizationName || siteName,
464
- url: siteUrl,
465
- logo: `${siteUrl}/logo.png`,
466
- },
467
- {
468
- '@context': 'https://schema.org',
469
- '@type': 'WebSite',
470
- name: siteName,
471
- url: siteUrl,
472
- potentialAction: {
473
- '@type': 'SearchAction',
474
- target: {
475
- '@type': 'EntryPoint',
476
- urlTemplate: `${siteUrl}/search?q={search_term_string}`,
477
- },
478
- 'query-input': 'required name=search_term_string',
479
- },
480
- },
481
- ];
482
-
483
- const pageSchemas: Record<string, object> = {
484
- article: {
485
- '@context': 'https://schema.org',
486
- '@type': 'Article',
487
- headline: '{{title}}',
488
- description: '{{description}}',
489
- image: '{{image_url}}',
490
- datePublished: '{{date_published}}',
491
- dateModified: '{{date_modified}}',
492
- author: {
493
- '@type': 'Person',
494
- name: authorName || '{{author_name}}',
495
- url: '{{author_url}}',
496
- },
497
- publisher: {
498
- '@type': 'Organization',
499
- name: organizationName || siteName,
500
- logo: {
501
- '@type': 'ImageObject',
502
- url: `${siteUrl}/logo.png`,
503
- },
504
- },
505
- },
506
- product: {
507
- '@context': 'https://schema.org',
508
- '@type': 'Product',
509
- name: '{{product_name}}',
510
- description: '{{product_description}}',
511
- image: '{{product_image}}',
512
- brand: {
513
- '@type': 'Brand',
514
- name: '{{brand_name}}',
515
- },
516
- sku: '{{sku}}',
517
- offers: {
518
- '@type': 'Offer',
519
- price: '{{price}}',
520
- priceCurrency: 'USD',
521
- availability: 'https://schema.org/InStock',
522
- url: '{{product_url}}',
523
- },
524
- aggregateRating: {
525
- '@type': 'AggregateRating',
526
- ratingValue: '{{rating}}',
527
- reviewCount: '{{review_count}}',
528
- },
529
- },
530
- faq: {
531
- '@context': 'https://schema.org',
532
- '@type': 'FAQPage',
533
- mainEntity: [
534
- {
535
- '@type': 'Question',
536
- name: '{{question_1}}',
537
- acceptedAnswer: {
538
- '@type': 'Answer',
539
- text: '{{answer_1}}',
540
- },
541
- },
542
- {
543
- '@type': 'Question',
544
- name: '{{question_2}}',
545
- acceptedAnswer: {
546
- '@type': 'Answer',
547
- text: '{{answer_2}}',
548
- },
549
- },
550
- ],
551
- },
552
- 'local-business': {
553
- '@context': 'https://schema.org',
554
- '@type': 'LocalBusiness',
555
- name: '{{business_name}}',
556
- description: '{{description}}',
557
- url: siteUrl,
558
- telephone: '{{phone}}',
559
- address: {
560
- '@type': 'PostalAddress',
561
- streetAddress: '{{street}}',
562
- addressLocality: '{{city}}',
563
- addressRegion: '{{state}}',
564
- postalCode: '{{zip}}',
565
- addressCountry: '{{country}}',
566
- },
567
- geo: {
568
- '@type': 'GeoCoordinates',
569
- latitude: '{{latitude}}',
570
- longitude: '{{longitude}}',
571
- },
572
- openingHoursSpecification: [
573
- {
574
- '@type': 'OpeningHoursSpecification',
575
- dayOfWeek: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
576
- opens: '09:00',
577
- closes: '17:00',
578
- },
579
- ],
580
- },
581
- website: baseSchemas[1],
582
- };
583
-
584
- const result: object[] = [...baseSchemas];
585
- if (pageType !== 'website' && pageSchemas[pageType]) {
586
- result.push(pageSchemas[pageType]);
587
- }
588
-
589
- return JSON.stringify(result, null, 2);
590
- }