sanity-plugin-seo-copilot 0.1.2 → 0.2.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/dist/index.js +4729 -895
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4722 -888
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/ChatPanel.tsx +87 -69
- package/src/components/FeedbackButton.tsx +2 -2
- package/src/components/KeywordBadge.tsx +50 -50
- package/src/components/KeywordPanel.tsx +97 -226
- package/src/components/PlacementIndicators.tsx +80 -76
- package/src/components/SEOCopilotPanel.tsx +712 -165
- package/src/components/ScoreDonut.tsx +158 -0
- package/src/components/SeedKeywordInput.tsx +128 -125
- package/src/components/ShimmerLoader.tsx +119 -0
- package/src/components/TabBar.tsx +370 -0
- package/src/components/styles.ts +66 -0
- package/src/components/tabs/AEOTab.tsx +573 -0
- package/src/components/tabs/LinkingTab.tsx +343 -0
- package/src/components/tabs/MetaTab.tsx +417 -0
- package/src/components/tabs/SummaryTab.tsx +384 -0
- package/src/components/tabs/TechnicalTab.tsx +776 -0
- package/src/hooks/useDocumentContent.ts +216 -99
- package/src/hooks/useKeywordAnalysis.ts +28 -8
- package/src/hooks/useSEOChat.ts +38 -11
- package/src/lib/api.ts +109 -13
- package/src/lib/geoAnalysis.ts +109 -0
- package/src/lib/persistence.ts +69 -0
- package/src/lib/scoring.ts +147 -0
- package/src/lib/summary.ts +504 -0
- package/src/lib/types.ts +197 -108
|
@@ -0,0 +1,504 @@
|
|
|
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
|
+
}
|
|
25
|
+
|
|
26
|
+
function tokensContain(haystack: string, needle?: string): boolean {
|
|
27
|
+
if (!needle) return true;
|
|
28
|
+
const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
|
|
29
|
+
if (tokens.length === 0) return true;
|
|
30
|
+
const lower = haystack.toLowerCase();
|
|
31
|
+
return tokens.every((t) => lower.includes(t));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
35
|
+
const items: SummaryItem[] = [];
|
|
36
|
+
// contentScore is in BuildSummaryInput for forward-compat but is now shown
|
|
37
|
+
// directly on the Summary tab as a card with breakdown - no echo item needed here.
|
|
38
|
+
const { analysis, deepAnalysis, documentFields, linkingSuggestions, linkCheckResults, text } = input;
|
|
39
|
+
const primaryKeyword = analysis?.primaryKeyword?.term;
|
|
40
|
+
|
|
41
|
+
// ---------- META: title ----------
|
|
42
|
+
// Length warnings removed - the article title IS the page title and editors
|
|
43
|
+
// can't easily shorten it without rewriting the article. The real lever they
|
|
44
|
+
// have is keyword position: putting the primary keyword in the first 30 chars
|
|
45
|
+
// (or first 5 words) so it survives Google's ~60-char SERP truncation.
|
|
46
|
+
const title = documentFields?.title;
|
|
47
|
+
if (!title) {
|
|
48
|
+
items.push({
|
|
49
|
+
id: "meta-title-missing",
|
|
50
|
+
category: "meta",
|
|
51
|
+
severity: "error",
|
|
52
|
+
label: "Title tag missing",
|
|
53
|
+
description: "No title set on this document.",
|
|
54
|
+
howToFix: "Add a title that leads with the primary keyword. The title is what Google shows in search results.",
|
|
55
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
56
|
+
});
|
|
57
|
+
} else if (primaryKeyword) {
|
|
58
|
+
if (!tokensContain(title, primaryKeyword)) {
|
|
59
|
+
items.push({
|
|
60
|
+
id: "meta-title-no-keyword",
|
|
61
|
+
category: "meta",
|
|
62
|
+
severity: "warning",
|
|
63
|
+
label: "Primary keyword not in title",
|
|
64
|
+
description: `Title doesn't contain "${primaryKeyword}".`,
|
|
65
|
+
howToFix: "Rewrite the title to lead with the primary keyword. Google weights early-position keywords heavily.",
|
|
66
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
// Locate the first keyword token to assess position.
|
|
70
|
+
const lowerTitle = title.toLowerCase();
|
|
71
|
+
const tokens = primaryKeyword.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
|
|
72
|
+
let firstHit = -1;
|
|
73
|
+
for (const t of tokens) {
|
|
74
|
+
const i = lowerTitle.indexOf(t);
|
|
75
|
+
if (i >= 0 && (firstHit === -1 || i < firstHit)) firstHit = i;
|
|
76
|
+
}
|
|
77
|
+
const wordsBefore = firstHit >= 0 ? title.slice(0, firstHit).trim().split(/\s+/).filter(Boolean).length : 0;
|
|
78
|
+
if (firstHit > 30 && wordsBefore > 5) {
|
|
79
|
+
items.push({
|
|
80
|
+
id: "meta-title-keyword-late",
|
|
81
|
+
category: "meta",
|
|
82
|
+
severity: "warning",
|
|
83
|
+
label: "Primary keyword late in title",
|
|
84
|
+
description: `"${primaryKeyword}" starts at character ${firstHit + 1} of the title.`,
|
|
85
|
+
howToFix: "Move the primary keyword toward the start of the title so it stays visible if Google truncates at ~60 characters.",
|
|
86
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ---------- META: description ----------
|
|
93
|
+
const meta = documentFields?.metaDescription;
|
|
94
|
+
if (!meta) {
|
|
95
|
+
items.push({
|
|
96
|
+
id: "meta-desc-missing",
|
|
97
|
+
category: "meta",
|
|
98
|
+
severity: "error",
|
|
99
|
+
label: "Meta description missing",
|
|
100
|
+
description: "No meta description set.",
|
|
101
|
+
howToFix: "Write a 120-160 character description that summarizes the article and includes your primary keyword.",
|
|
102
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
const len = meta.length;
|
|
106
|
+
if (len < 120) {
|
|
107
|
+
items.push({
|
|
108
|
+
id: "meta-desc-short",
|
|
109
|
+
category: "meta",
|
|
110
|
+
severity: "warning",
|
|
111
|
+
label: "Meta description is short",
|
|
112
|
+
description: `Meta description is ${len} characters - below the 120-160 ideal.`,
|
|
113
|
+
howToFix: "Expand the description to 120-160 characters so you don't leave SERP space empty.",
|
|
114
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
115
|
+
});
|
|
116
|
+
} else if (len > 160) {
|
|
117
|
+
items.push({
|
|
118
|
+
id: "meta-desc-long",
|
|
119
|
+
category: "meta",
|
|
120
|
+
severity: "warning",
|
|
121
|
+
label: "Meta description is long",
|
|
122
|
+
description: `Meta description is ${len} characters - Google may truncate beyond 160.`,
|
|
123
|
+
howToFix: "Trim the description to under 160 characters so the full text shows in search.",
|
|
124
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (primaryKeyword && !tokensContain(meta, primaryKeyword)) {
|
|
128
|
+
items.push({
|
|
129
|
+
id: "meta-desc-no-keyword",
|
|
130
|
+
category: "meta",
|
|
131
|
+
severity: "opportunity",
|
|
132
|
+
label: "Primary keyword not in meta description",
|
|
133
|
+
description: `Meta description doesn't include "${primaryKeyword}".`,
|
|
134
|
+
howToFix: "Naturally include the primary keyword in the description - it influences click-through rate even when not a direct ranking factor.",
|
|
135
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---------- META: slug ----------
|
|
141
|
+
const slug = documentFields?.slug;
|
|
142
|
+
if (!slug) {
|
|
143
|
+
items.push({
|
|
144
|
+
id: "meta-slug-missing",
|
|
145
|
+
category: "meta",
|
|
146
|
+
severity: "error",
|
|
147
|
+
label: "URL slug missing",
|
|
148
|
+
description: "No URL slug set.",
|
|
149
|
+
howToFix: "Add a clean, hyphenated slug 3-5 words long that contains the primary keyword.",
|
|
150
|
+
jumpTo: { tab: "meta", anchorId: "anchor-url-slug" },
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
if (slug.length > 60) {
|
|
154
|
+
items.push({
|
|
155
|
+
id: "meta-slug-long",
|
|
156
|
+
category: "meta",
|
|
157
|
+
severity: "warning",
|
|
158
|
+
label: "URL slug is long",
|
|
159
|
+
description: `Slug is ${slug.length} characters. 3-5 words is the 2026 sweet spot.`,
|
|
160
|
+
howToFix: "Shorten the slug to keep the URL clean and scannable.",
|
|
161
|
+
jumpTo: { tab: "meta", anchorId: "anchor-url-slug" },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (primaryKeyword && !tokensContain(slug.replace(/-/g, " "), primaryKeyword)) {
|
|
165
|
+
items.push({
|
|
166
|
+
id: "meta-slug-no-keyword",
|
|
167
|
+
category: "meta",
|
|
168
|
+
severity: "opportunity",
|
|
169
|
+
label: "Primary keyword not in URL",
|
|
170
|
+
description: `Slug doesn't contain "${primaryKeyword}".`,
|
|
171
|
+
howToFix: "Rework the slug to include the primary keyword (hyphenated). URLs with keywords still get a modest ranking lift.",
|
|
172
|
+
jumpTo: { tab: "meta", anchorId: "anchor-url-slug" },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---------- CONTENT: word count ----------
|
|
178
|
+
// 450 is the body-text floor (per editor guidance). 1,500+ is the competitive
|
|
179
|
+
// target for HCP clinical articles.
|
|
180
|
+
const wordCount = text ? text.trim().split(/\s+/).filter(Boolean).length : 0;
|
|
181
|
+
if (wordCount === 0) {
|
|
182
|
+
// No item - empty doc state is handled by the empty-state UI elsewhere
|
|
183
|
+
} else if (wordCount < 450) {
|
|
184
|
+
items.push({
|
|
185
|
+
id: "content-too-short",
|
|
186
|
+
category: "content",
|
|
187
|
+
severity: "error",
|
|
188
|
+
label: "Content is too short",
|
|
189
|
+
description: `${wordCount} words. Body copy should be at least 450 words.`,
|
|
190
|
+
howToFix: "Add more body text. A link or image on its own doesn't count - the article needs real written substance.",
|
|
191
|
+
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
192
|
+
});
|
|
193
|
+
} else if (wordCount < 1500) {
|
|
194
|
+
items.push({
|
|
195
|
+
id: "content-short-for-clinical",
|
|
196
|
+
category: "content",
|
|
197
|
+
severity: "warning",
|
|
198
|
+
label: "Article could be longer",
|
|
199
|
+
description: `${wordCount} words. 1,500+ is the standard for competitive clinical articles.`,
|
|
200
|
+
howToFix: "Expand sections with citations, comparative data, or guideline references.",
|
|
201
|
+
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ---------- HEADINGS ----------
|
|
206
|
+
const headings = documentFields?.headings || [];
|
|
207
|
+
const headingsDetailed = documentFields?.headingsDetailed;
|
|
208
|
+
// H2 count - prefer the detailed list (which records actual levels). When only
|
|
209
|
+
// a flat list is available the typical case is "all H2s", so we use the total
|
|
210
|
+
// as a fallback approximation.
|
|
211
|
+
const h2Count = headingsDetailed
|
|
212
|
+
? headingsDetailed.filter((h) => h.level === 2).length
|
|
213
|
+
: headings.length;
|
|
214
|
+
if (headings.length === 0 && wordCount > 200 && wordCount < 1000) {
|
|
215
|
+
items.push({
|
|
216
|
+
id: "headings-missing",
|
|
217
|
+
category: "headings",
|
|
218
|
+
severity: "warning",
|
|
219
|
+
label: "No H2/H3 headings detected",
|
|
220
|
+
description: "Article has no subheadings to break up content.",
|
|
221
|
+
howToFix: "Add H2 headings every 200-300 words so Google can pull them into featured snippets and readers can scan.",
|
|
222
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Long-content density checks (matches TechnicalTab thresholds).
|
|
226
|
+
if (wordCount >= 1000 && h2Count === 0) {
|
|
227
|
+
items.push({
|
|
228
|
+
id: "headings-density-zero",
|
|
229
|
+
category: "headings",
|
|
230
|
+
severity: "error",
|
|
231
|
+
label: "Long article without section headings",
|
|
232
|
+
description: `${wordCount} words and no H2 headings.`,
|
|
233
|
+
howToFix: "Add 2-3 H2 headings to break the article into scannable sections.",
|
|
234
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
235
|
+
});
|
|
236
|
+
} else if (wordCount >= 2500 && h2Count < 5) {
|
|
237
|
+
items.push({
|
|
238
|
+
id: "headings-density-long",
|
|
239
|
+
category: "headings",
|
|
240
|
+
severity: "warning",
|
|
241
|
+
label: "Long article could use more section headings",
|
|
242
|
+
description: `${h2Count} H2 heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
|
|
243
|
+
howToFix: "Long articles read best with 1 H2 per 300-400 words. Add more named section breaks.",
|
|
244
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
245
|
+
});
|
|
246
|
+
} else if (wordCount >= 1500 && h2Count < 3) {
|
|
247
|
+
items.push({
|
|
248
|
+
id: "headings-density",
|
|
249
|
+
category: "headings",
|
|
250
|
+
severity: "warning",
|
|
251
|
+
label: "Article could use more section headings",
|
|
252
|
+
description: `${h2Count} H2 heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
|
|
253
|
+
howToFix: "Articles above 1,500 words usually need at least 3 H2 sections. Break the content into more named blocks.",
|
|
254
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
// H1 inside body (the title is already the H1)
|
|
258
|
+
if (headingsDetailed) {
|
|
259
|
+
const bodyH1 = headingsDetailed.filter((h) => h.level === 1).length;
|
|
260
|
+
if (bodyH1 > 0) {
|
|
261
|
+
items.push({
|
|
262
|
+
id: "headings-h1-in-body",
|
|
263
|
+
category: "headings",
|
|
264
|
+
severity: "warning",
|
|
265
|
+
label: "H1 inside the body",
|
|
266
|
+
description: `${bodyH1} H1 heading${bodyH1 === 1 ? "" : "s"} in the body of the article.`,
|
|
267
|
+
howToFix: "The article title is your H1. Body headings should start at H2 so the outline isn't ambiguous.",
|
|
268
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
// Skipped-level check
|
|
272
|
+
let prevLevel = 0;
|
|
273
|
+
let skips = 0;
|
|
274
|
+
for (const h of headingsDetailed) {
|
|
275
|
+
if (prevLevel > 0 && h.level > prevLevel + 1) skips++;
|
|
276
|
+
prevLevel = h.level;
|
|
277
|
+
}
|
|
278
|
+
if (skips > 0) {
|
|
279
|
+
items.push({
|
|
280
|
+
id: "headings-skipped-levels",
|
|
281
|
+
category: "headings",
|
|
282
|
+
severity: "warning",
|
|
283
|
+
label: "Heading levels skip",
|
|
284
|
+
description: `${skips} place${skips === 1 ? "" : "s"} where the heading level jumps (e.g. H2 to H4).`,
|
|
285
|
+
howToFix: "Use sequential heading levels (H2 → H3 → H4) so screen readers and search engines parse the outline cleanly.",
|
|
286
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
// Empty heading blocks
|
|
290
|
+
const empties = headingsDetailed.filter((h) => !h.text.trim()).length;
|
|
291
|
+
if (empties > 0) {
|
|
292
|
+
items.push({
|
|
293
|
+
id: "headings-empty",
|
|
294
|
+
category: "headings",
|
|
295
|
+
severity: "error",
|
|
296
|
+
label: "Empty heading blocks",
|
|
297
|
+
description: `${empties} heading${empties === 1 ? "" : "s"} with no text.`,
|
|
298
|
+
howToFix: "Either remove the empty heading blocks or fill them with text.",
|
|
299
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ---------- IMAGES ----------
|
|
305
|
+
const images = documentFields?.imageNames || [];
|
|
306
|
+
if (images.length === 0 && wordCount > 300) {
|
|
307
|
+
items.push({
|
|
308
|
+
id: "images-none",
|
|
309
|
+
category: "images",
|
|
310
|
+
severity: "opportunity",
|
|
311
|
+
label: "No images",
|
|
312
|
+
description: "Article doesn't have any images.",
|
|
313
|
+
howToFix: "Add at least one hero image with descriptive alt text. Articles with images perform better on both reader engagement and search.",
|
|
314
|
+
jumpTo: { tab: "technical", anchorId: "anchor-images" },
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
// Filename + alt quality - mirrors the classification heuristic in TechnicalTab.
|
|
318
|
+
const IMG_EXT_RE = /\.(jpe?g|png|gif|webp|svg|tiff?|bmp)$/i;
|
|
319
|
+
const GENERIC_FN_RE = /^(IMG_|DSC|DCIM|screenshot|photo\d*|image\d*|untitled|file_?\d+|unsplash|stock)/i;
|
|
320
|
+
const imageFilenames = images.filter((n) => IMG_EXT_RE.test(n));
|
|
321
|
+
const imageAlts = images.filter((n) => !IMG_EXT_RE.test(n));
|
|
322
|
+
const badFilenames = imageFilenames.filter((f) => {
|
|
323
|
+
const base = f.replace(IMG_EXT_RE, "");
|
|
324
|
+
if (GENERIC_FN_RE.test(base)) return true;
|
|
325
|
+
if (/_/.test(base) || /\s/.test(base)) return true;
|
|
326
|
+
const words = base.split("-").filter(Boolean);
|
|
327
|
+
return words.length < 2 || words.length > 7;
|
|
328
|
+
});
|
|
329
|
+
if (badFilenames.length > 0) {
|
|
330
|
+
items.push({
|
|
331
|
+
id: "images-filenames-bad",
|
|
332
|
+
category: "images",
|
|
333
|
+
severity: "warning",
|
|
334
|
+
label: `${badFilenames.length} image filename${badFilenames.length === 1 ? "" : "s"} needs work`,
|
|
335
|
+
description: "Filenames should use 2-3 hyphenated descriptive words.",
|
|
336
|
+
howToFix: "Rename images with 2-3 descriptive hyphenated words, ideally including the primary keyword. Avoid IMG_xxxx, screenshot, photo1.",
|
|
337
|
+
jumpTo: { tab: "technical", anchorId: "anchor-image-filenames" },
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
const badAlts = imageAlts.filter((alt) => {
|
|
341
|
+
const trimmed = alt.trim();
|
|
342
|
+
if (!trimmed) return false;
|
|
343
|
+
const len = trimmed.length;
|
|
344
|
+
const wc = trimmed.split(/\s+/).filter(Boolean).length;
|
|
345
|
+
return len > 125 || wc < 2;
|
|
346
|
+
});
|
|
347
|
+
if (badAlts.length > 0) {
|
|
348
|
+
items.push({
|
|
349
|
+
id: "images-alt-bad",
|
|
350
|
+
category: "images",
|
|
351
|
+
severity: "warning",
|
|
352
|
+
label: `${badAlts.length} image alt text${badAlts.length === 1 ? "" : "s"} needs work`,
|
|
353
|
+
description: "Alt text should be 2-5 descriptive keywords, under 125 chars.",
|
|
354
|
+
howToFix: "Write alt text as 2-5 descriptive keywords that describe the image, ideally including the primary keyword. Keep it under 125 characters.",
|
|
355
|
+
jumpTo: { tab: "technical", anchorId: "anchor-image-alt" },
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
// Image titles (the hover tooltip) - the director treats this as an SEO signal.
|
|
359
|
+
const imageTitleCount = (documentFields?.imageTitles || []).length;
|
|
360
|
+
const totalImageCount = documentFields?.imageCount ?? 0;
|
|
361
|
+
const missingTitles = totalImageCount > 0 ? totalImageCount - imageTitleCount : 0;
|
|
362
|
+
if (missingTitles > 0) {
|
|
363
|
+
items.push({
|
|
364
|
+
id: "images-titles-missing",
|
|
365
|
+
category: "images",
|
|
366
|
+
severity: "warning",
|
|
367
|
+
label: `${missingTitles} image${missingTitles === 1 ? "" : "s"} missing a title`,
|
|
368
|
+
description: "The title attribute shows on hover and sends an SEO signal.",
|
|
369
|
+
howToFix: "Add a descriptive title attribute (2-5 keywords) to each image that's missing one.",
|
|
370
|
+
jumpTo: { tab: "technical", anchorId: "anchor-image-titles" },
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// ---------- KEYWORDS: primary candidate confidence ----------
|
|
375
|
+
if (!primaryKeyword) {
|
|
376
|
+
// Keywords haven't loaded - skip
|
|
377
|
+
} else {
|
|
378
|
+
// If primary is missing from body, flag it
|
|
379
|
+
if (text && !tokensContain(text, primaryKeyword)) {
|
|
380
|
+
items.push({
|
|
381
|
+
id: "keywords-primary-not-in-body",
|
|
382
|
+
category: "keywords",
|
|
383
|
+
severity: "warning",
|
|
384
|
+
label: "Primary keyword not in body",
|
|
385
|
+
description: `"${primaryKeyword}" doesn't appear in the article body.`,
|
|
386
|
+
howToFix: "Use the primary keyword naturally in the introduction and at least one body paragraph.",
|
|
387
|
+
jumpTo: { tab: "keywords" },
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ---------- CONTENT SCORE ----------
|
|
393
|
+
// The score itself is shown as a card at the top of the Summary tab with a
|
|
394
|
+
// visible per-component breakdown, so we DON'T echo it here as a separate
|
|
395
|
+
// item - that would be redundant. The individual signals (missing keywords,
|
|
396
|
+
// short title, etc.) already produce their own actionable items above.
|
|
397
|
+
|
|
398
|
+
// ---------- AEO: question headings ----------
|
|
399
|
+
const questionHeadings = deepAnalysis?.aeo?.questionHeadings || [];
|
|
400
|
+
if (deepAnalysis && questionHeadings.length === 0 && wordCount > 300) {
|
|
401
|
+
items.push({
|
|
402
|
+
id: "aeo-no-question-headings",
|
|
403
|
+
category: "aeo",
|
|
404
|
+
severity: "opportunity",
|
|
405
|
+
label: "No question-style headings",
|
|
406
|
+
description: "None of your headings are phrased as questions.",
|
|
407
|
+
howToFix: "Rewrite a heading or two as a question (\"What is...?\", \"How does...?\"). Google often pulls question headings into featured snippets.",
|
|
408
|
+
jumpTo: { tab: "aeo" },
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ---------- LINKING: low coverage ----------
|
|
413
|
+
if (linkingSuggestions.length === 0 && analysis && wordCount > 500) {
|
|
414
|
+
items.push({
|
|
415
|
+
id: "linking-none",
|
|
416
|
+
category: "internal-linking",
|
|
417
|
+
severity: "opportunity",
|
|
418
|
+
label: "No internal links suggested yet",
|
|
419
|
+
description: "Linking suggestions haven't been generated for this article.",
|
|
420
|
+
howToFix: "Open the Linking tab and refresh to fetch related articles to link to.",
|
|
421
|
+
jumpTo: { tab: "linking", anchorId: "anchor-linking-suggestions" },
|
|
422
|
+
});
|
|
423
|
+
} else if (linkingSuggestions.length > 0) {
|
|
424
|
+
const strong = linkingSuggestions.filter((s) => s.compositeScore >= 60).length;
|
|
425
|
+
if (strong === 0) {
|
|
426
|
+
items.push({
|
|
427
|
+
id: "linking-weak",
|
|
428
|
+
category: "internal-linking",
|
|
429
|
+
severity: "opportunity",
|
|
430
|
+
label: "Linking matches are weak",
|
|
431
|
+
description: "None of the suggested articles reach 60% match for relevance.",
|
|
432
|
+
howToFix: "Refine your primary keyword on the Keywords tab for tighter matches - or skip linking for this article.",
|
|
433
|
+
jumpTo: { tab: "linking", anchorId: "anchor-linking-suggestions" },
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// ---------- TECHNICAL: broken links (Other Recs tab) ----------
|
|
439
|
+
// Only surfaces after the editor has actually run the check on the Other Recs tab.
|
|
440
|
+
if (linkCheckResults && linkCheckResults.length > 0) {
|
|
441
|
+
const broken = linkCheckResults.filter((r) => r.category === "broken" || r.category === "error");
|
|
442
|
+
if (broken.length > 0) {
|
|
443
|
+
items.push({
|
|
444
|
+
id: "broken-links",
|
|
445
|
+
category: "technical",
|
|
446
|
+
severity: "error",
|
|
447
|
+
label: `${broken.length} broken link${broken.length === 1 ? "" : "s"}`,
|
|
448
|
+
description: `${broken.length} link${broken.length === 1 ? " was" : "s were"} unreachable or returned an error status.`,
|
|
449
|
+
howToFix: "Open the Other Recs tab's Link Health card to see the failing URLs and fix or remove them.",
|
|
450
|
+
jumpTo: { tab: "technical", anchorId: "anchor-link-check" },
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ---------- DEEP ANALYSIS: readability / gaps / structure ----------
|
|
456
|
+
if (deepAnalysis) {
|
|
457
|
+
const readability = deepAnalysis.readabilityNotes || [];
|
|
458
|
+
const gaps = deepAnalysis.competitiveGaps || [];
|
|
459
|
+
const structure = deepAnalysis.structureRecommendations || [];
|
|
460
|
+
readability.slice(0, 2).forEach((note, i) => {
|
|
461
|
+
items.push({
|
|
462
|
+
id: `deep-readability-${i}`,
|
|
463
|
+
category: "content",
|
|
464
|
+
severity: "opportunity",
|
|
465
|
+
label: "Readability note",
|
|
466
|
+
description: note,
|
|
467
|
+
howToFix: "Simplify the flagged passages - shorter sentences, fewer clauses, plainer phrasing where the clinical meaning allows.",
|
|
468
|
+
jumpTo: { tab: "summary" },
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
gaps.slice(0, 2).forEach((note, i) => {
|
|
472
|
+
items.push({
|
|
473
|
+
id: `deep-gap-${i}`,
|
|
474
|
+
category: "content",
|
|
475
|
+
severity: "opportunity",
|
|
476
|
+
label: "Competitive gap",
|
|
477
|
+
description: note,
|
|
478
|
+
howToFix: "Add a section covering this topic so the article matches what competing pages offer.",
|
|
479
|
+
jumpTo: { tab: "summary" },
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
structure.slice(0, 2).forEach((note, i) => {
|
|
483
|
+
items.push({
|
|
484
|
+
id: `deep-structure-${i}`,
|
|
485
|
+
category: "headings",
|
|
486
|
+
severity: "opportunity",
|
|
487
|
+
label: "Structure recommendation",
|
|
488
|
+
description: note,
|
|
489
|
+
howToFix: "Update the heading or section structure per the recommendation.",
|
|
490
|
+
jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Sort: severity (error > warning > opportunity), then category alphabetical
|
|
496
|
+
const severityRank: Record<string, number> = { error: 0, warning: 1, opportunity: 2 };
|
|
497
|
+
items.sort((a, b) => {
|
|
498
|
+
const s = severityRank[a.severity] - severityRank[b.severity];
|
|
499
|
+
if (s !== 0) return s;
|
|
500
|
+
return a.category.localeCompare(b.category);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
return items;
|
|
504
|
+
}
|