@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,419 +0,0 @@
1
- /**
2
- * Internal Linking Analyzer
3
- *
4
- * Analyzes internal link structure for SEO optimization.
5
- * Checks link distribution, anchor text, orphan pages, and link depth.
6
- */
7
-
8
- import * as cheerio from 'cheerio';
9
- import type { AuditIssue } from '../audit/types.js';
10
-
11
- export interface InternalLinkingResult {
12
- score: number;
13
- totalLinks: number;
14
- internalLinks: number;
15
- externalLinks: number;
16
- navigationLinks: number;
17
- contentLinks: number;
18
- uniqueInternalTargets: number;
19
- linksWithKeywords: number;
20
- linksWithGenericText: number;
21
- orphanRisk: boolean;
22
- linkDetails: LinkInfo[];
23
- anchorTextAnalysis: AnchorTextStats;
24
- issues: AuditIssue[];
25
- recommendations: string[];
26
- }
27
-
28
- export interface LinkInfo {
29
- href: string;
30
- text: string;
31
- isInternal: boolean;
32
- isNavigation: boolean;
33
- rel?: string;
34
- title?: string;
35
- issues: string[];
36
- }
37
-
38
- export interface AnchorTextStats {
39
- total: number;
40
- descriptive: number;
41
- generic: number;
42
- empty: number;
43
- tooLong: number;
44
- imageLinks: number;
45
- patterns: { text: string; count: number }[];
46
- }
47
-
48
- const GENERIC_ANCHOR_TEXTS = [
49
- 'click here',
50
- 'read more',
51
- 'learn more',
52
- 'here',
53
- 'link',
54
- 'this',
55
- 'more',
56
- 'continue',
57
- 'see more',
58
- 'view more',
59
- 'details',
60
- 'go',
61
- 'continue reading',
62
- '>>',
63
- '→',
64
- 'next',
65
- 'previous',
66
- ];
67
-
68
- /**
69
- * Check if URL is internal
70
- */
71
- function isInternalUrl(href: string, baseUrl: string): boolean {
72
- if (!href || href.startsWith('#') || href.startsWith('javascript:') || href.startsWith('mailto:') || href.startsWith('tel:')) {
73
- return false;
74
- }
75
-
76
- if (href.startsWith('/') && !href.startsWith('//')) {
77
- return true;
78
- }
79
-
80
- try {
81
- const base = new URL(baseUrl);
82
- const link = new URL(href, baseUrl);
83
- return link.hostname === base.hostname;
84
- } catch {
85
- return false;
86
- }
87
- }
88
-
89
- /**
90
- * Check if link is in navigation
91
- */
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- function isNavigationLink($el: cheerio.Cheerio<any>, $: cheerio.CheerioAPI): boolean {
94
- const parent = $el.parents('nav, header, footer, [role="navigation"], .nav, .navigation, .menu, .sidebar').first();
95
- return parent.length > 0;
96
- }
97
-
98
- /**
99
- * Analyze anchor text quality
100
- */
101
- function analyzeAnchorText(text: string): { isGeneric: boolean; isTooLong: boolean; isEmpty: boolean } {
102
- const normalized = text.toLowerCase().trim();
103
-
104
- return {
105
- isEmpty: normalized.length === 0,
106
- isGeneric: GENERIC_ANCHOR_TEXTS.some(g => normalized === g || normalized.includes(g)),
107
- isTooLong: normalized.length > 100,
108
- };
109
- }
110
-
111
- /**
112
- * Analyze internal linking structure
113
- */
114
- export function analyzeInternalLinking(html: string, url: string): InternalLinkingResult {
115
- const $ = cheerio.load(html);
116
- const issues: AuditIssue[] = [];
117
- const recommendations: string[] = [];
118
- let score = 100;
119
-
120
- const linkDetails: LinkInfo[] = [];
121
- const anchorTextCounts: Record<string, number> = {};
122
-
123
- let totalLinks = 0;
124
- let internalLinks = 0;
125
- let externalLinks = 0;
126
- let navigationLinks = 0;
127
- let contentLinks = 0;
128
- let linksWithGenericText = 0;
129
- let linksWithKeywords = 0;
130
- let emptyAnchorLinks = 0;
131
- let tooLongAnchorLinks = 0;
132
- let imageLinks = 0;
133
-
134
- const internalTargets = new Set<string>();
135
-
136
- $('a[href]').each((_, el) => {
137
- const $link = $(el);
138
- const href = $link.attr('href') || '';
139
- const text = $link.text().trim();
140
- const rel = $link.attr('rel');
141
- const title = $link.attr('title');
142
- const hasImage = $link.find('img').length > 0;
143
-
144
- // Skip non-HTTP links
145
- if (href.startsWith('mailto:') || href.startsWith('tel:') || href.startsWith('javascript:')) {
146
- return;
147
- }
148
-
149
- totalLinks++;
150
- const linkIssues: string[] = [];
151
- const isInternal = isInternalUrl(href, url);
152
- const isNav = isNavigationLink($link, $);
153
-
154
- if (isInternal) {
155
- internalLinks++;
156
-
157
- // Track unique targets
158
- try {
159
- const targetUrl = new URL(href, url).pathname;
160
- internalTargets.add(targetUrl);
161
- } catch {}
162
- } else if (href.startsWith('http')) {
163
- externalLinks++;
164
- }
165
-
166
- if (isNav) {
167
- navigationLinks++;
168
- } else {
169
- contentLinks++;
170
- }
171
-
172
- // Analyze anchor text
173
- const anchorAnalysis = analyzeAnchorText(text);
174
-
175
- if (hasImage && !text) {
176
- imageLinks++;
177
- const imgAlt = $link.find('img').attr('alt');
178
- if (!imgAlt) {
179
- linkIssues.push('Image link without alt text');
180
- }
181
- } else if (anchorAnalysis.isEmpty) {
182
- emptyAnchorLinks++;
183
- linkIssues.push('Empty anchor text');
184
- } else if (anchorAnalysis.isGeneric) {
185
- linksWithGenericText++;
186
- linkIssues.push('Generic anchor text');
187
- } else {
188
- linksWithKeywords++;
189
- }
190
-
191
- if (anchorAnalysis.isTooLong) {
192
- tooLongAnchorLinks++;
193
- linkIssues.push('Anchor text too long');
194
- }
195
-
196
- // Track anchor text patterns
197
- if (text) {
198
- const normalizedText = text.toLowerCase().substring(0, 50);
199
- anchorTextCounts[normalizedText] = (anchorTextCounts[normalizedText] || 0) + 1;
200
- }
201
-
202
- // Check for nofollow on internal links
203
- if (isInternal && rel?.includes('nofollow')) {
204
- linkIssues.push('nofollow on internal link');
205
- }
206
-
207
- // Check for sponsored/ugc on internal links
208
- if (isInternal && (rel?.includes('sponsored') || rel?.includes('ugc'))) {
209
- linkIssues.push('sponsored/ugc on internal link');
210
- }
211
-
212
- linkDetails.push({
213
- href: href.substring(0, 200),
214
- text: text.substring(0, 100),
215
- isInternal,
216
- isNavigation: isNav,
217
- rel,
218
- title,
219
- issues: linkIssues,
220
- });
221
- });
222
-
223
- // Generate anchor text patterns
224
- const anchorPatterns = Object.entries(anchorTextCounts)
225
- .sort((a, b) => b[1] - a[1])
226
- .slice(0, 10)
227
- .map(([text, count]) => ({ text, count }));
228
-
229
- // Analyze results
230
- const uniqueInternalTargets = internalTargets.size;
231
-
232
- // Check for orphan risk (very few internal links)
233
- const orphanRisk = internalLinks < 3 && contentLinks < 2;
234
-
235
- // Generate issues
236
- if (internalLinks === 0) {
237
- issues.push({
238
- code: 'LINK_NO_INTERNAL',
239
- severity: 'critical',
240
- category: 'content',
241
- title: 'No internal links found',
242
- description: 'This page has no internal links to other pages on your site.',
243
- impact: 'Poor link equity distribution, crawlability issues',
244
- howToFix: 'Add relevant internal links to other pages on your site.',
245
- affectedUrls: [url],
246
- });
247
- score -= 25;
248
- } else if (contentLinks === 0 && internalLinks < 5) {
249
- issues.push({
250
- code: 'LINK_LOW_INTERNAL',
251
- severity: 'warning',
252
- category: 'content',
253
- title: 'Very few internal links in content',
254
- description: `Only ${internalLinks} internal links found, all in navigation.`,
255
- impact: 'Limited topic relevance signals',
256
- howToFix: 'Add contextual internal links within your content.',
257
- affectedUrls: [url],
258
- });
259
- score -= 15;
260
- }
261
-
262
- if (linksWithGenericText > 3) {
263
- const percentage = Math.round((linksWithGenericText / totalLinks) * 100);
264
- issues.push({
265
- code: 'LINK_GENERIC_ANCHOR',
266
- severity: 'warning',
267
- category: 'content',
268
- title: `${linksWithGenericText} links with generic anchor text`,
269
- description: `${percentage}% of links use non-descriptive text like "click here" or "read more".`,
270
- impact: 'Missed keyword relevance signals',
271
- howToFix: 'Replace generic anchors with descriptive, keyword-rich text.',
272
- affectedUrls: [url],
273
- });
274
- score -= Math.min(linksWithGenericText * 2, 15);
275
- }
276
-
277
- if (emptyAnchorLinks > 0) {
278
- issues.push({
279
- code: 'LINK_EMPTY_ANCHOR',
280
- severity: 'warning',
281
- category: 'content',
282
- title: `${emptyAnchorLinks} links with empty anchor text`,
283
- description: 'Links without text or alt text are inaccessible and provide no SEO value.',
284
- impact: 'Accessibility issues, wasted link equity',
285
- howToFix: 'Add descriptive text or ensure image links have alt text.',
286
- affectedUrls: [url],
287
- });
288
- score -= Math.min(emptyAnchorLinks * 3, 15);
289
- }
290
-
291
- if (orphanRisk) {
292
- issues.push({
293
- code: 'LINK_ORPHAN_RISK',
294
- severity: 'info',
295
- category: 'content',
296
- title: 'Page may be an orphan',
297
- description: 'This page has very few internal links, which may indicate it\'s poorly connected in your site structure.',
298
- impact: 'Difficult for users and crawlers to find',
299
- howToFix: 'Link to this page from related content and relevant hub pages.',
300
- affectedUrls: [url],
301
- });
302
- score -= 10;
303
- }
304
-
305
- // Check internal link nofollow
306
- const nofollowInternalLinks = linkDetails.filter(l => l.isInternal && l.rel?.includes('nofollow'));
307
- if (nofollowInternalLinks.length > 0) {
308
- issues.push({
309
- code: 'LINK_NOFOLLOW_INTERNAL',
310
- severity: 'warning',
311
- category: 'technical',
312
- title: `${nofollowInternalLinks.length} internal links with nofollow`,
313
- description: 'Internal links should not have nofollow - it wastes PageRank.',
314
- impact: 'Reduced internal link equity flow',
315
- howToFix: 'Remove nofollow from internal links.',
316
- affectedUrls: [url],
317
- });
318
- score -= nofollowInternalLinks.length * 3;
319
- }
320
-
321
- // Check for excessive external links
322
- if (externalLinks > internalLinks && externalLinks > 10) {
323
- issues.push({
324
- code: 'LINK_EXTERNAL_HEAVY',
325
- severity: 'info',
326
- category: 'content',
327
- title: 'More external links than internal',
328
- description: `${externalLinks} external vs ${internalLinks} internal links.`,
329
- impact: 'May leak PageRank to external sites',
330
- howToFix: 'Consider adding more internal links or using nofollow/sponsored for some external links.',
331
- affectedUrls: [url],
332
- });
333
- }
334
-
335
- // Recommendations
336
- if (contentLinks < 3 && internalLinks > 0) {
337
- recommendations.push('Add 2-3 contextual internal links within your content');
338
- }
339
-
340
- if (linksWithKeywords / Math.max(totalLinks, 1) > 0.7) {
341
- recommendations.push('✓ Good use of descriptive anchor text');
342
- }
343
-
344
- if (uniqueInternalTargets > 5) {
345
- recommendations.push('✓ Good diversity of internal link targets');
346
- }
347
-
348
- // Suggest hub pages
349
- if (internalLinks > 10) {
350
- recommendations.push('Consider creating a hub/pillar page to consolidate topic authority');
351
- }
352
-
353
- return {
354
- score: Math.max(0, Math.min(100, score)),
355
- totalLinks,
356
- internalLinks,
357
- externalLinks,
358
- navigationLinks,
359
- contentLinks,
360
- uniqueInternalTargets,
361
- linksWithKeywords,
362
- linksWithGenericText,
363
- orphanRisk,
364
- linkDetails,
365
- anchorTextAnalysis: {
366
- total: totalLinks,
367
- descriptive: linksWithKeywords,
368
- generic: linksWithGenericText,
369
- empty: emptyAnchorLinks,
370
- tooLong: tooLongAnchorLinks,
371
- imageLinks,
372
- patterns: anchorPatterns,
373
- },
374
- issues,
375
- recommendations,
376
- };
377
- }
378
-
379
- /**
380
- * Suggest internal linking opportunities
381
- */
382
- export function suggestInternalLinks(content: string, availablePages: { url: string; title: string; keywords: string[] }[]): {
383
- keyword: string;
384
- suggestedUrl: string;
385
- suggestedTitle: string;
386
- relevance: number;
387
- }[] {
388
- const suggestions: { keyword: string; suggestedUrl: string; suggestedTitle: string; relevance: number }[] = [];
389
- const contentLower = content.toLowerCase();
390
-
391
- for (const page of availablePages) {
392
- for (const keyword of page.keywords) {
393
- if (contentLower.includes(keyword.toLowerCase())) {
394
- // Check if not already linked
395
- const alreadyLinked = content.includes(`href="${page.url}"`) ||
396
- content.includes(`href='${page.url}'`);
397
-
398
- if (!alreadyLinked) {
399
- // Simple relevance: keyword length + position
400
- const position = contentLower.indexOf(keyword.toLowerCase());
401
- const relevance = (keyword.length * 2) + (1000 - Math.min(position, 1000)) / 100;
402
-
403
- suggestions.push({
404
- keyword,
405
- suggestedUrl: page.url,
406
- suggestedTitle: page.title,
407
- relevance,
408
- });
409
- }
410
- }
411
- }
412
- }
413
-
414
- // Sort by relevance and dedupe
415
- return suggestions
416
- .sort((a, b) => b.relevance - a.relevance)
417
- .filter((s, i, arr) => arr.findIndex(x => x.suggestedUrl === s.suggestedUrl) === i)
418
- .slice(0, 10);
419
- }
@@ -1,140 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { analyzeMobileSEO } from './mobile-seo-analyzer.js';
3
-
4
- describe('Mobile SEO Analyzer', () => {
5
- describe('analyzeMobileSEO', () => {
6
- it('detects proper viewport', () => {
7
- const html = `
8
- <!DOCTYPE html>
9
- <html>
10
- <head>
11
- <meta name="viewport" content="width=device-width, initial-scale=1">
12
- </head>
13
- <body><h1>Test</h1></body>
14
- </html>
15
- `;
16
- const result = analyzeMobileSEO(html, 'https://example.com');
17
- expect(result.viewport.hasViewport).toBe(true);
18
- expect(result.viewport.isResponsive).toBe(true);
19
- });
20
-
21
- it('detects missing viewport', () => {
22
- const html = `
23
- <!DOCTYPE html>
24
- <html>
25
- <head><title>Test</title></head>
26
- <body><h1>Test</h1></body>
27
- </html>
28
- `;
29
- const result = analyzeMobileSEO(html, 'https://example.com');
30
- expect(result.viewport.hasViewport).toBe(false);
31
- expect(result.issues.some(i => i.code === 'MOBILE_NO_VIEWPORT')).toBe(true);
32
- });
33
-
34
- it('detects fixed viewport width', () => {
35
- const html = `
36
- <!DOCTYPE html>
37
- <html>
38
- <head>
39
- <meta name="viewport" content="width=1024">
40
- </head>
41
- <body><h1>Test</h1></body>
42
- </html>
43
- `;
44
- const result = analyzeMobileSEO(html, 'https://example.com');
45
- expect(result.viewport.isResponsive).toBe(false);
46
- });
47
-
48
- it('warns about disabled zooming', () => {
49
- const html = `
50
- <!DOCTYPE html>
51
- <html>
52
- <head>
53
- <meta name="viewport" content="width=device-width, user-scalable=no">
54
- </head>
55
- <body><h1>Test</h1></body>
56
- </html>
57
- `;
58
- const result = analyzeMobileSEO(html, 'https://example.com');
59
- expect(result.issues.some(i => i.code === 'MOBILE_ZOOM_DISABLED')).toBe(true);
60
- });
61
-
62
- it('detects apple touch icon', () => {
63
- const html = `
64
- <!DOCTYPE html>
65
- <html>
66
- <head>
67
- <meta name="viewport" content="width=device-width, initial-scale=1">
68
- <link rel="apple-touch-icon" href="/apple-touch-icon.png">
69
- </head>
70
- <body><h1>Test</h1></body>
71
- </html>
72
- `;
73
- const result = analyzeMobileSEO(html, 'https://example.com');
74
- expect(result.mobileSpecific.hasAppleTouchIcon).toBe(true);
75
- });
76
-
77
- it('detects theme color', () => {
78
- const html = `
79
- <!DOCTYPE html>
80
- <html>
81
- <head>
82
- <meta name="viewport" content="width=device-width, initial-scale=1">
83
- <meta name="theme-color" content="#ffffff">
84
- </head>
85
- <body><h1>Test</h1></body>
86
- </html>
87
- `;
88
- const result = analyzeMobileSEO(html, 'https://example.com');
89
- expect(result.mobileSpecific.hasThemeColor).toBe(true);
90
- });
91
-
92
- it('detects web app manifest', () => {
93
- const html = `
94
- <!DOCTYPE html>
95
- <html>
96
- <head>
97
- <meta name="viewport" content="width=device-width, initial-scale=1">
98
- <link rel="manifest" href="/manifest.json">
99
- </head>
100
- <body><h1>Test</h1></body>
101
- </html>
102
- `;
103
- const result = analyzeMobileSEO(html, 'https://example.com');
104
- expect(result.mobileSpecific.hasManifest).toBe(true);
105
- });
106
-
107
- it('detects responsive images', () => {
108
- const html = `
109
- <!DOCTYPE html>
110
- <html>
111
- <head>
112
- <meta name="viewport" content="width=device-width, initial-scale=1">
113
- </head>
114
- <body>
115
- <img srcset="/image-400.jpg 400w, /image-800.jpg 800w" src="/image.jpg" alt="Test">
116
- </body>
117
- </html>
118
- `;
119
- const result = analyzeMobileSEO(html, 'https://example.com');
120
- expect(result.mobileSpecific.hasMobileOptimizedImages).toBe(true);
121
- });
122
-
123
- it('calculates overall score', () => {
124
- const html = `
125
- <!DOCTYPE html>
126
- <html>
127
- <head>
128
- <meta name="viewport" content="width=device-width, initial-scale=1">
129
- <meta name="theme-color" content="#000000">
130
- <link rel="manifest" href="/manifest.json">
131
- <link rel="apple-touch-icon" href="/icon.png">
132
- </head>
133
- <body><h1>Test</h1></body>
134
- </html>
135
- `;
136
- const result = analyzeMobileSEO(html, 'https://example.com');
137
- expect(result.score).toBeGreaterThan(80);
138
- });
139
- });
140
- });