@rankcli/agent-runtime 0.0.15 → 0.0.17

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 (203) hide show
  1. package/README.md +5 -4
  2. package/dist/index.d.mts +44 -393
  3. package/dist/index.d.ts +44 -393
  4. package/dist/index.js +22098 -26131
  5. package/dist/index.mjs +11834 -15857
  6. package/package.json +10 -4
  7. package/scripts/build-deno.ts +0 -134
  8. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  9. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  10. package/src/analyzers/geo-analyzer.test.ts +0 -310
  11. package/src/analyzers/geo-analyzer.ts +0 -814
  12. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  13. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  14. package/src/analyzers/index.ts +0 -233
  15. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  16. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  17. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  18. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  19. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  20. package/src/analyzers/security-headers-analyzer.ts +0 -318
  21. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  22. package/src/analyzers/structured-data-analyzer.ts +0 -590
  23. package/src/audit/ai/analyzer.ts +0 -347
  24. package/src/audit/ai/index.ts +0 -29
  25. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  26. package/src/audit/ai/types.ts +0 -179
  27. package/src/audit/checks/additional-checks.ts +0 -439
  28. package/src/audit/checks/agent-experience.ts +0 -108
  29. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  30. package/src/audit/checks/ai-content-structure.ts +0 -325
  31. package/src/audit/checks/ai-readiness.ts +0 -406
  32. package/src/audit/checks/anchor-text.ts +0 -179
  33. package/src/audit/checks/answer-conciseness.ts +0 -322
  34. package/src/audit/checks/asset-minification.ts +0 -270
  35. package/src/audit/checks/bing-optimization.ts +0 -206
  36. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  37. package/src/audit/checks/caching-headers.ts +0 -305
  38. package/src/audit/checks/canonical-advanced.ts +0 -150
  39. package/src/audit/checks/canonical-domain.ts +0 -196
  40. package/src/audit/checks/citation-quality.ts +0 -358
  41. package/src/audit/checks/client-rendering.ts +0 -542
  42. package/src/audit/checks/color-contrast.ts +0 -342
  43. package/src/audit/checks/content-freshness.ts +0 -170
  44. package/src/audit/checks/content-science.ts +0 -589
  45. package/src/audit/checks/conversion-elements.ts +0 -526
  46. package/src/audit/checks/crawlability.ts +0 -220
  47. package/src/audit/checks/directory-listing.ts +0 -172
  48. package/src/audit/checks/dom-analysis.ts +0 -191
  49. package/src/audit/checks/dom-size.ts +0 -246
  50. package/src/audit/checks/duplicate-content.ts +0 -194
  51. package/src/audit/checks/eeat-signals.ts +0 -990
  52. package/src/audit/checks/entity-seo.ts +0 -396
  53. package/src/audit/checks/featured-snippet.ts +0 -473
  54. package/src/audit/checks/freshness-signals.ts +0 -443
  55. package/src/audit/checks/funnel-intent.ts +0 -463
  56. package/src/audit/checks/hreflang.ts +0 -174
  57. package/src/audit/checks/html-compliance.ts +0 -302
  58. package/src/audit/checks/image-dimensions.ts +0 -167
  59. package/src/audit/checks/images.ts +0 -160
  60. package/src/audit/checks/indexnow.ts +0 -275
  61. package/src/audit/checks/interactive-tools.ts +0 -475
  62. package/src/audit/checks/internal-link-graph.ts +0 -436
  63. package/src/audit/checks/keyword-analysis.ts +0 -239
  64. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  65. package/src/audit/checks/keyword-placement.ts +0 -471
  66. package/src/audit/checks/links.ts +0 -273
  67. package/src/audit/checks/llms-txt.ts +0 -224
  68. package/src/audit/checks/local-seo.ts +0 -296
  69. package/src/audit/checks/mobile.ts +0 -167
  70. package/src/audit/checks/modern-images.ts +0 -226
  71. package/src/audit/checks/navboost-signals.ts +0 -395
  72. package/src/audit/checks/on-page.ts +0 -209
  73. package/src/audit/checks/page-resources.ts +0 -285
  74. package/src/audit/checks/pagination.ts +0 -180
  75. package/src/audit/checks/performance.ts +0 -153
  76. package/src/audit/checks/platform-presence.ts +0 -580
  77. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  78. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  79. package/src/audit/checks/redirect-analysis.ts +0 -153
  80. package/src/audit/checks/redirect-chain.ts +0 -389
  81. package/src/audit/checks/resource-hints.ts +0 -420
  82. package/src/audit/checks/responsive-css.ts +0 -247
  83. package/src/audit/checks/responsive-images.ts +0 -396
  84. package/src/audit/checks/review-ecosystem.ts +0 -415
  85. package/src/audit/checks/robots-validation.ts +0 -373
  86. package/src/audit/checks/security-headers.ts +0 -188
  87. package/src/audit/checks/security.ts +0 -144
  88. package/src/audit/checks/serp-preview.ts +0 -251
  89. package/src/audit/checks/site-maturity.ts +0 -453
  90. package/src/audit/checks/social-meta.test.ts +0 -275
  91. package/src/audit/checks/social-meta.ts +0 -134
  92. package/src/audit/checks/soft-404.ts +0 -151
  93. package/src/audit/checks/structured-data.ts +0 -238
  94. package/src/audit/checks/tech-detection.ts +0 -496
  95. package/src/audit/checks/topical-clusters.ts +0 -435
  96. package/src/audit/checks/tracker-bloat.ts +0 -462
  97. package/src/audit/checks/tracking-verification.test.ts +0 -371
  98. package/src/audit/checks/tracking-verification.ts +0 -636
  99. package/src/audit/checks/url-safety.ts +0 -682
  100. package/src/audit/deno-entry.ts +0 -66
  101. package/src/audit/discovery/index.ts +0 -15
  102. package/src/audit/discovery/link-crawler.ts +0 -233
  103. package/src/audit/discovery/repo-routes.ts +0 -347
  104. package/src/audit/engine.ts +0 -633
  105. package/src/audit/fixes/index.ts +0 -209
  106. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  107. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  108. package/src/audit/index.ts +0 -74
  109. package/src/audit/runner.test.ts +0 -299
  110. package/src/audit/runner.ts +0 -130
  111. package/src/audit/types.ts +0 -1987
  112. package/src/content/featured-snippet.ts +0 -367
  113. package/src/content/generator.test.ts +0 -534
  114. package/src/content/generator.ts +0 -501
  115. package/src/content/headline.ts +0 -317
  116. package/src/content/index.ts +0 -62
  117. package/src/content/intent.ts +0 -258
  118. package/src/content/keyword-density.ts +0 -349
  119. package/src/content/readability.ts +0 -262
  120. package/src/executor.ts +0 -336
  121. package/src/fixer/framework-fixes.test.ts +0 -489
  122. package/src/fixer/framework-fixes.ts +0 -5287
  123. package/src/fixer/index.ts +0 -6
  124. package/src/fixer/schemas.ts +0 -971
  125. package/src/fixer.ts +0 -642
  126. package/src/frameworks/detector.test.ts +0 -248
  127. package/src/frameworks/detector.ts +0 -899
  128. package/src/frameworks/index.ts +0 -68
  129. package/src/frameworks/recipes/angular.yaml +0 -171
  130. package/src/frameworks/recipes/astro.yaml +0 -206
  131. package/src/frameworks/recipes/django.yaml +0 -180
  132. package/src/frameworks/recipes/laravel.yaml +0 -137
  133. package/src/frameworks/recipes/nextjs.yaml +0 -268
  134. package/src/frameworks/recipes/nuxt.yaml +0 -175
  135. package/src/frameworks/recipes/rails.yaml +0 -188
  136. package/src/frameworks/recipes/react.yaml +0 -202
  137. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  138. package/src/frameworks/recipes/vue.yaml +0 -137
  139. package/src/frameworks/recipes/wordpress.yaml +0 -209
  140. package/src/frameworks/suggestion-engine.ts +0 -357
  141. package/src/geo/geo-content.test.ts +0 -305
  142. package/src/geo/geo-content.ts +0 -266
  143. package/src/geo/geo-history.test.ts +0 -473
  144. package/src/geo/geo-history.ts +0 -433
  145. package/src/geo/geo-tracker.test.ts +0 -359
  146. package/src/geo/geo-tracker.ts +0 -411
  147. package/src/geo/index.ts +0 -11
  148. package/src/geo/llm-citation-checker.ts +0 -188
  149. package/src/git/commit-helper.test.ts +0 -261
  150. package/src/git/commit-helper.ts +0 -329
  151. package/src/git/index.ts +0 -12
  152. package/src/git/pr-helper.test.ts +0 -284
  153. package/src/git/pr-helper.ts +0 -307
  154. package/src/index.ts +0 -76
  155. package/src/keywords/ai-keyword-engine.ts +0 -1062
  156. package/src/keywords/ai-summarizer.ts +0 -387
  157. package/src/keywords/ci-mode.ts +0 -555
  158. package/src/keywords/engine.ts +0 -359
  159. package/src/keywords/index.ts +0 -151
  160. package/src/keywords/llm-judge.ts +0 -357
  161. package/src/keywords/nlp-analysis.ts +0 -706
  162. package/src/keywords/prioritizer.ts +0 -295
  163. package/src/keywords/site-crawler.ts +0 -342
  164. package/src/keywords/sources/autocomplete.ts +0 -139
  165. package/src/keywords/sources/competitive-search.ts +0 -450
  166. package/src/keywords/sources/competitor-analysis.ts +0 -374
  167. package/src/keywords/sources/dataforseo.ts +0 -206
  168. package/src/keywords/sources/free-sources.ts +0 -294
  169. package/src/keywords/sources/gsc.ts +0 -123
  170. package/src/keywords/topic-grouping.ts +0 -327
  171. package/src/keywords/types.ts +0 -144
  172. package/src/keywords/wizard.ts +0 -457
  173. package/src/loader.ts +0 -40
  174. package/src/ranking/index.ts +0 -5
  175. package/src/ranking/serp-client.ts +0 -348
  176. package/src/ranking/tracker.ts +0 -380
  177. package/src/ranking/types.ts +0 -123
  178. package/src/reports/index.ts +0 -7
  179. package/src/reports/report-generator.test.ts +0 -293
  180. package/src/reports/report-generator.ts +0 -713
  181. package/src/scheduler/alerts.test.ts +0 -458
  182. package/src/scheduler/alerts.ts +0 -328
  183. package/src/scheduler/index.ts +0 -8
  184. package/src/scheduler/scheduled-audit.test.ts +0 -377
  185. package/src/scheduler/scheduled-audit.ts +0 -149
  186. package/src/test/integration-test.ts +0 -325
  187. package/src/tools/analyzer.ts +0 -373
  188. package/src/tools/crawl.ts +0 -293
  189. package/src/tools/files.ts +0 -301
  190. package/src/tools/h1-fixer.ts +0 -249
  191. package/src/tools/index.ts +0 -67
  192. package/src/tracking/github-action.ts +0 -326
  193. package/src/tracking/google-analytics.ts +0 -265
  194. package/src/tracking/index.ts +0 -45
  195. package/src/tracking/report-generator.ts +0 -386
  196. package/src/tracking/search-console.ts +0 -335
  197. package/src/types.ts +0 -148
  198. package/src/utils/http.ts +0 -302
  199. package/src/wasm-adapter.ts +0 -297
  200. package/src/wasm-entry.ts +0 -14
  201. package/tsconfig.json +0 -17
  202. package/tsup.wasm.config.ts +0 -26
  203. 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
- }