@rankcli/agent-runtime 0.0.1
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.
- package/README.md +242 -0
- package/dist/analyzer-2CSWIQGD.mjs +6 -0
- package/dist/chunk-YNZYHEYM.mjs +774 -0
- package/dist/index.d.mts +4012 -0
- package/dist/index.d.ts +4012 -0
- package/dist/index.js +29672 -0
- package/dist/index.mjs +28602 -0
- package/package.json +53 -0
- package/scripts/build-deno.ts +134 -0
- package/src/audit/ai/analyzer.ts +347 -0
- package/src/audit/ai/index.ts +29 -0
- package/src/audit/ai/prompts/content-analysis.ts +271 -0
- package/src/audit/ai/types.ts +179 -0
- package/src/audit/checks/additional-checks.ts +439 -0
- package/src/audit/checks/ai-citation-worthiness.ts +399 -0
- package/src/audit/checks/ai-content-structure.ts +325 -0
- package/src/audit/checks/ai-readiness.ts +339 -0
- package/src/audit/checks/anchor-text.ts +179 -0
- package/src/audit/checks/answer-conciseness.ts +322 -0
- package/src/audit/checks/asset-minification.ts +270 -0
- package/src/audit/checks/bing-optimization.ts +206 -0
- package/src/audit/checks/brand-mention-optimization.ts +349 -0
- package/src/audit/checks/caching-headers.ts +305 -0
- package/src/audit/checks/canonical-advanced.ts +150 -0
- package/src/audit/checks/canonical-domain.ts +196 -0
- package/src/audit/checks/citation-quality.ts +358 -0
- package/src/audit/checks/client-rendering.ts +542 -0
- package/src/audit/checks/color-contrast.ts +342 -0
- package/src/audit/checks/content-freshness.ts +170 -0
- package/src/audit/checks/content-science.ts +589 -0
- package/src/audit/checks/conversion-elements.ts +526 -0
- package/src/audit/checks/crawlability.ts +220 -0
- package/src/audit/checks/directory-listing.ts +172 -0
- package/src/audit/checks/dom-analysis.ts +191 -0
- package/src/audit/checks/dom-size.ts +246 -0
- package/src/audit/checks/duplicate-content.ts +194 -0
- package/src/audit/checks/eeat-signals.ts +990 -0
- package/src/audit/checks/entity-seo.ts +396 -0
- package/src/audit/checks/featured-snippet.ts +473 -0
- package/src/audit/checks/freshness-signals.ts +443 -0
- package/src/audit/checks/funnel-intent.ts +463 -0
- package/src/audit/checks/hreflang.ts +174 -0
- package/src/audit/checks/html-compliance.ts +302 -0
- package/src/audit/checks/image-dimensions.ts +167 -0
- package/src/audit/checks/images.ts +160 -0
- package/src/audit/checks/indexnow.ts +275 -0
- package/src/audit/checks/interactive-tools.ts +475 -0
- package/src/audit/checks/internal-link-graph.ts +436 -0
- package/src/audit/checks/keyword-analysis.ts +239 -0
- package/src/audit/checks/keyword-cannibalization.ts +385 -0
- package/src/audit/checks/keyword-placement.ts +471 -0
- package/src/audit/checks/links.ts +203 -0
- package/src/audit/checks/llms-txt.ts +224 -0
- package/src/audit/checks/local-seo.ts +296 -0
- package/src/audit/checks/mobile.ts +167 -0
- package/src/audit/checks/modern-images.ts +226 -0
- package/src/audit/checks/navboost-signals.ts +395 -0
- package/src/audit/checks/on-page.ts +209 -0
- package/src/audit/checks/page-resources.ts +285 -0
- package/src/audit/checks/pagination.ts +180 -0
- package/src/audit/checks/performance.ts +153 -0
- package/src/audit/checks/platform-presence.ts +580 -0
- package/src/audit/checks/redirect-analysis.ts +153 -0
- package/src/audit/checks/redirect-chain.ts +389 -0
- package/src/audit/checks/resource-hints.ts +420 -0
- package/src/audit/checks/responsive-css.ts +247 -0
- package/src/audit/checks/responsive-images.ts +396 -0
- package/src/audit/checks/review-ecosystem.ts +415 -0
- package/src/audit/checks/robots-validation.ts +373 -0
- package/src/audit/checks/security-headers.ts +172 -0
- package/src/audit/checks/security.ts +144 -0
- package/src/audit/checks/serp-preview.ts +251 -0
- package/src/audit/checks/site-maturity.ts +444 -0
- package/src/audit/checks/social-meta.test.ts +275 -0
- package/src/audit/checks/social-meta.ts +134 -0
- package/src/audit/checks/soft-404.ts +151 -0
- package/src/audit/checks/structured-data.ts +238 -0
- package/src/audit/checks/tech-detection.ts +496 -0
- package/src/audit/checks/topical-clusters.ts +435 -0
- package/src/audit/checks/tracker-bloat.ts +462 -0
- package/src/audit/checks/tracking-verification.test.ts +371 -0
- package/src/audit/checks/tracking-verification.ts +636 -0
- package/src/audit/checks/url-safety.ts +682 -0
- package/src/audit/deno-entry.ts +66 -0
- package/src/audit/discovery/index.ts +15 -0
- package/src/audit/discovery/link-crawler.ts +232 -0
- package/src/audit/discovery/repo-routes.ts +347 -0
- package/src/audit/engine.ts +620 -0
- package/src/audit/fixes/index.ts +209 -0
- package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
- package/src/audit/fixes/social-meta-fixes.ts +463 -0
- package/src/audit/index.ts +74 -0
- package/src/audit/runner.test.ts +299 -0
- package/src/audit/runner.ts +130 -0
- package/src/audit/types.ts +1953 -0
- package/src/content/featured-snippet.ts +367 -0
- package/src/content/generator.test.ts +534 -0
- package/src/content/generator.ts +501 -0
- package/src/content/headline.ts +317 -0
- package/src/content/index.ts +62 -0
- package/src/content/intent.ts +258 -0
- package/src/content/keyword-density.ts +349 -0
- package/src/content/readability.ts +262 -0
- package/src/executor.ts +336 -0
- package/src/fixer.ts +416 -0
- package/src/frameworks/detector.test.ts +248 -0
- package/src/frameworks/detector.ts +371 -0
- package/src/frameworks/index.ts +68 -0
- package/src/frameworks/recipes/angular.yaml +171 -0
- package/src/frameworks/recipes/astro.yaml +206 -0
- package/src/frameworks/recipes/django.yaml +180 -0
- package/src/frameworks/recipes/laravel.yaml +137 -0
- package/src/frameworks/recipes/nextjs.yaml +268 -0
- package/src/frameworks/recipes/nuxt.yaml +175 -0
- package/src/frameworks/recipes/rails.yaml +188 -0
- package/src/frameworks/recipes/react.yaml +202 -0
- package/src/frameworks/recipes/sveltekit.yaml +154 -0
- package/src/frameworks/recipes/vue.yaml +137 -0
- package/src/frameworks/recipes/wordpress.yaml +209 -0
- package/src/frameworks/suggestion-engine.ts +320 -0
- package/src/geo/geo-content.test.ts +305 -0
- package/src/geo/geo-content.ts +266 -0
- package/src/geo/geo-history.test.ts +473 -0
- package/src/geo/geo-history.ts +433 -0
- package/src/geo/geo-tracker.test.ts +359 -0
- package/src/geo/geo-tracker.ts +411 -0
- package/src/geo/index.ts +10 -0
- package/src/git/commit-helper.test.ts +261 -0
- package/src/git/commit-helper.ts +329 -0
- package/src/git/index.ts +12 -0
- package/src/git/pr-helper.test.ts +284 -0
- package/src/git/pr-helper.ts +307 -0
- package/src/index.ts +66 -0
- package/src/keywords/ai-keyword-engine.ts +1062 -0
- package/src/keywords/ai-summarizer.ts +387 -0
- package/src/keywords/ci-mode.ts +555 -0
- package/src/keywords/engine.ts +359 -0
- package/src/keywords/index.ts +151 -0
- package/src/keywords/llm-judge.ts +357 -0
- package/src/keywords/nlp-analysis.ts +706 -0
- package/src/keywords/prioritizer.ts +295 -0
- package/src/keywords/site-crawler.ts +342 -0
- package/src/keywords/sources/autocomplete.ts +139 -0
- package/src/keywords/sources/competitive-search.ts +450 -0
- package/src/keywords/sources/competitor-analysis.ts +374 -0
- package/src/keywords/sources/dataforseo.ts +206 -0
- package/src/keywords/sources/free-sources.ts +294 -0
- package/src/keywords/sources/gsc.ts +123 -0
- package/src/keywords/topic-grouping.ts +327 -0
- package/src/keywords/types.ts +144 -0
- package/src/keywords/wizard.ts +457 -0
- package/src/loader.ts +40 -0
- package/src/reports/index.ts +7 -0
- package/src/reports/report-generator.test.ts +293 -0
- package/src/reports/report-generator.ts +713 -0
- package/src/scheduler/alerts.test.ts +458 -0
- package/src/scheduler/alerts.ts +328 -0
- package/src/scheduler/index.ts +8 -0
- package/src/scheduler/scheduled-audit.test.ts +377 -0
- package/src/scheduler/scheduled-audit.ts +149 -0
- package/src/test/integration-test.ts +325 -0
- package/src/tools/analyzer.ts +373 -0
- package/src/tools/crawl.ts +293 -0
- package/src/tools/files.ts +301 -0
- package/src/tools/h1-fixer.ts +249 -0
- package/src/tools/index.ts +67 -0
- package/src/tracking/github-action.ts +326 -0
- package/src/tracking/google-analytics.ts +265 -0
- package/src/tracking/index.ts +45 -0
- package/src/tracking/report-generator.ts +386 -0
- package/src/tracking/search-console.ts +335 -0
- package/src/types.ts +134 -0
- package/src/utils/http.ts +302 -0
- package/src/wasm-adapter.ts +297 -0
- package/src/wasm-entry.ts +14 -0
- package/tsconfig.json +17 -0
- package/tsup.wasm.config.ts +26 -0
- package/vitest.config.ts +15 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// Featured Snippet Optimization Checks
|
|
2
|
+
// Based on advanced SEO research: optimizing content for featured snippets
|
|
3
|
+
// Includes: definition format, list format, table format, Q&A structure
|
|
4
|
+
|
|
5
|
+
import * as cheerio from 'cheerio';
|
|
6
|
+
import type { AuditIssue } from '../types.js';
|
|
7
|
+
|
|
8
|
+
export interface SnippetOpportunity {
|
|
9
|
+
type: 'definition' | 'list' | 'table' | 'paragraph' | 'qa';
|
|
10
|
+
heading: string;
|
|
11
|
+
score: number; // 0-100 optimization score
|
|
12
|
+
issues: string[];
|
|
13
|
+
suggestions: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface FeaturedSnippetData {
|
|
17
|
+
hasDefinitionFormat: boolean;
|
|
18
|
+
hasListFormat: boolean;
|
|
19
|
+
hasTableFormat: boolean;
|
|
20
|
+
hasQAFormat: boolean;
|
|
21
|
+
hasInvertedPyramid: boolean;
|
|
22
|
+
opportunities: SnippetOpportunity[];
|
|
23
|
+
faqSchemaPresent: boolean;
|
|
24
|
+
howToSchemaPresent: boolean;
|
|
25
|
+
questionHeadingsCount: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Detect definition-style content (optimal for "what is" snippets)
|
|
30
|
+
* Pattern: "X is a/an [noun] that..."
|
|
31
|
+
*/
|
|
32
|
+
export function detectDefinitionFormat(html: string): {
|
|
33
|
+
found: boolean;
|
|
34
|
+
definitions: Array<{ term: string; definition: string }>;
|
|
35
|
+
} {
|
|
36
|
+
const $ = cheerio.load(html);
|
|
37
|
+
const definitions: Array<{ term: string; definition: string }> = [];
|
|
38
|
+
|
|
39
|
+
// Check for <dfn> tags
|
|
40
|
+
$('dfn').each((_, el) => {
|
|
41
|
+
const term = $(el).text().trim();
|
|
42
|
+
const parent = $(el).parent().text().trim();
|
|
43
|
+
if (term && parent) {
|
|
44
|
+
definitions.push({ term, definition: parent });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Check for "X is a/an" patterns in paragraphs following H2/H3
|
|
49
|
+
$('h2, h3').each((_, el) => {
|
|
50
|
+
const heading = $(el).text().trim();
|
|
51
|
+
const nextP = $(el).next('p').text().trim();
|
|
52
|
+
|
|
53
|
+
// Pattern: starts with a noun phrase and "is a/an"
|
|
54
|
+
const definitionPattern = /^([\w\s]+)\s+is\s+(?:a|an|the)\s+[\w\s]+(?:that|which|who)/i;
|
|
55
|
+
const match = nextP.match(definitionPattern);
|
|
56
|
+
|
|
57
|
+
if (match) {
|
|
58
|
+
definitions.push({ term: match[1].trim(), definition: nextP.substring(0, 200) });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return { found: definitions.length > 0, definitions };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Detect list-format content (optimal for "how to" and "best X" snippets)
|
|
67
|
+
*/
|
|
68
|
+
export function detectListFormat(html: string): {
|
|
69
|
+
found: boolean;
|
|
70
|
+
lists: Array<{ type: 'ol' | 'ul'; itemCount: number; context: string }>;
|
|
71
|
+
} {
|
|
72
|
+
const $ = cheerio.load(html);
|
|
73
|
+
const lists: Array<{ type: 'ol' | 'ul'; itemCount: number; context: string }> = [];
|
|
74
|
+
|
|
75
|
+
// Find ordered lists after headings
|
|
76
|
+
$('h2, h3').each((_, el) => {
|
|
77
|
+
const heading = $(el).text().trim();
|
|
78
|
+
const nextEl = $(el).next();
|
|
79
|
+
|
|
80
|
+
if (nextEl.is('ol')) {
|
|
81
|
+
const items = nextEl.find('li').length;
|
|
82
|
+
if (items >= 3 && items <= 10) {
|
|
83
|
+
lists.push({ type: 'ol', itemCount: items, context: heading });
|
|
84
|
+
}
|
|
85
|
+
} else if (nextEl.is('ul')) {
|
|
86
|
+
const items = nextEl.find('li').length;
|
|
87
|
+
if (items >= 3 && items <= 10) {
|
|
88
|
+
lists.push({ type: 'ul', itemCount: items, context: heading });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return { found: lists.length > 0, lists };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Detect table-format content (optimal for comparison snippets)
|
|
98
|
+
*/
|
|
99
|
+
export function detectTableFormat(html: string): {
|
|
100
|
+
found: boolean;
|
|
101
|
+
tables: Array<{ hasHeaders: boolean; rows: number; cols: number }>;
|
|
102
|
+
} {
|
|
103
|
+
const $ = cheerio.load(html);
|
|
104
|
+
const tables: Array<{ hasHeaders: boolean; rows: number; cols: number }> = [];
|
|
105
|
+
|
|
106
|
+
$('table').each((_, el) => {
|
|
107
|
+
const $table = $(el);
|
|
108
|
+
const hasHeaders = $table.find('th').length > 0 || $table.find('thead').length > 0;
|
|
109
|
+
const rows = $table.find('tr').length;
|
|
110
|
+
const cols = $table.find('tr').first().find('td, th').length;
|
|
111
|
+
|
|
112
|
+
// Good snippet tables have 3-5 columns and 4-10 rows
|
|
113
|
+
if (cols >= 2 && cols <= 6 && rows >= 3 && rows <= 15) {
|
|
114
|
+
tables.push({ hasHeaders, rows, cols });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return { found: tables.length > 0, tables };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Detect Q&A format content (optimal for PAA boxes and FAQ snippets)
|
|
123
|
+
*/
|
|
124
|
+
export function detectQAFormat(html: string): {
|
|
125
|
+
found: boolean;
|
|
126
|
+
qaCount: number;
|
|
127
|
+
questions: string[];
|
|
128
|
+
} {
|
|
129
|
+
const $ = cheerio.load(html);
|
|
130
|
+
const questions: string[] = [];
|
|
131
|
+
|
|
132
|
+
// Question patterns in headings
|
|
133
|
+
const questionPatterns = [
|
|
134
|
+
/^what\s+/i,
|
|
135
|
+
/^how\s+/i,
|
|
136
|
+
/^why\s+/i,
|
|
137
|
+
/^when\s+/i,
|
|
138
|
+
/^where\s+/i,
|
|
139
|
+
/^who\s+/i,
|
|
140
|
+
/^which\s+/i,
|
|
141
|
+
/^can\s+/i,
|
|
142
|
+
/^does\s+/i,
|
|
143
|
+
/^is\s+/i,
|
|
144
|
+
/^are\s+/i,
|
|
145
|
+
/^should\s+/i,
|
|
146
|
+
/\?$/,
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
// Check H2-H4 headings for questions
|
|
150
|
+
$('h2, h3, h4').each((_, el) => {
|
|
151
|
+
const text = $(el).text().trim();
|
|
152
|
+
for (const pattern of questionPatterns) {
|
|
153
|
+
if (pattern.test(text)) {
|
|
154
|
+
questions.push(text);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Check for FAQ sections
|
|
161
|
+
const hasFaqSection =
|
|
162
|
+
$('section.faq, div.faq, #faq, .faqs, [data-faq]').length > 0 ||
|
|
163
|
+
$('h2, h3').text().toLowerCase().includes('faq') ||
|
|
164
|
+
$('h2, h3').text().toLowerCase().includes('frequently asked');
|
|
165
|
+
|
|
166
|
+
// Check for details/summary elements (accordion FAQs)
|
|
167
|
+
$('details summary').each((_, el) => {
|
|
168
|
+
const text = $(el).text().trim();
|
|
169
|
+
if (text.endsWith('?') || questionPatterns.some((p) => p.test(text))) {
|
|
170
|
+
questions.push(text);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return { found: questions.length > 0 || hasFaqSection, qaCount: questions.length, questions };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Check for inverted pyramid structure (key info first)
|
|
179
|
+
*/
|
|
180
|
+
export function detectInvertedPyramid(html: string): { found: boolean; score: number } {
|
|
181
|
+
const $ = cheerio.load(html);
|
|
182
|
+
|
|
183
|
+
// Remove non-content elements
|
|
184
|
+
$('script, style, nav, header, footer, aside').remove();
|
|
185
|
+
|
|
186
|
+
// Get first paragraph after H1
|
|
187
|
+
const h1 = $('h1').first();
|
|
188
|
+
const firstContent = h1.nextAll('p').first().text().trim();
|
|
189
|
+
|
|
190
|
+
if (!firstContent) {
|
|
191
|
+
return { found: false, score: 0 };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Check for answer patterns in first paragraph
|
|
195
|
+
const answerPatterns = [
|
|
196
|
+
/^the\s+answer\s+is/i,
|
|
197
|
+
/^yes[,\s]/i,
|
|
198
|
+
/^no[,\s]/i,
|
|
199
|
+
/^in\s+short/i,
|
|
200
|
+
/^to\s+summarize/i,
|
|
201
|
+
/^([\w\s]+)\s+is\s+/i, // Definition pattern
|
|
202
|
+
/^\d+/i, // Starts with number
|
|
203
|
+
/^the\s+best\s+/i,
|
|
204
|
+
/^you\s+(can|should|need)/i,
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
let score = 0;
|
|
208
|
+
|
|
209
|
+
// Check if first paragraph contains direct answer
|
|
210
|
+
for (const pattern of answerPatterns) {
|
|
211
|
+
if (pattern.test(firstContent)) {
|
|
212
|
+
score += 30;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Check word count of first paragraph (should be concise: 40-80 words)
|
|
218
|
+
const wordCount = firstContent.split(/\s+/).length;
|
|
219
|
+
if (wordCount >= 40 && wordCount <= 100) {
|
|
220
|
+
score += 30;
|
|
221
|
+
} else if (wordCount > 0 && wordCount < 40) {
|
|
222
|
+
score += 15;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Check if key terms from title appear in first paragraph
|
|
226
|
+
const title = $('title').text().toLowerCase();
|
|
227
|
+
const titleWords = title
|
|
228
|
+
.replace(/[^a-z0-9\s]/g, '')
|
|
229
|
+
.split(/\s+/)
|
|
230
|
+
.filter((w) => w.length > 3);
|
|
231
|
+
|
|
232
|
+
const firstParaLower = firstContent.toLowerCase();
|
|
233
|
+
const matchingWords = titleWords.filter((w) => firstParaLower.includes(w));
|
|
234
|
+
const titleMatchRatio = titleWords.length > 0 ? matchingWords.length / titleWords.length : 0;
|
|
235
|
+
|
|
236
|
+
if (titleMatchRatio > 0.5) {
|
|
237
|
+
score += 40;
|
|
238
|
+
} else if (titleMatchRatio > 0.25) {
|
|
239
|
+
score += 20;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return { found: score >= 50, score: Math.min(score, 100) };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Check for structured data that supports snippets
|
|
247
|
+
*/
|
|
248
|
+
export function detectSnippetSchema(html: string): {
|
|
249
|
+
hasFaqSchema: boolean;
|
|
250
|
+
hasHowToSchema: boolean;
|
|
251
|
+
hasQASchema: boolean;
|
|
252
|
+
} {
|
|
253
|
+
const $ = cheerio.load(html);
|
|
254
|
+
|
|
255
|
+
let hasFaqSchema = false;
|
|
256
|
+
let hasHowToSchema = false;
|
|
257
|
+
let hasQASchema = false;
|
|
258
|
+
|
|
259
|
+
// Check JSON-LD scripts
|
|
260
|
+
$('script[type="application/ld+json"]').each((_, el) => {
|
|
261
|
+
try {
|
|
262
|
+
const data = JSON.parse($(el).html() || '');
|
|
263
|
+
const types = Array.isArray(data) ? data.map((d) => d['@type']) : [data['@type']];
|
|
264
|
+
|
|
265
|
+
if (types.includes('FAQPage') || types.some((t) => t?.includes?.('FAQPage'))) {
|
|
266
|
+
hasFaqSchema = true;
|
|
267
|
+
}
|
|
268
|
+
if (types.includes('HowTo') || types.some((t) => t?.includes?.('HowTo'))) {
|
|
269
|
+
hasHowToSchema = true;
|
|
270
|
+
}
|
|
271
|
+
if (types.includes('QAPage') || types.some((t) => t?.includes?.('QAPage'))) {
|
|
272
|
+
hasQASchema = true;
|
|
273
|
+
}
|
|
274
|
+
} catch {
|
|
275
|
+
// Invalid JSON
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return { hasFaqSchema, hasHowToSchema, hasQASchema };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Analyze snippet bait headers (trigger words for featured snippets)
|
|
284
|
+
*/
|
|
285
|
+
export function analyzeSnippetBaitHeaders(html: string): string[] {
|
|
286
|
+
const $ = cheerio.load(html);
|
|
287
|
+
const snippetBaitHeaders: string[] = [];
|
|
288
|
+
|
|
289
|
+
// High-value snippet trigger patterns
|
|
290
|
+
const triggerPatterns = [
|
|
291
|
+
/^what\s+is\s+/i,
|
|
292
|
+
/^how\s+to\s+/i,
|
|
293
|
+
/^how\s+do\s+/i,
|
|
294
|
+
/^how\s+does\s+/i,
|
|
295
|
+
/^why\s+is\s+/i,
|
|
296
|
+
/^why\s+do\s+/i,
|
|
297
|
+
/^why\s+does\s+/i,
|
|
298
|
+
/^when\s+to\s+/i,
|
|
299
|
+
/^where\s+to\s+/i,
|
|
300
|
+
/^\d+\s+(ways|tips|steps|reasons|benefits|examples)/i,
|
|
301
|
+
/^(best|top)\s+\d+/i,
|
|
302
|
+
/^(guide|tutorial):/i,
|
|
303
|
+
/\s+vs\s+/i,
|
|
304
|
+
/^definition\s+of/i,
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
$('h2, h3').each((_, el) => {
|
|
308
|
+
const text = $(el).text().trim();
|
|
309
|
+
for (const pattern of triggerPatterns) {
|
|
310
|
+
if (pattern.test(text)) {
|
|
311
|
+
snippetBaitHeaders.push(text);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
return snippetBaitHeaders;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Main function: Analyze page for featured snippet optimization
|
|
322
|
+
*/
|
|
323
|
+
export function analyzeFeaturedSnippet(
|
|
324
|
+
html: string,
|
|
325
|
+
url: string
|
|
326
|
+
): { issues: AuditIssue[]; data: FeaturedSnippetData } {
|
|
327
|
+
const issues: AuditIssue[] = [];
|
|
328
|
+
|
|
329
|
+
const definitions = detectDefinitionFormat(html);
|
|
330
|
+
const lists = detectListFormat(html);
|
|
331
|
+
const tables = detectTableFormat(html);
|
|
332
|
+
const qa = detectQAFormat(html);
|
|
333
|
+
const invertedPyramid = detectInvertedPyramid(html);
|
|
334
|
+
const schema = detectSnippetSchema(html);
|
|
335
|
+
const snippetBaitHeaders = analyzeSnippetBaitHeaders(html);
|
|
336
|
+
|
|
337
|
+
const opportunities: SnippetOpportunity[] = [];
|
|
338
|
+
|
|
339
|
+
// Analyze definition opportunities
|
|
340
|
+
if (!definitions.found) {
|
|
341
|
+
opportunities.push({
|
|
342
|
+
type: 'definition',
|
|
343
|
+
heading: 'Missing definition format',
|
|
344
|
+
score: 0,
|
|
345
|
+
issues: ['No clear definition patterns found'],
|
|
346
|
+
suggestions: [
|
|
347
|
+
'Add a paragraph starting with "[Topic] is a [noun] that..." after your main heading',
|
|
348
|
+
'Use <dfn> tags for key term definitions',
|
|
349
|
+
'Keep definitions concise (40-60 words)',
|
|
350
|
+
],
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Analyze list opportunities
|
|
355
|
+
if (lists.found) {
|
|
356
|
+
for (const list of lists.lists) {
|
|
357
|
+
if (!list.context.toLowerCase().match(/^\d+|^(how|steps|tips|ways)/)) {
|
|
358
|
+
opportunities.push({
|
|
359
|
+
type: 'list',
|
|
360
|
+
heading: list.context,
|
|
361
|
+
score: 70,
|
|
362
|
+
issues: ['List heading could be more snippet-friendly'],
|
|
363
|
+
suggestions: [
|
|
364
|
+
'Consider rephrasing to "X Steps to..." or "Top X Tips for..."',
|
|
365
|
+
'Ensure list items are parallel in structure',
|
|
366
|
+
],
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
opportunities.push({
|
|
372
|
+
type: 'list',
|
|
373
|
+
heading: 'Missing list content',
|
|
374
|
+
score: 0,
|
|
375
|
+
issues: ['No optimized lists found for snippet targeting'],
|
|
376
|
+
suggestions: [
|
|
377
|
+
'Add numbered or bulleted lists with 4-8 items',
|
|
378
|
+
'Use headers like "Steps to...", "Ways to...", or "Top X..."',
|
|
379
|
+
'Keep list items concise and parallel in structure',
|
|
380
|
+
],
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Analyze table opportunities
|
|
385
|
+
if (!tables.found) {
|
|
386
|
+
opportunities.push({
|
|
387
|
+
type: 'table',
|
|
388
|
+
heading: 'No comparison tables',
|
|
389
|
+
score: 0,
|
|
390
|
+
issues: ['No tables optimized for comparison snippets'],
|
|
391
|
+
suggestions: [
|
|
392
|
+
'Add comparison tables with clear headers',
|
|
393
|
+
'Use 3-5 columns and 4-10 rows for optimal snippet display',
|
|
394
|
+
'Include thead with th elements for proper table structure',
|
|
395
|
+
],
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Analyze Q&A opportunities
|
|
400
|
+
if (qa.found && qa.qaCount > 0) {
|
|
401
|
+
if (!schema.hasFaqSchema && qa.qaCount >= 3) {
|
|
402
|
+
issues.push({
|
|
403
|
+
code: 'FAQ_SCHEMA_MISSING',
|
|
404
|
+
severity: 'warning',
|
|
405
|
+
category: 'structured-data',
|
|
406
|
+
title: 'FAQ content without FAQPage schema',
|
|
407
|
+
description: `Found ${qa.qaCount} question-format headings but no FAQPage schema markup.`,
|
|
408
|
+
impact: 'Missing out on FAQ rich results and PAA box opportunities.',
|
|
409
|
+
howToFix: 'Add FAQPage structured data for your Q&A content.',
|
|
410
|
+
affectedUrls: [url],
|
|
411
|
+
details: { questions: qa.questions.slice(0, 5) },
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
} else {
|
|
415
|
+
opportunities.push({
|
|
416
|
+
type: 'qa',
|
|
417
|
+
heading: 'Missing Q&A content',
|
|
418
|
+
score: 0,
|
|
419
|
+
issues: ['No question-format headers found'],
|
|
420
|
+
suggestions: [
|
|
421
|
+
'Add H2/H3 headings in question format (What is..., How to..., Why does...)',
|
|
422
|
+
'Follow each question heading with a direct answer paragraph',
|
|
423
|
+
'Consider adding a FAQ section with 3-5 common questions',
|
|
424
|
+
],
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Analyze inverted pyramid
|
|
429
|
+
if (!invertedPyramid.found) {
|
|
430
|
+
issues.push({
|
|
431
|
+
code: 'INVERTED_PYRAMID_MISSING',
|
|
432
|
+
severity: 'notice',
|
|
433
|
+
category: 'content',
|
|
434
|
+
title: 'Content not structured for featured snippets',
|
|
435
|
+
description: 'First paragraph does not contain a direct answer or summary.',
|
|
436
|
+
impact: 'Featured snippets pull from early content; burying answers reduces snippet capture rate.',
|
|
437
|
+
howToFix: 'Start with a concise answer (40-80 words) that directly addresses the page topic.',
|
|
438
|
+
affectedUrls: [url],
|
|
439
|
+
details: { invertedPyramidScore: invertedPyramid.score },
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Check for snippet bait headers
|
|
444
|
+
if (snippetBaitHeaders.length === 0) {
|
|
445
|
+
issues.push({
|
|
446
|
+
code: 'NO_SNIPPET_BAIT_HEADERS',
|
|
447
|
+
severity: 'notice',
|
|
448
|
+
category: 'on-page',
|
|
449
|
+
title: 'No snippet-targeting headers found',
|
|
450
|
+
description: 'Headings do not use patterns that commonly trigger featured snippets.',
|
|
451
|
+
impact: 'Missing opportunities for high-visibility snippet placements.',
|
|
452
|
+
howToFix:
|
|
453
|
+
'Use headers like "What is [topic]?", "How to [action]", or "X Ways to [achieve goal]".',
|
|
454
|
+
affectedUrls: [url],
|
|
455
|
+
details: { suggestedPatterns: ['What is X?', 'How to X', 'X Steps to Y', 'Best X for Y'] },
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return {
|
|
460
|
+
issues,
|
|
461
|
+
data: {
|
|
462
|
+
hasDefinitionFormat: definitions.found,
|
|
463
|
+
hasListFormat: lists.found,
|
|
464
|
+
hasTableFormat: tables.found,
|
|
465
|
+
hasQAFormat: qa.found,
|
|
466
|
+
hasInvertedPyramid: invertedPyramid.found,
|
|
467
|
+
opportunities,
|
|
468
|
+
faqSchemaPresent: schema.hasFaqSchema,
|
|
469
|
+
howToSchemaPresent: schema.hasHowToSchema,
|
|
470
|
+
questionHeadingsCount: qa.qaCount,
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
}
|