sanity-plugin-seo-copilot 0.2.1 → 0.2.7
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/dist/index.js +1407 -638
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1407 -638
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/KeywordPanel.tsx +170 -5
- package/src/components/OnboardingPopup.tsx +108 -0
- package/src/components/SEOCopilotPanel.tsx +123 -14
- package/src/components/styles.ts +8 -0
- package/src/components/tabs/AEOTab.tsx +9 -3
- package/src/components/tabs/LinkingTab.tsx +77 -4
- package/src/components/tabs/MetaTab.tsx +40 -115
- package/src/components/tabs/SummaryTab.tsx +19 -4
- package/src/components/tabs/TechnicalTab.tsx +200 -29
- package/src/hooks/useDocumentContent.ts +6 -174
- package/src/hooks/useKeywordAnalysis.ts +33 -4
- package/src/hooks/useSEOChat.ts +61 -16
- package/src/lib/api.ts +25 -7
- package/src/lib/documentExtract.ts +268 -0
- package/src/lib/geoAnalysis.ts +16 -3
- package/src/lib/scoring.ts +69 -19
- package/src/lib/summary.ts +169 -28
- package/src/lib/types.ts +4 -1
package/src/lib/scoring.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SEOAnalysis } from "./types";
|
|
1
|
+
import type { SEOAnalysis, DocumentFields } from "./types";
|
|
2
2
|
|
|
3
3
|
export interface ScoreComponent {
|
|
4
4
|
label: string;
|
|
@@ -12,11 +12,21 @@ export interface ContentScore {
|
|
|
12
12
|
components: ScoreComponent[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// Count whole-word / whole-phrase occurrences, anchored on word boundaries, so a
|
|
16
|
+
// short token like "as" or "cm" can't match inside "phase" or "cmv". Safari-safe:
|
|
17
|
+
// uses \b only (no lookbehind). The needle is regex-escaped.
|
|
18
|
+
function countWholeMatches(haystack: string, needle: string): number {
|
|
19
|
+
if (!needle) return 0;
|
|
20
|
+
const esc = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
|
+
const m = haystack.match(new RegExp(`\\b${esc}\\b`, "g"));
|
|
22
|
+
return m ? m.length : 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
/**
|
|
16
26
|
* Client-side content score (0-100) with per-component breakdown.
|
|
17
27
|
* Mirrors backend scoring.ts.
|
|
18
28
|
*/
|
|
19
|
-
export function calculateContentScoreDetailed(content: string, analysis: SEOAnalysis): ContentScore {
|
|
29
|
+
export function calculateContentScoreDetailed(content: string, analysis: SEOAnalysis, documentFields?: DocumentFields): ContentScore {
|
|
20
30
|
if (!content || !analysis) {
|
|
21
31
|
return { total: 0, components: [] };
|
|
22
32
|
}
|
|
@@ -27,23 +37,44 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
27
37
|
// 1. Primary keyword (up to 25)
|
|
28
38
|
const primaryTerm = (analysis.primaryKeyword?.term || "").toLowerCase();
|
|
29
39
|
if (primaryTerm) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
// A multi-word primary like "acoramidis ATTR-CM" almost never appears as an
|
|
41
|
+
// adjacent phrase, but if every token is in the body the keyword IS present.
|
|
42
|
+
// Try the exact phrase first; otherwise fall back to token co-occurrence (all
|
|
43
|
+
// tokens present) and use the rarest token as the concept's mention count.
|
|
44
|
+
// (This mirrors tokensContain() used by the Meta + Summary audits.)
|
|
45
|
+
const tokens = primaryTerm.split(/\s+/).filter((t) => t.length > 1);
|
|
46
|
+
const phraseCount = countWholeMatches(lowerContent, primaryTerm);
|
|
47
|
+
let occurrences = phraseCount;
|
|
48
|
+
let viaTokens = false;
|
|
49
|
+
if (phraseCount === 0 && tokens.length > 0) {
|
|
50
|
+
const counts = tokens.map((t) => countWholeMatches(lowerContent, t));
|
|
51
|
+
if (counts.every((c) => c > 0)) {
|
|
52
|
+
occurrences = Math.min(...counts);
|
|
53
|
+
viaTokens = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const primaryWordCount = Math.max(1, primaryTerm.split(/\s+/).filter(Boolean).length);
|
|
34
57
|
let pts = 0;
|
|
35
58
|
let detail: string;
|
|
36
|
-
if (
|
|
59
|
+
if (occurrences === 0) {
|
|
37
60
|
detail = `Primary keyword "${primaryTerm}" not found in content`;
|
|
38
61
|
} else {
|
|
39
62
|
pts += 12;
|
|
40
|
-
|
|
63
|
+
// Exact phrase: an N-word phrase appearing M times occupies M*N keyword-words.
|
|
64
|
+
// Token co-occurrence: tokens are spread through the body, so count each once.
|
|
65
|
+
const density = words > 0
|
|
66
|
+
? ((viaTokens ? occurrences : occurrences * primaryWordCount) / words) * 100
|
|
67
|
+
: 0;
|
|
41
68
|
if (density >= 0.5 && density <= 2.5) {
|
|
42
69
|
pts += 13;
|
|
43
70
|
detail = `Primary keyword present, density ${density.toFixed(2)}% (ideal range)`;
|
|
44
71
|
} else if (density < 0.5) {
|
|
45
72
|
pts += 7;
|
|
46
73
|
detail = `Primary keyword present but density only ${density.toFixed(2)}% - aim for 0.5-2.5%`;
|
|
74
|
+
} else if (viaTokens && density <= 6) {
|
|
75
|
+
// Tokens spread through the body is topical depth, not keyword stuffing.
|
|
76
|
+
pts += 11;
|
|
77
|
+
detail = `Primary keyword strongly represented (${density.toFixed(2)}%)`;
|
|
47
78
|
} else {
|
|
48
79
|
pts += 4;
|
|
49
80
|
detail = `Primary keyword over-used at ${density.toFixed(2)}% density - reduce to 0.5-2.5%`;
|
|
@@ -89,15 +120,29 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
89
120
|
components.push({ label: "Word count", points: wcPts, max: 15, detail: wcDetail });
|
|
90
121
|
|
|
91
122
|
// 4. Heading structure (up to 10)
|
|
92
|
-
|
|
93
|
-
|
|
123
|
+
// Prefer the structured heading data the plugin extracts from Portable Text.
|
|
124
|
+
// The plain `content` string has no markup, so regexing it for #/<h3> always
|
|
125
|
+
// misses real headings - fall back to the regex only for plain-text callers.
|
|
126
|
+
let hasH1orTitle: boolean;
|
|
127
|
+
let hasSubheadings: boolean;
|
|
128
|
+
if (documentFields) {
|
|
129
|
+
hasH1orTitle = !!(documentFields.title && documentFields.title.trim());
|
|
130
|
+
const det = documentFields.headingsDetailed;
|
|
131
|
+
// Any H2+ heading counts as a subheading. Fall back to the flat heading list
|
|
132
|
+
// when the detailed list is absent OR empty, so a real outline is never missed.
|
|
133
|
+
const detHasSub = Array.isArray(det) && det.some((h) => h.level >= 2);
|
|
134
|
+
hasSubheadings = detHasSub || (documentFields.headings?.length || 0) > 0;
|
|
135
|
+
} else {
|
|
136
|
+
hasH1orTitle = /^#\s|<h1/im.test(content);
|
|
137
|
+
hasSubheadings = /^##\s|^###\s|<h2|<h3/im.test(content);
|
|
138
|
+
}
|
|
94
139
|
const structurePts = (hasH1orTitle ? 5 : 0) + (hasSubheadings ? 5 : 0);
|
|
95
140
|
const structureDetail = !hasH1orTitle && !hasSubheadings
|
|
96
|
-
? "No
|
|
141
|
+
? "No title or subheadings detected"
|
|
97
142
|
: !hasSubheadings
|
|
98
|
-
? "Has title but no subheadings"
|
|
143
|
+
? "Has a title but no H2/H3 subheadings - add section headings"
|
|
99
144
|
: !hasH1orTitle
|
|
100
|
-
? "Has subheadings but no
|
|
145
|
+
? "Has subheadings but no title"
|
|
101
146
|
: "Title and subheadings present";
|
|
102
147
|
components.push({ label: "Heading structure", points: structurePts, max: 10, detail: structureDetail });
|
|
103
148
|
|
|
@@ -122,13 +167,18 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
122
167
|
// 6. AEO signals (up to 10) - question-format headings that Google answer
|
|
123
168
|
// features and AI engines surface directly. (FAQ scoring removed May 2026 after
|
|
124
169
|
// Google sunset FAQ rich results - question headings are the modern equivalent.)
|
|
170
|
+
// Detect from the structured heading list (plain `content` has no heading
|
|
171
|
+
// markup to regex). Single clean tier: 0 / 4 / 7 / 10 for 0 / 1 / 2 / 3+.
|
|
172
|
+
let qCount: number;
|
|
173
|
+
if (documentFields) {
|
|
174
|
+
qCount = (documentFields.headings || []).filter((h) => h.trim().endsWith("?")).length;
|
|
175
|
+
} else {
|
|
176
|
+
qCount = (content.match(/^#{1,6}\s+.*\?$/gm) || []).length + (content.match(/<h[1-6][^>]*>.*\?<\/h[1-6]>/gi) || []).length;
|
|
177
|
+
}
|
|
125
178
|
let aeoPts = 0;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (qCount
|
|
129
|
-
else if (qCount === 2) aeoPts += 4;
|
|
130
|
-
else if (qCount === 1) aeoPts += 2;
|
|
131
|
-
if (qCount > 0) aeoPts += 4;
|
|
179
|
+
if (qCount >= 3) aeoPts = 10;
|
|
180
|
+
else if (qCount === 2) aeoPts = 7;
|
|
181
|
+
else if (qCount === 1) aeoPts = 4;
|
|
132
182
|
const aeoDetail =
|
|
133
183
|
qCount === 0
|
|
134
184
|
? "No question-style headings - AI answer engines favor them"
|
package/src/lib/summary.ts
CHANGED
|
@@ -21,6 +21,11 @@ interface BuildSummaryInput {
|
|
|
21
21
|
// When non-empty, broken/errored entries surface here as their own issue.
|
|
22
22
|
linkCheckResults?: LinkCheckResult[];
|
|
23
23
|
text: string;
|
|
24
|
+
// The editor's SELECTED primary keyword (effectivePrimary). Falls back to the
|
|
25
|
+
// analysis' top candidate when not supplied.
|
|
26
|
+
primaryKeyword?: string;
|
|
27
|
+
// Optional secondary target keyword - items flag where it's missing.
|
|
28
|
+
secondaryKeyword?: string;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
function tokensContain(haystack: string, needle?: string): boolean {
|
|
@@ -31,12 +36,46 @@ function tokensContain(haystack: string, needle?: string): boolean {
|
|
|
31
36
|
return tokens.every((t) => lower.includes(t));
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
// True when the primary keyword leads the URL slug (within the first three words).
|
|
40
|
+
function keywordLeadsSlug(slug: string, primaryKeyword: string): boolean {
|
|
41
|
+
const slugWords = slug.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
|
|
42
|
+
const tokens = primaryKeyword.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
|
|
43
|
+
if (tokens.length === 0 || slugWords.length === 0) return true;
|
|
44
|
+
let earliest = Infinity;
|
|
45
|
+
for (const t of tokens) {
|
|
46
|
+
const idx = slugWords.findIndex((w) => w.includes(t));
|
|
47
|
+
if (idx >= 0) earliest = Math.min(earliest, idx);
|
|
48
|
+
}
|
|
49
|
+
return earliest <= 2;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Conference previews, news briefs, recaps, and listicles are legitimately short.
|
|
53
|
+
// Detect them so we don't nag "push past 1,500 words" on content that should be
|
|
54
|
+
// short. Uses the contentCategory field when present, else title-pattern signals.
|
|
55
|
+
export function isShortFormContent(documentFields?: DocumentFields, title?: string): boolean {
|
|
56
|
+
const cat = (documentFields?.contentCategory || "").toLowerCase().trim();
|
|
57
|
+
// Media formats (video / podcast / episode / webinar): the body text is a summary
|
|
58
|
+
// of the media, not the article. Match the category AS A WHOLE so a written piece
|
|
59
|
+
// in a compound category like "clinical video interviews" is NOT exempted.
|
|
60
|
+
if (/^(videos?|podcasts?|episodes?|webinars?|video series|peer exchange)$/.test(cat)) return true;
|
|
61
|
+
// Written short formats - token match (not substring) so "newsletter" doesn't match
|
|
62
|
+
// "news" and "updated-guidelines" doesn't match "update".
|
|
63
|
+
const shortFormCats = new Set(["news", "brief", "preview", "recap", "update", "announcement", "roundup", "digest", "interview"]);
|
|
64
|
+
const catTokens = cat.split(/[^a-z]+/).filter(Boolean);
|
|
65
|
+
if (catTokens.some((tok) => shortFormCats.has(tok))) return true;
|
|
66
|
+
const t = (title || "").toLowerCase();
|
|
67
|
+
if (/\b(preview|recap|roundup|digest)\b/.test(t)) return true;
|
|
68
|
+
if (/:\s*\d+\s+(trials|things|takeaways|highlights|tips|questions|charts)/.test(t)) return true;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
34
72
|
export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
35
73
|
const items: SummaryItem[] = [];
|
|
36
74
|
// contentScore is in BuildSummaryInput for forward-compat but is now shown
|
|
37
75
|
// directly on the Summary tab as a card with breakdown - no echo item needed here.
|
|
38
76
|
const { analysis, deepAnalysis, documentFields, linkingSuggestions, linkCheckResults, text } = input;
|
|
39
|
-
const primaryKeyword = analysis?.primaryKeyword?.term;
|
|
77
|
+
const primaryKeyword = input.primaryKeyword || analysis?.primaryKeyword?.term;
|
|
78
|
+
const secondaryKeyword = input.secondaryKeyword || "";
|
|
40
79
|
|
|
41
80
|
// ---------- META: title ----------
|
|
42
81
|
// Length warnings removed - the article title IS the page title and editors
|
|
@@ -137,39 +176,41 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
137
176
|
}
|
|
138
177
|
}
|
|
139
178
|
|
|
140
|
-
// ----------
|
|
179
|
+
// ---------- URL slug (lives on the Other Recs tab) ----------
|
|
180
|
+
// No character-count nag and no "too long" - just scan for the primary keyword,
|
|
181
|
+
// ideally leading the URL. Keep the guidance vague (short + descriptive).
|
|
141
182
|
const slug = documentFields?.slug;
|
|
142
183
|
if (!slug) {
|
|
143
184
|
items.push({
|
|
144
185
|
id: "meta-slug-missing",
|
|
145
186
|
category: "meta",
|
|
146
|
-
severity: "
|
|
187
|
+
severity: "warning",
|
|
147
188
|
label: "URL slug missing",
|
|
148
189
|
description: "No URL slug set.",
|
|
149
|
-
howToFix: "Add a
|
|
150
|
-
jumpTo: { tab: "
|
|
190
|
+
howToFix: "Add a short, descriptive slug that leads with your primary keyword.",
|
|
191
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
151
192
|
});
|
|
152
193
|
} else {
|
|
153
|
-
|
|
194
|
+
const slugAsWords = slug.replace(/-/g, " ");
|
|
195
|
+
if (primaryKeyword && !tokensContain(slugAsWords, primaryKeyword)) {
|
|
154
196
|
items.push({
|
|
155
|
-
id: "meta-slug-
|
|
197
|
+
id: "meta-slug-no-keyword",
|
|
156
198
|
category: "meta",
|
|
157
|
-
severity: "
|
|
158
|
-
label: "
|
|
159
|
-
description: `
|
|
160
|
-
howToFix: "
|
|
161
|
-
jumpTo: { tab: "
|
|
199
|
+
severity: "opportunity",
|
|
200
|
+
label: "Primary keyword not in URL",
|
|
201
|
+
description: `The URL doesn't include "${primaryKeyword}".`,
|
|
202
|
+
howToFix: "Work the primary keyword into the URL, ideally at the start. Keep the URL short and descriptive.",
|
|
203
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
162
204
|
});
|
|
163
|
-
}
|
|
164
|
-
if (primaryKeyword && !tokensContain(slug.replace(/-/g, " "), primaryKeyword)) {
|
|
205
|
+
} else if (primaryKeyword && !keywordLeadsSlug(slug, primaryKeyword)) {
|
|
165
206
|
items.push({
|
|
166
|
-
id: "meta-slug-
|
|
207
|
+
id: "meta-slug-keyword-late",
|
|
167
208
|
category: "meta",
|
|
168
209
|
severity: "opportunity",
|
|
169
|
-
label: "Primary keyword
|
|
170
|
-
description: `
|
|
171
|
-
howToFix: "
|
|
172
|
-
jumpTo: { tab: "
|
|
210
|
+
label: "Primary keyword late in URL",
|
|
211
|
+
description: `"${primaryKeyword}" is in the URL but not near the start.`,
|
|
212
|
+
howToFix: "Lead the URL with the primary keyword so it stays visible if the address gets shortened.",
|
|
213
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
173
214
|
});
|
|
174
215
|
}
|
|
175
216
|
}
|
|
@@ -178,9 +219,12 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
178
219
|
// 450 is the body-text floor (per editor guidance). 1,500+ is the competitive
|
|
179
220
|
// target for HCP clinical articles.
|
|
180
221
|
const wordCount = text ? text.trim().split(/\s+/).filter(Boolean).length : 0;
|
|
222
|
+
// Videos, podcasts, news, briefs, etc. are legitimately short (the body is a
|
|
223
|
+
// summary, not the deliverable), so they're exempt from the word-count floor.
|
|
224
|
+
const isShortForm = isShortFormContent(documentFields, title);
|
|
181
225
|
if (wordCount === 0) {
|
|
182
226
|
// No item - empty doc state is handled by the empty-state UI elsewhere
|
|
183
|
-
} else if (wordCount < 450) {
|
|
227
|
+
} else if (wordCount < 450 && !isShortForm) {
|
|
184
228
|
items.push({
|
|
185
229
|
id: "content-too-short",
|
|
186
230
|
category: "content",
|
|
@@ -190,14 +234,14 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
190
234
|
howToFix: "Add more body text. A link or image on its own doesn't count - the article needs real written substance.",
|
|
191
235
|
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
192
236
|
});
|
|
193
|
-
} else if (wordCount < 1500) {
|
|
237
|
+
} else if (wordCount < 1500 && !isShortForm) {
|
|
194
238
|
items.push({
|
|
195
239
|
id: "content-short-for-clinical",
|
|
196
240
|
category: "content",
|
|
197
|
-
severity: "
|
|
241
|
+
severity: "opportunity",
|
|
198
242
|
label: "Article could be longer",
|
|
199
|
-
description: `${wordCount} words. 1,500+
|
|
200
|
-
howToFix: "
|
|
243
|
+
description: `${wordCount} words. For evergreen clinical topics 1,500+ tends to rank better - news, previews, and briefs are fine shorter.`,
|
|
244
|
+
howToFix: "If this is an in-depth clinical piece, expand with citations, comparative data, or guideline references. For news or previews, this length is appropriate.",
|
|
201
245
|
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
202
246
|
});
|
|
203
247
|
}
|
|
@@ -208,8 +252,9 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
208
252
|
// H2 count - prefer the detailed list (which records actual levels). When only
|
|
209
253
|
// a flat list is available the typical case is "all H2s", so we use the total
|
|
210
254
|
// as a fallback approximation.
|
|
255
|
+
// Count H2 AND H3 as section headings - an H3-only article is still sectioned.
|
|
211
256
|
const h2Count = headingsDetailed
|
|
212
|
-
? headingsDetailed.filter((h) => h.level === 2).length
|
|
257
|
+
? headingsDetailed.filter((h) => h.level === 2 || h.level === 3).length
|
|
213
258
|
: headings.length;
|
|
214
259
|
if (headings.length === 0 && wordCount > 200 && wordCount < 1000) {
|
|
215
260
|
items.push({
|
|
@@ -358,7 +403,11 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
358
403
|
// Image titles (the hover tooltip) - the director treats this as an SEO signal.
|
|
359
404
|
const imageTitleCount = (documentFields?.imageTitles || []).length;
|
|
360
405
|
const totalImageCount = documentFields?.imageCount ?? 0;
|
|
361
|
-
|
|
406
|
+
// Only flag missing titles when SOME image already has one (i.e. the schema
|
|
407
|
+
// actually exposes a title field). MJH combines alt + title into a single
|
|
408
|
+
// "Image ALT/Title Text" field, so imageTitleCount is always 0 there - flagging
|
|
409
|
+
// every image as "missing a title" was a false alarm. Mirrors TechnicalTab's skip.
|
|
410
|
+
const missingTitles = totalImageCount > 0 && imageTitleCount > 0 ? totalImageCount - imageTitleCount : 0;
|
|
362
411
|
if (missingTitles > 0) {
|
|
363
412
|
items.push({
|
|
364
413
|
id: "images-titles-missing",
|
|
@@ -387,6 +436,77 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
387
436
|
jumpTo: { tab: "keywords" },
|
|
388
437
|
});
|
|
389
438
|
}
|
|
439
|
+
// Primary keyword with no measurable search volume. Only meaningful once deep
|
|
440
|
+
// analysis has fetched real SEMrush volumes (realtime leaves volume null), so
|
|
441
|
+
// gate on deepAnalysis to avoid false warnings mid-typing.
|
|
442
|
+
const primaryVolume = analysis?.primaryKeyword?.volume;
|
|
443
|
+
// Only an explicit measured zero means "nobody searches this". A null volume
|
|
444
|
+
// means SEMrush simply had no data for the term (common for niche clinical
|
|
445
|
+
// phrases) - warning on null produced false positives, so we don't.
|
|
446
|
+
if (deepAnalysis && primaryVolume === 0) {
|
|
447
|
+
items.push({
|
|
448
|
+
id: "keywords-primary-zero-volume",
|
|
449
|
+
category: "keywords",
|
|
450
|
+
severity: "warning",
|
|
451
|
+
label: "Primary keyword has no search volume",
|
|
452
|
+
description: `"${primaryKeyword}" shows no measurable monthly searches, so even ranking #1 brings little traffic.`,
|
|
453
|
+
howToFix: "Pick a primary people actually search for - check your supporting keywords for higher-volume options, or set a new primary on the Keywords tab.",
|
|
454
|
+
jumpTo: { tab: "keywords" },
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ---------- SECONDARY KEYWORD COVERAGE ----------
|
|
460
|
+
// When the editor has chosen an optional secondary keyword, flag the spots it's
|
|
461
|
+
// missing from so the "primary in, secondary out" gaps are visible at a glance.
|
|
462
|
+
if (secondaryKeyword) {
|
|
463
|
+
if (text && !tokensContain(text, secondaryKeyword)) {
|
|
464
|
+
items.push({
|
|
465
|
+
id: "secondary-not-in-body",
|
|
466
|
+
category: "keywords",
|
|
467
|
+
severity: "opportunity",
|
|
468
|
+
label: "Secondary keyword not in body",
|
|
469
|
+
description: `Your secondary keyword "${secondaryKeyword}" doesn't appear in the article body.`,
|
|
470
|
+
howToFix: "Work the secondary keyword into a body paragraph or two where it reads naturally.",
|
|
471
|
+
jumpTo: { tab: "keywords" },
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
const titleVal = documentFields?.title;
|
|
475
|
+
if (titleVal && !tokensContain(titleVal, secondaryKeyword)) {
|
|
476
|
+
items.push({
|
|
477
|
+
id: "secondary-not-in-title",
|
|
478
|
+
category: "meta",
|
|
479
|
+
severity: "opportunity",
|
|
480
|
+
label: "Secondary keyword not in title",
|
|
481
|
+
description: `The title leads with the primary keyword but doesn't include "${secondaryKeyword}".`,
|
|
482
|
+
howToFix: "If it fits naturally, include the secondary keyword in the title too - but never at the cost of the primary leading.",
|
|
483
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
const metaVal = documentFields?.metaDescription;
|
|
487
|
+
if (metaVal && !tokensContain(metaVal, secondaryKeyword)) {
|
|
488
|
+
items.push({
|
|
489
|
+
id: "secondary-not-in-meta",
|
|
490
|
+
category: "meta",
|
|
491
|
+
severity: "opportunity",
|
|
492
|
+
label: "Secondary keyword not in meta description",
|
|
493
|
+
description: `The meta description doesn't include "${secondaryKeyword}".`,
|
|
494
|
+
howToFix: "Add the secondary keyword to the meta description if it reads naturally.",
|
|
495
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
const slugVal = documentFields?.slug;
|
|
499
|
+
if (slugVal && !tokensContain(slugVal.replace(/-/g, " "), secondaryKeyword)) {
|
|
500
|
+
items.push({
|
|
501
|
+
id: "secondary-not-in-url",
|
|
502
|
+
category: "meta",
|
|
503
|
+
severity: "opportunity",
|
|
504
|
+
label: "Secondary keyword not in URL",
|
|
505
|
+
description: `The URL doesn't include "${secondaryKeyword}".`,
|
|
506
|
+
howToFix: "Optionally include the secondary keyword in the URL after the primary - only if the slug stays short and clean.",
|
|
507
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
508
|
+
});
|
|
509
|
+
}
|
|
390
510
|
}
|
|
391
511
|
|
|
392
512
|
// ---------- CONTENT SCORE ----------
|
|
@@ -396,8 +516,13 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
396
516
|
// short title, etc.) already produce their own actionable items above.
|
|
397
517
|
|
|
398
518
|
// ---------- AEO: question headings ----------
|
|
399
|
-
|
|
400
|
-
|
|
519
|
+
// Count the question headings the editor has ACTUALLY written (ending in "?"),
|
|
520
|
+
// matching the AEO score signal - NOT Claude's rewrite suggestions, which would
|
|
521
|
+
// contradict the score (an article with a real "?" heading must not also be told
|
|
522
|
+
// it has "no question-style headings"). Gate on deepAnalysis so it only surfaces
|
|
523
|
+
// once that tab has run.
|
|
524
|
+
const actualQuestionHeadings = (documentFields?.headings || []).filter((h) => h.trim().endsWith("?"));
|
|
525
|
+
if (deepAnalysis && actualQuestionHeadings.length === 0 && wordCount > 300) {
|
|
401
526
|
items.push({
|
|
402
527
|
id: "aeo-no-question-headings",
|
|
403
528
|
category: "aeo",
|
|
@@ -437,6 +562,10 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
437
562
|
|
|
438
563
|
// ---------- TECHNICAL: broken links (Other Recs tab) ----------
|
|
439
564
|
// Only surfaces after the editor has actually run the check on the Other Recs tab.
|
|
565
|
+
// Truly broken (404/5xx/timeout/DNS-fail) is an error. 401/403/429 are
|
|
566
|
+
// "unverified" - the link may work for human readers but our server fetch was
|
|
567
|
+
// blocked by an anti-bot WAF, so we surface those as a softer warning rather
|
|
568
|
+
// than panicking the editor about links that are actually fine.
|
|
440
569
|
if (linkCheckResults && linkCheckResults.length > 0) {
|
|
441
570
|
const broken = linkCheckResults.filter((r) => r.category === "broken" || r.category === "error");
|
|
442
571
|
if (broken.length > 0) {
|
|
@@ -450,6 +579,18 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
450
579
|
jumpTo: { tab: "technical", anchorId: "anchor-link-check" },
|
|
451
580
|
});
|
|
452
581
|
}
|
|
582
|
+
const unverified = linkCheckResults.filter((r) => r.category === "unverified");
|
|
583
|
+
if (unverified.length > 0) {
|
|
584
|
+
items.push({
|
|
585
|
+
id: "unverified-links",
|
|
586
|
+
category: "technical",
|
|
587
|
+
severity: "warning",
|
|
588
|
+
label: `${unverified.length} link${unverified.length === 1 ? "" : "s"} couldn't be auto-verified`,
|
|
589
|
+
description: `${unverified.length} link${unverified.length === 1 ? " was" : "s were"} blocked by an anti-bot wall (401/403/429) - the URLs may work fine for readers, our server just couldn't confirm.`,
|
|
590
|
+
howToFix: "Open each one manually in a new tab to confirm it loads, then ignore the warning if it does.",
|
|
591
|
+
jumpTo: { tab: "technical", anchorId: "anchor-link-check" },
|
|
592
|
+
});
|
|
593
|
+
}
|
|
453
594
|
}
|
|
454
595
|
|
|
455
596
|
// ---------- DEEP ANALYSIS: readability / gaps / structure ----------
|
package/src/lib/types.ts
CHANGED
|
@@ -179,7 +179,10 @@ export interface LinkCheckResult {
|
|
|
179
179
|
// True when the request landed on a different URL than the original.
|
|
180
180
|
redirected: boolean;
|
|
181
181
|
// One-word category for the badge in the UI.
|
|
182
|
-
|
|
182
|
+
// "unverified" = the URL responded 401/403/429 - usually anti-bot blocking
|
|
183
|
+
// server-side fetches (e.g. Cloudflare blocking cloud-provider egress IPs).
|
|
184
|
+
// The link may work fine for human readers; editors should click to verify.
|
|
185
|
+
category: "ok" | "redirect" | "broken" | "unverified" | "error";
|
|
183
186
|
// Human-friendly message used when category is "error" (timeout, DNS fail, etc.).
|
|
184
187
|
error?: string;
|
|
185
188
|
}
|