sanity-plugin-seo-copilot 0.2.15 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -50
- package/dist/index.js +841 -782
- package/dist/index.mjs +763 -704
- package/package.json +62 -64
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -3
- package/src/components/ChatPanel.tsx +0 -311
- package/src/components/ConfigContext.tsx +0 -22
- package/src/components/FeedbackButton.tsx +0 -218
- package/src/components/KeywordBadge.tsx +0 -50
- package/src/components/KeywordPanel.tsx +0 -1234
- package/src/components/OnboardingPopup.tsx +0 -108
- package/src/components/PlacementIndicators.tsx +0 -80
- package/src/components/ReportProblemButton.tsx +0 -212
- package/src/components/SEOCopilotPanel.tsx +0 -1287
- package/src/components/ScoreDonut.tsx +0 -158
- package/src/components/SeedKeywordInput.tsx +0 -128
- package/src/components/ShimmerLoader.tsx +0 -123
- package/src/components/TabBar.tsx +0 -373
- package/src/components/styles.ts +0 -158
- package/src/components/tabs/AEOTab.tsx +0 -585
- package/src/components/tabs/LinkingTab.tsx +0 -446
- package/src/components/tabs/MetaTab.tsx +0 -431
- package/src/components/tabs/SummaryTab.tsx +0 -405
- package/src/components/tabs/TechnicalTab.tsx +0 -933
- package/src/hooks/useDocumentContent.ts +0 -48
- package/src/hooks/useKeywordAnalysis.ts +0 -292
- package/src/hooks/useSEOChat.ts +0 -254
- package/src/index.ts +0 -18
- package/src/inspector.ts +0 -58
- package/src/lib/api.ts +0 -262
- package/src/lib/apiKey.ts +0 -30
- package/src/lib/documentExtract.ts +0 -422
- package/src/lib/geoAnalysis.ts +0 -122
- package/src/lib/persistence.ts +0 -69
- package/src/lib/scoring.ts +0 -197
- package/src/lib/summary.ts +0 -645
- package/src/lib/types.ts +0 -212
- package/src/lib/utils.ts +0 -35
- package/v2-incompatible.js +0 -10
package/src/lib/summary.ts
DELETED
|
@@ -1,645 +0,0 @@
|
|
|
1
|
-
// buildSummaryItems - pure aggregator. Takes everything the panel knows about the article
|
|
2
|
-
// and produces a flat, severity-sorted SummaryItem[] for the Summary tab.
|
|
3
|
-
// No fetches happen here - this only runs against state already in memory.
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
SEOAnalysis,
|
|
7
|
-
DeepAnalysis,
|
|
8
|
-
DocumentFields,
|
|
9
|
-
LinkingSuggestion,
|
|
10
|
-
LinkCheckResult,
|
|
11
|
-
SummaryItem,
|
|
12
|
-
} from "./types";
|
|
13
|
-
|
|
14
|
-
interface BuildSummaryInput {
|
|
15
|
-
analysis: SEOAnalysis | null;
|
|
16
|
-
deepAnalysis: DeepAnalysis | null;
|
|
17
|
-
documentFields?: DocumentFields;
|
|
18
|
-
contentScore: number | null;
|
|
19
|
-
linkingSuggestions: LinkingSuggestion[];
|
|
20
|
-
// Set after the editor has run the broken-link checker on the Other Recs tab.
|
|
21
|
-
// When non-empty, broken/errored entries surface here as their own issue.
|
|
22
|
-
linkCheckResults?: LinkCheckResult[];
|
|
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;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
import { containsKeywordTokens, keywordLeadsSlug } from "./utils";
|
|
32
|
-
|
|
33
|
-
// Conference previews, news briefs, recaps, and listicles are legitimately short.
|
|
34
|
-
// Detect them so we don't nag "push past 1,500 words" on content that should be
|
|
35
|
-
// short. Uses the contentCategory field when present, else title-pattern signals.
|
|
36
|
-
export function isShortFormContent(documentFields?: DocumentFields, title?: string): boolean {
|
|
37
|
-
const cat = (documentFields?.contentCategory || "").toLowerCase().trim();
|
|
38
|
-
// Media formats (video / podcast / episode / webinar): the body text is a summary
|
|
39
|
-
// of the media, not the article. Match the category AS A WHOLE so a written piece
|
|
40
|
-
// in a compound category like "clinical video interviews" is NOT exempted.
|
|
41
|
-
if (/^(videos?|podcasts?|episodes?|webinars?|video series|peer exchange)$/.test(cat)) return true;
|
|
42
|
-
// Written short formats - token match (not substring) so "newsletter" doesn't match
|
|
43
|
-
// "news" and "updated-guidelines" doesn't match "update".
|
|
44
|
-
const shortFormCats = new Set(["news", "brief", "preview", "recap", "update", "announcement", "roundup", "digest", "interview"]);
|
|
45
|
-
const catTokens = cat.split(/[^a-z]+/).filter(Boolean);
|
|
46
|
-
if (catTokens.some((tok) => shortFormCats.has(tok))) return true;
|
|
47
|
-
const t = (title || "").toLowerCase();
|
|
48
|
-
if (/\b(preview|recap|roundup|digest)\b/.test(t)) return true;
|
|
49
|
-
if (/:\s*\d+\s+(trials|things|takeaways|highlights|tips|questions|charts)/.test(t)) return true;
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
54
|
-
const items: SummaryItem[] = [];
|
|
55
|
-
// contentScore is in BuildSummaryInput for forward-compat but is now shown
|
|
56
|
-
// directly on the Summary tab as a card with breakdown - no echo item needed here.
|
|
57
|
-
const { analysis, deepAnalysis, documentFields, linkingSuggestions, linkCheckResults, text } = input;
|
|
58
|
-
const primaryKeyword = input.primaryKeyword || analysis?.primaryKeyword?.term;
|
|
59
|
-
const secondaryKeyword = input.secondaryKeyword || "";
|
|
60
|
-
// Body-only text: useDocumentContent prepends the document title so the AI
|
|
61
|
-
// analysis includes it, but word-count and keyword-in-body checks must not
|
|
62
|
-
// count the title as body content. Strip the title prefix when present.
|
|
63
|
-
const bodyText = (() => {
|
|
64
|
-
if (!documentFields?.title) return text;
|
|
65
|
-
if (!text.startsWith(documentFields.title)) return text;
|
|
66
|
-
const rest = text.slice(documentFields.title.length);
|
|
67
|
-
if (rest === "" || /^\s/.test(rest)) return rest.trimStart();
|
|
68
|
-
return text;
|
|
69
|
-
})();
|
|
70
|
-
|
|
71
|
-
// ---------- META: title ----------
|
|
72
|
-
// Length warnings removed - the article title IS the page title and editors
|
|
73
|
-
// can't easily shorten it without rewriting the article. The real lever they
|
|
74
|
-
// have is keyword position: putting the primary keyword in the first 30 chars
|
|
75
|
-
// (or first 5 words) so it survives Google's ~60-char SERP truncation.
|
|
76
|
-
const title = documentFields?.title;
|
|
77
|
-
if (!title) {
|
|
78
|
-
items.push({
|
|
79
|
-
id: "meta-title-missing",
|
|
80
|
-
category: "meta",
|
|
81
|
-
severity: "error",
|
|
82
|
-
label: "Title tag missing",
|
|
83
|
-
description: "No title set on this document.",
|
|
84
|
-
howToFix: "Add a title that leads with the primary keyword. The title is what Google shows in search results.",
|
|
85
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
86
|
-
});
|
|
87
|
-
} else if (primaryKeyword) {
|
|
88
|
-
if (!containsKeywordTokens(title, primaryKeyword)) {
|
|
89
|
-
items.push({
|
|
90
|
-
id: "meta-title-no-keyword",
|
|
91
|
-
category: "meta",
|
|
92
|
-
severity: "warning",
|
|
93
|
-
label: "Primary keyword not in title",
|
|
94
|
-
description: `Title doesn't contain "${primaryKeyword}".`,
|
|
95
|
-
howToFix: "Rewrite the title to lead with the primary keyword. Google weights early-position keywords heavily.",
|
|
96
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
// Locate the first keyword token to assess position.
|
|
100
|
-
const lowerTitle = title.toLowerCase();
|
|
101
|
-
const tokens = primaryKeyword.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
|
|
102
|
-
let firstHit = -1;
|
|
103
|
-
for (const t of tokens) {
|
|
104
|
-
const i = lowerTitle.indexOf(t);
|
|
105
|
-
if (i >= 0 && (firstHit === -1 || i < firstHit)) firstHit = i;
|
|
106
|
-
}
|
|
107
|
-
const wordsBefore = firstHit >= 0 ? title.slice(0, firstHit).trim().split(/\s+/).filter(Boolean).length : 0;
|
|
108
|
-
if (firstHit > 30 && wordsBefore > 5) {
|
|
109
|
-
items.push({
|
|
110
|
-
id: "meta-title-keyword-late",
|
|
111
|
-
category: "meta",
|
|
112
|
-
severity: "warning",
|
|
113
|
-
label: "Primary keyword late in title",
|
|
114
|
-
description: `"${primaryKeyword}" starts at character ${firstHit + 1} of the title.`,
|
|
115
|
-
howToFix: "Move the primary keyword toward the start of the title so it stays visible if Google truncates at ~60 characters.",
|
|
116
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// ---------- META: description ----------
|
|
123
|
-
const meta = documentFields?.metaDescription;
|
|
124
|
-
if (!meta) {
|
|
125
|
-
items.push({
|
|
126
|
-
id: "meta-desc-missing",
|
|
127
|
-
category: "meta",
|
|
128
|
-
severity: "error",
|
|
129
|
-
label: "Meta description missing",
|
|
130
|
-
description: "No meta description set.",
|
|
131
|
-
howToFix: "Write a 120-160 character description that summarizes the article and includes your primary keyword.",
|
|
132
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
const len = meta.length;
|
|
136
|
-
if (len < 120) {
|
|
137
|
-
items.push({
|
|
138
|
-
id: "meta-desc-short",
|
|
139
|
-
category: "meta",
|
|
140
|
-
severity: "warning",
|
|
141
|
-
label: "Meta description is short",
|
|
142
|
-
description: `Meta description is ${len} characters - below the 120-160 ideal.`,
|
|
143
|
-
howToFix: "Expand the description to 120-160 characters so the full description shows in search.",
|
|
144
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
145
|
-
});
|
|
146
|
-
} else if (len > 160) {
|
|
147
|
-
items.push({
|
|
148
|
-
id: "meta-desc-long",
|
|
149
|
-
category: "meta",
|
|
150
|
-
severity: "warning",
|
|
151
|
-
label: "Meta description is long",
|
|
152
|
-
description: `Meta description is ${len} characters - Google may truncate beyond 160.`,
|
|
153
|
-
howToFix: "Trim the description to under 160 characters so the full text shows in search.",
|
|
154
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
if (primaryKeyword && !containsKeywordTokens(meta, primaryKeyword)) {
|
|
158
|
-
items.push({
|
|
159
|
-
id: "meta-desc-no-keyword",
|
|
160
|
-
category: "meta",
|
|
161
|
-
severity: "opportunity",
|
|
162
|
-
label: "Primary keyword not in meta description",
|
|
163
|
-
description: `Meta description doesn't include "${primaryKeyword}".`,
|
|
164
|
-
howToFix: "Naturally include the primary keyword in the description - it influences click-through rate even when not a direct ranking factor.",
|
|
165
|
-
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ---------- URL slug (lives on the Other Recs tab) ----------
|
|
171
|
-
// No character-count nag and no "too long" - just scan for the primary keyword,
|
|
172
|
-
// ideally leading the URL. Keep the guidance vague (short + descriptive).
|
|
173
|
-
const slug = documentFields?.slug;
|
|
174
|
-
if (!slug) {
|
|
175
|
-
items.push({
|
|
176
|
-
id: "meta-slug-missing",
|
|
177
|
-
category: "meta",
|
|
178
|
-
severity: "warning",
|
|
179
|
-
label: "URL slug missing",
|
|
180
|
-
description: "No URL slug set.",
|
|
181
|
-
howToFix: "Add a short, descriptive slug that leads with your primary keyword.",
|
|
182
|
-
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
const slugAsWords = slug.replace(/-/g, " ");
|
|
186
|
-
if (primaryKeyword && !containsKeywordTokens(slugAsWords, primaryKeyword)) {
|
|
187
|
-
items.push({
|
|
188
|
-
id: "meta-slug-no-keyword",
|
|
189
|
-
category: "meta",
|
|
190
|
-
severity: "opportunity",
|
|
191
|
-
label: "Primary keyword not in URL",
|
|
192
|
-
description: `The URL doesn't include "${primaryKeyword}".`,
|
|
193
|
-
howToFix: "Work the primary keyword into the URL, ideally at the start. Keep the URL short and descriptive.",
|
|
194
|
-
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
195
|
-
});
|
|
196
|
-
} else if (primaryKeyword && !keywordLeadsSlug(slug, primaryKeyword)) {
|
|
197
|
-
items.push({
|
|
198
|
-
id: "meta-slug-keyword-late",
|
|
199
|
-
category: "meta",
|
|
200
|
-
severity: "opportunity",
|
|
201
|
-
label: "Primary keyword late in URL",
|
|
202
|
-
description: `"${primaryKeyword}" is in the URL but not near the start.`,
|
|
203
|
-
howToFix: "Lead the URL with the primary keyword so it stays visible if the address gets shortened.",
|
|
204
|
-
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ---------- CONTENT: word count ----------
|
|
210
|
-
// 450 is the body-text floor (per editor guidance). 1,500+ is the competitive
|
|
211
|
-
// target for HCP clinical articles.
|
|
212
|
-
const wordCount = bodyText ? bodyText.trim().split(/\s+/).filter(Boolean).length : 0;
|
|
213
|
-
// Videos, podcasts, news, briefs, etc. are legitimately short (the body is a
|
|
214
|
-
// summary, not the deliverable), so they're exempt from the word-count floor.
|
|
215
|
-
const isShortForm = isShortFormContent(documentFields, title);
|
|
216
|
-
if (wordCount === 0) {
|
|
217
|
-
// No item - empty doc state is handled by the empty-state UI elsewhere
|
|
218
|
-
} else if (wordCount < 450 && !isShortForm) {
|
|
219
|
-
items.push({
|
|
220
|
-
id: "content-too-short",
|
|
221
|
-
category: "content",
|
|
222
|
-
severity: "error",
|
|
223
|
-
label: "Content is too short",
|
|
224
|
-
description: `${wordCount} words. Body copy should be at least 450 words.`,
|
|
225
|
-
howToFix: "Add more body text. A link or image on its own doesn't count - the article needs real written substance.",
|
|
226
|
-
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
227
|
-
});
|
|
228
|
-
} else if (wordCount < 1500 && !isShortForm) {
|
|
229
|
-
items.push({
|
|
230
|
-
id: "content-short-for-clinical",
|
|
231
|
-
category: "content",
|
|
232
|
-
severity: "opportunity",
|
|
233
|
-
label: "Article could be longer",
|
|
234
|
-
description: `${wordCount} words. For evergreen clinical topics 1,500+ tends to rank better - news, previews, and briefs are fine shorter.`,
|
|
235
|
-
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.",
|
|
236
|
-
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// ---------- HEADINGS ----------
|
|
241
|
-
const headings = documentFields?.headings || [];
|
|
242
|
-
const headingsDetailed = documentFields?.headingsDetailed;
|
|
243
|
-
// H2 count - prefer the detailed list (which records actual levels). When only
|
|
244
|
-
// a flat list is available the typical case is "all H2s", so we use the total
|
|
245
|
-
// as a fallback approximation.
|
|
246
|
-
// Count H2 AND H3 as section headings - an H3-only article is still sectioned.
|
|
247
|
-
const h2Count = headingsDetailed
|
|
248
|
-
? headingsDetailed.filter((h) => h.level === 2 || h.level === 3).length
|
|
249
|
-
: headings.length;
|
|
250
|
-
if (h2Count === 0 && wordCount > 200 && wordCount < 1000) {
|
|
251
|
-
items.push({
|
|
252
|
-
id: "headings-missing",
|
|
253
|
-
category: "headings",
|
|
254
|
-
severity: "warning",
|
|
255
|
-
label: "No H2/H3 headings detected",
|
|
256
|
-
description: "Article has no subheadings to break up content.",
|
|
257
|
-
howToFix: "Add H2 headings every 200-300 words so Google can pull them into featured snippets and readers can scan.",
|
|
258
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
// Long-content density checks (matches TechnicalTab thresholds).
|
|
262
|
-
if (wordCount >= 1000 && h2Count === 0) {
|
|
263
|
-
items.push({
|
|
264
|
-
id: "headings-density-zero",
|
|
265
|
-
category: "headings",
|
|
266
|
-
severity: "error",
|
|
267
|
-
label: "Long article without section headings",
|
|
268
|
-
description: `${wordCount} words and no H2 or H3 section headings.`,
|
|
269
|
-
howToFix: "Add 2-3 H2 headings to break the article into scannable sections.",
|
|
270
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
271
|
-
});
|
|
272
|
-
} else if (wordCount >= 2500 && h2Count < 5) {
|
|
273
|
-
items.push({
|
|
274
|
-
id: "headings-density-long",
|
|
275
|
-
category: "headings",
|
|
276
|
-
severity: "warning",
|
|
277
|
-
label: "Long article could use more section headings",
|
|
278
|
-
description: `${h2Count} section heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
|
|
279
|
-
howToFix: "Long articles read best with 1 H2 per 300-400 words. Add more named section breaks.",
|
|
280
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
281
|
-
});
|
|
282
|
-
} else if (wordCount >= 1500 && h2Count < 3) {
|
|
283
|
-
items.push({
|
|
284
|
-
id: "headings-density",
|
|
285
|
-
category: "headings",
|
|
286
|
-
severity: "warning",
|
|
287
|
-
label: "Article could use more section headings",
|
|
288
|
-
description: `${h2Count} section heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
|
|
289
|
-
howToFix: "Articles above 1,500 words usually need at least 3 H2 sections. Break the content into more named blocks.",
|
|
290
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
// (H1-in-body is intentionally no longer flagged: the article title IS the H1, and the
|
|
294
|
-
// Heading Outline on the Other Recs tab now shows it explicitly instead of warning.)
|
|
295
|
-
if (headingsDetailed) {
|
|
296
|
-
// Skipped-level check
|
|
297
|
-
let prevLevel = 0;
|
|
298
|
-
let skips = 0;
|
|
299
|
-
for (const h of headingsDetailed) {
|
|
300
|
-
if (prevLevel > 0 && h.level > prevLevel + 1) skips++;
|
|
301
|
-
prevLevel = h.level;
|
|
302
|
-
}
|
|
303
|
-
if (skips > 0) {
|
|
304
|
-
items.push({
|
|
305
|
-
id: "headings-skipped-levels",
|
|
306
|
-
category: "headings",
|
|
307
|
-
severity: "warning",
|
|
308
|
-
label: "Heading levels skip",
|
|
309
|
-
description: `${skips} place${skips === 1 ? "" : "s"} where the heading level jumps (e.g. H2 to H4).`,
|
|
310
|
-
howToFix: "Use sequential heading levels (H2 → H3 → H4) so screen readers and search engines parse the outline cleanly.",
|
|
311
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
// Empty heading blocks
|
|
315
|
-
const empties = headingsDetailed.filter((h) => !h.text.trim()).length;
|
|
316
|
-
if (empties > 0) {
|
|
317
|
-
items.push({
|
|
318
|
-
id: "headings-empty",
|
|
319
|
-
category: "headings",
|
|
320
|
-
severity: "error",
|
|
321
|
-
label: "Empty heading blocks",
|
|
322
|
-
description: `${empties} heading${empties === 1 ? "" : "s"} with no text.`,
|
|
323
|
-
howToFix: "Either remove the empty heading blocks or fill them with text.",
|
|
324
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
// Keyword-in-headings opportunity - mirrors the "Keywords in Headings" audit on the
|
|
328
|
-
// Other Recs tab so the nudge also surfaces in the Summary hub. Only when subheadings
|
|
329
|
-
// exist and neither target keyword appears in any of them.
|
|
330
|
-
const subheads = headingsDetailed.filter((h) => h.level >= 2);
|
|
331
|
-
if (subheads.length > 0 && (primaryKeyword || secondaryKeyword)) {
|
|
332
|
-
const subText = subheads.map((h) => h.text).join(" ");
|
|
333
|
-
const hasP = primaryKeyword ? containsKeywordTokens(subText, primaryKeyword) : false;
|
|
334
|
-
const hasS = secondaryKeyword ? containsKeywordTokens(subText, secondaryKeyword) : false;
|
|
335
|
-
if (!hasP && !hasS) {
|
|
336
|
-
items.push({
|
|
337
|
-
id: "headings-keyword-missing",
|
|
338
|
-
category: "headings",
|
|
339
|
-
severity: "opportunity",
|
|
340
|
-
label: "Keyword missing from subheadings",
|
|
341
|
-
description: "No H2/H3 subheading uses your primary or secondary keyword.",
|
|
342
|
-
howToFix: "Work your primary or secondary keyword into at least one subheading - keywords in headers reinforce relevance for readers and search.",
|
|
343
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-keyword" },
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// ---------- IMAGES ----------
|
|
350
|
-
const images = documentFields?.imageNames || [];
|
|
351
|
-
if (images.length === 0 && wordCount > 300) {
|
|
352
|
-
items.push({
|
|
353
|
-
id: "images-none",
|
|
354
|
-
category: "images",
|
|
355
|
-
severity: "opportunity",
|
|
356
|
-
label: "No images",
|
|
357
|
-
description: "Article doesn't have any images.",
|
|
358
|
-
howToFix: "Add at least one hero image with descriptive alt text. Articles with images perform better on both reader engagement and search.",
|
|
359
|
-
jumpTo: { tab: "technical", anchorId: "anchor-images" },
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
// Filename + alt quality - mirrors the classification heuristic in TechnicalTab.
|
|
363
|
-
const IMG_EXT_RE = /\.(jpe?g|png|gif|webp|svg|tiff?|bmp)$/i;
|
|
364
|
-
const GENERIC_FN_RE = /^(IMG_|DSC|DCIM|screenshot|photo\d*|image\d*|untitled|file_?\d+|unsplash|stock)/i;
|
|
365
|
-
const imageFilenames = images.filter((n) => IMG_EXT_RE.test(n));
|
|
366
|
-
const imageAlts = images.filter((n) => !IMG_EXT_RE.test(n));
|
|
367
|
-
const badFilenames = imageFilenames.filter((f) => {
|
|
368
|
-
const base = f.replace(IMG_EXT_RE, "");
|
|
369
|
-
if (GENERIC_FN_RE.test(base)) return true;
|
|
370
|
-
if (/_/.test(base) || /\s/.test(base)) return true;
|
|
371
|
-
const words = base.split("-").filter(Boolean);
|
|
372
|
-
return words.length < 2 || words.length > 5;
|
|
373
|
-
});
|
|
374
|
-
if (badFilenames.length > 0) {
|
|
375
|
-
items.push({
|
|
376
|
-
id: "images-filenames-bad",
|
|
377
|
-
category: "images",
|
|
378
|
-
severity: "warning",
|
|
379
|
-
label: `${badFilenames.length} image filename${badFilenames.length === 1 ? "" : "s"} needs work`,
|
|
380
|
-
description: "Filenames should use 2-3 hyphenated descriptive words.",
|
|
381
|
-
howToFix: "Rename images with 2-3 descriptive hyphenated words, ideally including the primary keyword. Avoid IMG_xxxx, screenshot, photo1.",
|
|
382
|
-
jumpTo: { tab: "technical", anchorId: "anchor-image-filenames" },
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
const badAlts = imageAlts.filter((alt) => {
|
|
386
|
-
const trimmed = alt.trim();
|
|
387
|
-
if (!trimmed) return false;
|
|
388
|
-
const len = trimmed.length;
|
|
389
|
-
const wc = trimmed.split(/\s+/).filter(Boolean).length;
|
|
390
|
-
return len >= 125 || wc < 2;
|
|
391
|
-
});
|
|
392
|
-
if (badAlts.length > 0) {
|
|
393
|
-
items.push({
|
|
394
|
-
id: "images-alt-bad",
|
|
395
|
-
category: "images",
|
|
396
|
-
severity: "warning",
|
|
397
|
-
label: `${badAlts.length} image alt text${badAlts.length === 1 ? "" : "s"} needs work`,
|
|
398
|
-
description: "Alt text should be 2-5 descriptive keywords, under 125 chars.",
|
|
399
|
-
howToFix: "Write alt text as 2-5 descriptive keywords that describe the image, ideally including the primary keyword. Keep it under 125 characters.",
|
|
400
|
-
jumpTo: { tab: "technical", anchorId: "anchor-image-alt" },
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
// Image titles (the hover tooltip) - the director treats this as an SEO signal.
|
|
404
|
-
const imageTitleCount = (documentFields?.imageTitles || []).length;
|
|
405
|
-
const totalImageCount = documentFields?.imageCount ?? 0;
|
|
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;
|
|
411
|
-
if (missingTitles > 0) {
|
|
412
|
-
items.push({
|
|
413
|
-
id: "images-titles-missing",
|
|
414
|
-
category: "images",
|
|
415
|
-
severity: "warning",
|
|
416
|
-
label: `${missingTitles} image${missingTitles === 1 ? "" : "s"} missing a title`,
|
|
417
|
-
description: "The title attribute shows on hover and sends an SEO signal.",
|
|
418
|
-
howToFix: "Add a descriptive title attribute (2-5 keywords) to each image that's missing one.",
|
|
419
|
-
jumpTo: { tab: "technical", anchorId: "anchor-image-titles" },
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// ---------- KEYWORDS: primary candidate confidence ----------
|
|
424
|
-
if (!primaryKeyword) {
|
|
425
|
-
// Keywords haven't loaded - skip
|
|
426
|
-
} else {
|
|
427
|
-
// If primary is missing from body, flag it
|
|
428
|
-
if (bodyText && !containsKeywordTokens(bodyText, primaryKeyword)) {
|
|
429
|
-
items.push({
|
|
430
|
-
id: "keywords-primary-not-in-body",
|
|
431
|
-
category: "keywords",
|
|
432
|
-
severity: "warning",
|
|
433
|
-
label: "Primary keyword not in body",
|
|
434
|
-
description: `"${primaryKeyword}" doesn't appear in the article body.`,
|
|
435
|
-
howToFix: "Use the primary keyword naturally in the introduction and at least one body paragraph.",
|
|
436
|
-
jumpTo: { tab: "keywords" },
|
|
437
|
-
});
|
|
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 (bodyText && !containsKeywordTokens(bodyText, 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 && !containsKeywordTokens(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 doesn't include your secondary keyword "${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 && !containsKeywordTokens(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 && !containsKeywordTokens(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
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// ---------- CONTENT SCORE ----------
|
|
513
|
-
// The score itself is shown as a card at the top of the Summary tab with a
|
|
514
|
-
// visible per-component breakdown, so we DON'T echo it here as a separate
|
|
515
|
-
// item - that would be redundant. The individual signals (missing keywords,
|
|
516
|
-
// short title, etc.) already produce their own actionable items above.
|
|
517
|
-
|
|
518
|
-
// ---------- AEO: question headings ----------
|
|
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) {
|
|
526
|
-
items.push({
|
|
527
|
-
id: "aeo-no-question-headings",
|
|
528
|
-
category: "aeo",
|
|
529
|
-
severity: "opportunity",
|
|
530
|
-
label: "No question-style headings",
|
|
531
|
-
description: "None of your headings are phrased as questions.",
|
|
532
|
-
howToFix: "Rewrite a heading or two as a question (\"What is...?\", \"How does...?\"). Google often pulls question headings into featured snippets.",
|
|
533
|
-
jumpTo: { tab: "aeo" },
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// ---------- LINKING: low coverage ----------
|
|
538
|
-
if (linkingSuggestions.length === 0 && analysis && wordCount > 500) {
|
|
539
|
-
items.push({
|
|
540
|
-
id: "linking-none",
|
|
541
|
-
category: "internal-linking",
|
|
542
|
-
severity: "opportunity",
|
|
543
|
-
label: "No internal links suggested yet",
|
|
544
|
-
description: "Linking suggestions haven't been generated for this article.",
|
|
545
|
-
howToFix: "Open the Linking tab and refresh to fetch related articles to link to.",
|
|
546
|
-
jumpTo: { tab: "linking", anchorId: "anchor-linking-suggestions" },
|
|
547
|
-
});
|
|
548
|
-
} else if (linkingSuggestions.length > 0) {
|
|
549
|
-
const strong = linkingSuggestions.filter((s) => s.compositeScore >= 60).length;
|
|
550
|
-
if (strong === 0) {
|
|
551
|
-
items.push({
|
|
552
|
-
id: "linking-weak",
|
|
553
|
-
category: "internal-linking",
|
|
554
|
-
severity: "opportunity",
|
|
555
|
-
label: "Linking matches are weak",
|
|
556
|
-
description: "None of the suggested articles reach 60% match for relevance.",
|
|
557
|
-
howToFix: "Refine your primary keyword on the Keywords tab for tighter matches - or skip linking for this article.",
|
|
558
|
-
jumpTo: { tab: "linking", anchorId: "anchor-linking-suggestions" },
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// ---------- TECHNICAL: broken links (Other Recs tab) ----------
|
|
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.
|
|
569
|
-
if (linkCheckResults && linkCheckResults.length > 0) {
|
|
570
|
-
const broken = linkCheckResults.filter((r) => r.category === "broken" || r.category === "error");
|
|
571
|
-
if (broken.length > 0) {
|
|
572
|
-
items.push({
|
|
573
|
-
id: "broken-links",
|
|
574
|
-
category: "technical",
|
|
575
|
-
severity: "error",
|
|
576
|
-
label: `${broken.length} broken link${broken.length === 1 ? "" : "s"}`,
|
|
577
|
-
description: `${broken.length} link${broken.length === 1 ? " was" : "s were"} unreachable or returned an error status.`,
|
|
578
|
-
howToFix: "Open the Other Recs tab's Link Health card to see the failing URLs and fix or remove them.",
|
|
579
|
-
jumpTo: { tab: "technical", anchorId: "anchor-link-check" },
|
|
580
|
-
});
|
|
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
|
-
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
// ---------- DEEP ANALYSIS: readability / gaps / structure ----------
|
|
597
|
-
if (deepAnalysis) {
|
|
598
|
-
const readability = deepAnalysis.readabilityNotes || [];
|
|
599
|
-
const gaps = deepAnalysis.competitiveGaps || [];
|
|
600
|
-
const structure = deepAnalysis.structureRecommendations || [];
|
|
601
|
-
readability.slice(0, 2).forEach((note, i) => {
|
|
602
|
-
items.push({
|
|
603
|
-
id: `deep-readability-${i}`,
|
|
604
|
-
category: "content",
|
|
605
|
-
severity: "opportunity",
|
|
606
|
-
label: "Readability note",
|
|
607
|
-
description: note,
|
|
608
|
-
howToFix: "Simplify the flagged passages - shorter sentences, fewer clauses, plainer phrasing where the clinical meaning allows.",
|
|
609
|
-
jumpTo: { tab: "summary" },
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
gaps.slice(0, 2).forEach((note, i) => {
|
|
613
|
-
items.push({
|
|
614
|
-
id: `deep-gap-${i}`,
|
|
615
|
-
category: "content",
|
|
616
|
-
severity: "opportunity",
|
|
617
|
-
label: "Competitive gap",
|
|
618
|
-
description: note,
|
|
619
|
-
howToFix: "Add a section covering this topic so the article matches what competing pages offer.",
|
|
620
|
-
jumpTo: { tab: "summary" },
|
|
621
|
-
});
|
|
622
|
-
});
|
|
623
|
-
structure.slice(0, 2).forEach((note, i) => {
|
|
624
|
-
items.push({
|
|
625
|
-
id: `deep-structure-${i}`,
|
|
626
|
-
category: "headings",
|
|
627
|
-
severity: "opportunity",
|
|
628
|
-
label: "Structure recommendation",
|
|
629
|
-
description: note,
|
|
630
|
-
howToFix: "Update the heading or section structure per the recommendation.",
|
|
631
|
-
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
632
|
-
});
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// Sort: severity (error > warning > opportunity), then category alphabetical
|
|
637
|
-
const severityRank: Record<string, number> = { error: 0, warning: 1, opportunity: 2 };
|
|
638
|
-
items.sort((a, b) => {
|
|
639
|
-
const s = severityRank[a.severity] - severityRank[b.severity];
|
|
640
|
-
if (s !== 0) return s;
|
|
641
|
-
return a.category.localeCompare(b.category);
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
return items;
|
|
645
|
-
}
|