sanity-plugin-seo-copilot 0.1.2 → 0.2.0
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 +1 -1
- 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,776 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { LoadingBars } from "../SEOCopilotPanel";
|
|
3
|
+
import { MJH_BLUE, MJH_GOLD } from "../styles";
|
|
4
|
+
import type { DocumentFields, HeadingItem, LinkCheckResult, TechnicalAuditItem } from "../../lib/types";
|
|
5
|
+
|
|
6
|
+
interface TechnicalTabProps {
|
|
7
|
+
text: string;
|
|
8
|
+
documentFields?: DocumentFields;
|
|
9
|
+
isLoading?: boolean;
|
|
10
|
+
// Link-check state lifted to the panel so results survive tab switches and re-mount.
|
|
11
|
+
linkCheckResults: LinkCheckResult[];
|
|
12
|
+
isLinkCheckLoading: boolean;
|
|
13
|
+
linkCheckError: string | null;
|
|
14
|
+
hasRunLinkCheck: boolean;
|
|
15
|
+
onCheckLinks: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cardStyle: React.CSSProperties = {
|
|
19
|
+
borderRadius: 14,
|
|
20
|
+
background: "rgba(255,255,255,0.55)",
|
|
21
|
+
backdropFilter: "blur(16px) saturate(170%)",
|
|
22
|
+
WebkitBackdropFilter: "blur(16px) saturate(170%)",
|
|
23
|
+
boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.85), inset 1.5px 2px 1px -1px rgba(255,255,255,1), inset -2px -3px 2px -1px rgba(255,255,255,0.6), 0 2px 6px rgba(0,0,0,0.07), 0 10px 26px rgba(0,0,0,0.08)",
|
|
24
|
+
padding: "14px",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function StatusBadge({ status }: { status: TechnicalAuditItem["status"] }) {
|
|
28
|
+
const map = {
|
|
29
|
+
good: { bg: "rgba(22,163,74,0.12)", color: "#16a34a", label: "Good" },
|
|
30
|
+
warning: { bg: "rgba(230,192,27,0.18)", color: "#8B7310", label: "Review" },
|
|
31
|
+
error: { bg: "rgba(220,38,38,0.1)", color: "#dc2626", label: "Fix" },
|
|
32
|
+
} as const;
|
|
33
|
+
const c = map[status];
|
|
34
|
+
return (
|
|
35
|
+
<span
|
|
36
|
+
style={{
|
|
37
|
+
fontSize: 9,
|
|
38
|
+
fontWeight: 700,
|
|
39
|
+
textTransform: "uppercase",
|
|
40
|
+
letterSpacing: "0.05em",
|
|
41
|
+
padding: "2px 7px",
|
|
42
|
+
borderRadius: 99,
|
|
43
|
+
background: c.bg,
|
|
44
|
+
color: c.color,
|
|
45
|
+
flexShrink: 0,
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
{c.label}
|
|
49
|
+
</span>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function AuditCard({
|
|
54
|
+
label,
|
|
55
|
+
value,
|
|
56
|
+
status,
|
|
57
|
+
recommendation,
|
|
58
|
+
anchorId,
|
|
59
|
+
}: {
|
|
60
|
+
label: string;
|
|
61
|
+
value: string;
|
|
62
|
+
status: TechnicalAuditItem["status"];
|
|
63
|
+
recommendation?: string;
|
|
64
|
+
anchorId?: string;
|
|
65
|
+
}) {
|
|
66
|
+
return (
|
|
67
|
+
<div id={anchorId} style={cardStyle}>
|
|
68
|
+
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
|
|
69
|
+
<span style={{ fontSize: 10.5, textTransform: "uppercase", letterSpacing: "0.06em", color: "#4b5563", fontWeight: 600 }}>
|
|
70
|
+
{label}
|
|
71
|
+
</span>
|
|
72
|
+
<StatusBadge status={status} />
|
|
73
|
+
</div>
|
|
74
|
+
<div
|
|
75
|
+
style={{
|
|
76
|
+
fontSize: 12,
|
|
77
|
+
color: status === "error" ? "#9ca3af" : "#374151",
|
|
78
|
+
lineHeight: 1.5,
|
|
79
|
+
fontStyle: status === "error" ? "italic" : "normal",
|
|
80
|
+
wordBreak: "break-word",
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
{value}
|
|
84
|
+
</div>
|
|
85
|
+
{recommendation && (
|
|
86
|
+
<div
|
|
87
|
+
style={{
|
|
88
|
+
marginTop: 8,
|
|
89
|
+
padding: "6px 10px",
|
|
90
|
+
background: status === "error" ? "rgba(220,38,38,0.04)" : "rgba(230,192,27,0.06)",
|
|
91
|
+
borderLeft: `2px solid ${status === "error" ? "#dc2626" : "#E6C01B"}`,
|
|
92
|
+
borderRadius: 6,
|
|
93
|
+
fontSize: 11,
|
|
94
|
+
color: "#1f2937",
|
|
95
|
+
lineHeight: 1.5,
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{recommendation}
|
|
99
|
+
</div>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const IMAGE_EXT_RE = /\.(jpe?g|png|gif|webp|svg|tiff?|bmp)$/i;
|
|
106
|
+
const GENERIC_FILENAME_RE = /^(IMG_|DSC|DCIM|screenshot|photo\d*|image\d*|untitled|file_?\d+|unsplash|stock)/i;
|
|
107
|
+
|
|
108
|
+
// Split the mixed imageNames array into filename strings (have a file extension)
|
|
109
|
+
// and alt-text strings (everything else). Lets us run targeted audits on each.
|
|
110
|
+
function classifyImageNames(names: string[]): { filenames: string[]; altTexts: string[] } {
|
|
111
|
+
const filenames: string[] = [];
|
|
112
|
+
const altTexts: string[] = [];
|
|
113
|
+
for (const n of names) {
|
|
114
|
+
if (IMAGE_EXT_RE.test(n)) filenames.push(n);
|
|
115
|
+
else altTexts.push(n);
|
|
116
|
+
}
|
|
117
|
+
return { filenames, altTexts };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Filename audit. Director's ask: 2-3 hyphenated keywords, ideally including the
|
|
121
|
+
// primary keyword; no underscores or special characters. Returns null when no
|
|
122
|
+
// filenames are present (often the case since asset filenames only flow through
|
|
123
|
+
// when the asset is pre-expanded in the document pane).
|
|
124
|
+
function imageFilenameAudit(filenames: string[]): TechnicalAuditItem | null {
|
|
125
|
+
if (filenames.length === 0) return null;
|
|
126
|
+
const issues: { filename: string; reason: string }[] = [];
|
|
127
|
+
for (const f of filenames) {
|
|
128
|
+
const base = f.replace(IMAGE_EXT_RE, "");
|
|
129
|
+
if (GENERIC_FILENAME_RE.test(base)) {
|
|
130
|
+
issues.push({ filename: f, reason: "generic name from a camera or screenshot tool" });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (/_/.test(base)) {
|
|
134
|
+
issues.push({ filename: f, reason: "uses underscores instead of hyphens" });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (/\s/.test(base)) {
|
|
138
|
+
issues.push({ filename: f, reason: "contains spaces (use hyphens)" });
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const words = base.split("-").filter(Boolean);
|
|
142
|
+
if (words.length < 2) {
|
|
143
|
+
issues.push({ filename: f, reason: "single word - use 2-3 descriptive hyphenated words" });
|
|
144
|
+
} else if (words.length > 7) {
|
|
145
|
+
issues.push({ filename: f, reason: "too many words - keep to 3-5" });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (issues.length === 0) {
|
|
149
|
+
return {
|
|
150
|
+
label: "Image Filenames",
|
|
151
|
+
value: `${filenames.length} filename${filenames.length === 1 ? "" : "s"} look descriptive`,
|
|
152
|
+
status: "good",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const examples = issues.slice(0, 2).map((i) => `"${i.filename}" - ${i.reason}`).join("; ");
|
|
156
|
+
return {
|
|
157
|
+
label: "Image Filenames",
|
|
158
|
+
value: `${issues.length} of ${filenames.length} filename${filenames.length === 1 ? "" : "s"} need attention`,
|
|
159
|
+
status: "warning",
|
|
160
|
+
recommendation: `${examples}. Use 2-3 hyphenated descriptive words, ideally including the primary keyword.`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Alt-text audit. Per director guidance, alt text should be roughly 2-5
|
|
165
|
+
// descriptive keywords - so we only flag the genuinely bad cases: a single bare
|
|
166
|
+
// word (not descriptive) or text so long Google would truncate it / it reads as
|
|
167
|
+
// keyword stuffing (>125 chars). Empty alt is intentional for decorative images
|
|
168
|
+
// and not flagged.
|
|
169
|
+
function imageAltTextAudit(altTexts: string[]): TechnicalAuditItem | null {
|
|
170
|
+
if (altTexts.length === 0) return null;
|
|
171
|
+
const issues: { alt: string; reason: string }[] = [];
|
|
172
|
+
for (const alt of altTexts) {
|
|
173
|
+
const trimmed = alt.trim();
|
|
174
|
+
if (!trimmed) continue; // empty alt is intentional - skip
|
|
175
|
+
const len = trimmed.length;
|
|
176
|
+
const wc = trimmed.split(/\s+/).filter(Boolean).length;
|
|
177
|
+
if (len > 125) {
|
|
178
|
+
issues.push({ alt: trimmed, reason: `${len} chars - shorten to under 125` });
|
|
179
|
+
} else if (wc < 2) {
|
|
180
|
+
issues.push({ alt: trimmed, reason: "just one word - use 2-5 descriptive keywords" });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (issues.length === 0) {
|
|
184
|
+
return {
|
|
185
|
+
label: "Image Alt Text",
|
|
186
|
+
value: `${altTexts.length} alt text${altTexts.length === 1 ? "" : "s"} look well-formed`,
|
|
187
|
+
status: "good",
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const examples = issues.slice(0, 2).map((i) => {
|
|
191
|
+
const short = i.alt.length > 50 ? `${i.alt.slice(0, 50)}...` : i.alt;
|
|
192
|
+
return `"${short}" - ${i.reason}`;
|
|
193
|
+
}).join("; ");
|
|
194
|
+
return {
|
|
195
|
+
label: "Image Alt Text",
|
|
196
|
+
value: `${issues.length} of ${altTexts.length} alt text${altTexts.length === 1 ? "" : "s"} need attention`,
|
|
197
|
+
status: "warning",
|
|
198
|
+
recommendation: `${examples}. Alt text should be 2-5 descriptive keywords that describe the image, ideally including the primary keyword, and stay under 125 characters.`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Image title audit. Per the director, the title attribute (the tooltip shown on
|
|
203
|
+
// hover) sends an SEO signal, so each image should carry a short descriptive title.
|
|
204
|
+
// Flags images with no title, and titles that are a single bare word.
|
|
205
|
+
function imageTitleAudit(titles: string[], imageCount: number): TechnicalAuditItem | null {
|
|
206
|
+
if (imageCount <= 0) return null;
|
|
207
|
+
const withTitle = titles.length;
|
|
208
|
+
const missing = imageCount - withTitle;
|
|
209
|
+
if (missing > 0) {
|
|
210
|
+
return {
|
|
211
|
+
label: "Image Titles",
|
|
212
|
+
value: `${withTitle} of ${imageCount} image${imageCount === 1 ? "" : "s"} ${withTitle === 1 ? "has" : "have"} a title`,
|
|
213
|
+
status: "warning",
|
|
214
|
+
recommendation: `Add a descriptive title attribute (2-5 keywords) to the ${missing} image${missing === 1 ? "" : "s"} without one. The title appears on hover and sends an SEO signal.`,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const sparse = titles.filter((t) => t.trim().split(/\s+/).filter(Boolean).length < 2);
|
|
218
|
+
if (sparse.length > 0) {
|
|
219
|
+
return {
|
|
220
|
+
label: "Image Titles",
|
|
221
|
+
value: `${sparse.length} image title${sparse.length === 1 ? "" : "s"} ${sparse.length === 1 ? "is" : "are"} a single word`,
|
|
222
|
+
status: "warning",
|
|
223
|
+
recommendation: "Use 2-5 descriptive keywords in each image title, not a single word.",
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
label: "Image Titles",
|
|
228
|
+
value: `All ${imageCount} image${imageCount === 1 ? "" : "s"} have a descriptive title`,
|
|
229
|
+
status: "good",
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Audits the body's heading structure: density (H2s per word count), H1 in body,
|
|
234
|
+
// heading-level skips, and empty heading blocks.
|
|
235
|
+
function computeHeadingStructureAudits(headings: HeadingItem[], wordCount: number): TechnicalAuditItem[] {
|
|
236
|
+
const audits: TechnicalAuditItem[] = [];
|
|
237
|
+
const h2Count = headings.filter((h) => h.level === 2).length;
|
|
238
|
+
|
|
239
|
+
// Heading-density check. Thresholds backed by SEO best-practice research:
|
|
240
|
+
// > 2,500 words really wants 1 H2 per ~400 words; 1,500+ usually needs 3+;
|
|
241
|
+
// 1,000+ without any H2 is unreadable. Below 1,000 words structure isn't
|
|
242
|
+
// critical so we don't flag it as a density issue.
|
|
243
|
+
// Order matters: the zero-H2 case is an error and must be checked before the
|
|
244
|
+
// softer density warnings, so a long article with no headings reports "error"
|
|
245
|
+
// (matching summary.ts) rather than falling into a lower-severity branch.
|
|
246
|
+
let densityFired = false;
|
|
247
|
+
if (wordCount >= 1000 && h2Count === 0) {
|
|
248
|
+
audits.push({
|
|
249
|
+
label: "Section Headings",
|
|
250
|
+
value: `No H2 headings in a ${wordCount}-word article`,
|
|
251
|
+
status: "error",
|
|
252
|
+
recommendation: "Articles this long need section headings. Add 2-3 H2 headings to break the body into scannable sections.",
|
|
253
|
+
});
|
|
254
|
+
densityFired = true;
|
|
255
|
+
} else if (wordCount >= 2500 && h2Count < 5) {
|
|
256
|
+
audits.push({
|
|
257
|
+
label: "Section Headings",
|
|
258
|
+
value: `${h2Count} H2 heading${h2Count === 1 ? "" : "s"} for a ${wordCount}-word article`,
|
|
259
|
+
status: "warning",
|
|
260
|
+
recommendation: "Long articles read best with 1 H2 per 300-400 words. Break the content into more named sections so readers and search engines can navigate it.",
|
|
261
|
+
});
|
|
262
|
+
densityFired = true;
|
|
263
|
+
} else if (wordCount >= 1500 && h2Count < 3) {
|
|
264
|
+
audits.push({
|
|
265
|
+
label: "Section Headings",
|
|
266
|
+
value: `${h2Count} H2 heading${h2Count === 1 ? "" : "s"} for a ${wordCount}-word article`,
|
|
267
|
+
status: "warning",
|
|
268
|
+
recommendation: "Articles above 1,500 words usually need at least 3 H2 sections. Add named section breaks so the outline is scannable.",
|
|
269
|
+
});
|
|
270
|
+
densityFired = true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// If the body has no headings at all and density didn't already flag it (short article),
|
|
274
|
+
// surface a generic structure note so the editor still sees a hint.
|
|
275
|
+
if (headings.length === 0) {
|
|
276
|
+
if (!densityFired) {
|
|
277
|
+
audits.push({
|
|
278
|
+
label: "Heading Structure",
|
|
279
|
+
value: "No headings in body",
|
|
280
|
+
status: "warning",
|
|
281
|
+
recommendation: "Add H2 headings to break the article into scannable sections.",
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return audits;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// H1 inside the body - the article title is the H1, so body should start at H2.
|
|
288
|
+
const h1s = headings.filter((h) => h.level === 1);
|
|
289
|
+
if (h1s.length > 0) {
|
|
290
|
+
audits.push({
|
|
291
|
+
label: "H1 in body",
|
|
292
|
+
value: `${h1s.length} H1 heading${h1s.length === 1 ? "" : "s"} in the body`,
|
|
293
|
+
status: "warning",
|
|
294
|
+
recommendation: "The article title is your H1. Body headings should start at H2 so the outline isn't ambiguous.",
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Skipped levels (e.g. H2 followed by H4 with no H3 between them).
|
|
299
|
+
let prevLevel = 0;
|
|
300
|
+
const skips: { from: number; to: number; at: string }[] = [];
|
|
301
|
+
for (const h of headings) {
|
|
302
|
+
if (prevLevel > 0 && h.level > prevLevel + 1) {
|
|
303
|
+
skips.push({ from: prevLevel, to: h.level, at: h.text || "(empty)" });
|
|
304
|
+
}
|
|
305
|
+
prevLevel = h.level;
|
|
306
|
+
}
|
|
307
|
+
if (skips.length > 0) {
|
|
308
|
+
const first = skips[0];
|
|
309
|
+
audits.push({
|
|
310
|
+
label: "Heading Hierarchy",
|
|
311
|
+
value: `${skips.length} skipped level${skips.length === 1 ? "" : "s"}`,
|
|
312
|
+
status: "warning",
|
|
313
|
+
recommendation: `Headings jump from H${first.from} to H${first.to} at "${first.at.slice(0, 60)}". Use sequential levels (H2 → H3 → H4) so the outline reads cleanly to screen readers and search engines.`,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Empty heading blocks.
|
|
318
|
+
const empties = headings.filter((h) => !h.text.trim());
|
|
319
|
+
if (empties.length > 0) {
|
|
320
|
+
audits.push({
|
|
321
|
+
label: "Empty Headings",
|
|
322
|
+
value: `${empties.length} empty heading${empties.length === 1 ? "" : "s"}`,
|
|
323
|
+
status: "error",
|
|
324
|
+
recommendation: "Either remove the empty heading blocks or fill them with text. Empty headings confuse the outline.",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Clean bill of health.
|
|
329
|
+
if (audits.length === 0) {
|
|
330
|
+
audits.push({
|
|
331
|
+
label: "Heading Structure",
|
|
332
|
+
value: `${headings.length} heading${headings.length === 1 ? "" : "s"}, hierarchy is clean`,
|
|
333
|
+
status: "good",
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return audits;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function LinkCheckCard({
|
|
341
|
+
urls,
|
|
342
|
+
results,
|
|
343
|
+
isLoading,
|
|
344
|
+
error,
|
|
345
|
+
hasRun,
|
|
346
|
+
onCheck,
|
|
347
|
+
}: {
|
|
348
|
+
urls: string[];
|
|
349
|
+
results: LinkCheckResult[];
|
|
350
|
+
isLoading: boolean;
|
|
351
|
+
error: string | null;
|
|
352
|
+
hasRun: boolean;
|
|
353
|
+
onCheck: () => void;
|
|
354
|
+
}) {
|
|
355
|
+
const counts = useMemo(() => {
|
|
356
|
+
const total = results.length;
|
|
357
|
+
const valid = results.filter((r) => r.category === "ok").length;
|
|
358
|
+
const redirects = results.filter((r) => r.category === "redirect").length;
|
|
359
|
+
const broken = results.filter((r) => r.category === "broken").length;
|
|
360
|
+
const errored = results.filter((r) => r.category === "error").length;
|
|
361
|
+
const issues = results.filter((r) => r.category !== "ok");
|
|
362
|
+
return { total, valid, redirects, broken, errored, issues };
|
|
363
|
+
}, [results]);
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<div id="anchor-link-check" style={cardStyle}>
|
|
367
|
+
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
|
|
368
|
+
<span style={{ fontSize: 10.5, textTransform: "uppercase", letterSpacing: "0.06em", color: "#4b5563", fontWeight: 600 }}>
|
|
369
|
+
Link Health
|
|
370
|
+
</span>
|
|
371
|
+
{hasRun && !isLoading && (
|
|
372
|
+
<button
|
|
373
|
+
onClick={onCheck}
|
|
374
|
+
style={{
|
|
375
|
+
background: "none",
|
|
376
|
+
border: "none",
|
|
377
|
+
fontSize: 10,
|
|
378
|
+
fontWeight: 600,
|
|
379
|
+
color: MJH_BLUE,
|
|
380
|
+
cursor: "pointer",
|
|
381
|
+
padding: "2px 4px",
|
|
382
|
+
}}
|
|
383
|
+
title="Run again"
|
|
384
|
+
>
|
|
385
|
+
Re-check
|
|
386
|
+
</button>
|
|
387
|
+
)}
|
|
388
|
+
</div>
|
|
389
|
+
|
|
390
|
+
<div style={{ fontSize: 11, color: "#1f2937", lineHeight: 1.5, marginBottom: 10 }}>
|
|
391
|
+
{urls.length === 0
|
|
392
|
+
? "No external links found in the body."
|
|
393
|
+
: `${urls.length} link${urls.length === 1 ? "" : "s"} found in the body.`}
|
|
394
|
+
</div>
|
|
395
|
+
|
|
396
|
+
{urls.length > 0 && !hasRun && !isLoading && (
|
|
397
|
+
<button
|
|
398
|
+
onClick={onCheck}
|
|
399
|
+
style={{
|
|
400
|
+
width: "100%",
|
|
401
|
+
padding: "8px 12px",
|
|
402
|
+
fontSize: 11,
|
|
403
|
+
fontWeight: 700,
|
|
404
|
+
color: "#1f2937",
|
|
405
|
+
background: MJH_GOLD,
|
|
406
|
+
border: "none",
|
|
407
|
+
borderRadius: 6,
|
|
408
|
+
cursor: "pointer",
|
|
409
|
+
letterSpacing: "0.01em",
|
|
410
|
+
}}
|
|
411
|
+
>
|
|
412
|
+
Check {urls.length} link{urls.length === 1 ? "" : "s"} for 404s
|
|
413
|
+
</button>
|
|
414
|
+
)}
|
|
415
|
+
|
|
416
|
+
{isLoading && (
|
|
417
|
+
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 8, padding: "16px 0" }}>
|
|
418
|
+
<LoadingBars size="xs" color={MJH_BLUE} />
|
|
419
|
+
<span style={{ fontSize: 11, color: "#4b5563" }}>Checking {urls.length} link{urls.length === 1 ? "" : "s"}...</span>
|
|
420
|
+
</div>
|
|
421
|
+
)}
|
|
422
|
+
|
|
423
|
+
{error && !isLoading && (
|
|
424
|
+
<div
|
|
425
|
+
style={{
|
|
426
|
+
padding: "10px 12px",
|
|
427
|
+
background: "rgba(220,38,38,0.04)",
|
|
428
|
+
border: "1px solid rgba(220,38,38,0.18)",
|
|
429
|
+
borderRadius: 8,
|
|
430
|
+
fontSize: 11,
|
|
431
|
+
color: "#b91c1c",
|
|
432
|
+
lineHeight: 1.5,
|
|
433
|
+
}}
|
|
434
|
+
>
|
|
435
|
+
{error}
|
|
436
|
+
<button
|
|
437
|
+
onClick={onCheck}
|
|
438
|
+
style={{
|
|
439
|
+
display: "block",
|
|
440
|
+
marginTop: 6,
|
|
441
|
+
padding: "4px 10px",
|
|
442
|
+
fontSize: 11,
|
|
443
|
+
fontWeight: 700,
|
|
444
|
+
color: "#ffffff",
|
|
445
|
+
background: "#dc2626",
|
|
446
|
+
border: "none",
|
|
447
|
+
borderRadius: 5,
|
|
448
|
+
cursor: "pointer",
|
|
449
|
+
}}
|
|
450
|
+
>
|
|
451
|
+
Try again
|
|
452
|
+
</button>
|
|
453
|
+
</div>
|
|
454
|
+
)}
|
|
455
|
+
|
|
456
|
+
{hasRun && !isLoading && !error && (
|
|
457
|
+
<>
|
|
458
|
+
{/* 4-up summary tile */}
|
|
459
|
+
<div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 6 }}>
|
|
460
|
+
<StatTile label="Checked" value={counts.total} color="#475569" />
|
|
461
|
+
<StatTile label="Valid" value={counts.valid} color="#16a34a" />
|
|
462
|
+
<StatTile label="Redirects" value={counts.redirects} color="#8B7310" />
|
|
463
|
+
<StatTile label="Broken" value={counts.broken + counts.errored} color="#dc2626" />
|
|
464
|
+
</div>
|
|
465
|
+
|
|
466
|
+
{/* Issues list */}
|
|
467
|
+
{counts.issues.length > 0 ? (
|
|
468
|
+
<div style={{ marginTop: 12, display: "flex", flexDirection: "column", gap: 6 }}>
|
|
469
|
+
<div style={{ fontSize: 10, fontWeight: 700, color: "#4b5563", textTransform: "uppercase", letterSpacing: "0.06em" }}>
|
|
470
|
+
{counts.issues.length} link{counts.issues.length === 1 ? "" : "s"} need{counts.issues.length === 1 ? "s" : ""} attention
|
|
471
|
+
</div>
|
|
472
|
+
{counts.issues.map((r) => (
|
|
473
|
+
<LinkIssueRow key={r.url} result={r} />
|
|
474
|
+
))}
|
|
475
|
+
</div>
|
|
476
|
+
) : (
|
|
477
|
+
<div
|
|
478
|
+
style={{
|
|
479
|
+
marginTop: 12,
|
|
480
|
+
padding: "8px 10px",
|
|
481
|
+
background: "rgba(22,163,74,0.05)",
|
|
482
|
+
border: "1px solid rgba(22,163,74,0.15)",
|
|
483
|
+
borderRadius: 8,
|
|
484
|
+
fontSize: 11,
|
|
485
|
+
color: "#16a34a",
|
|
486
|
+
fontWeight: 600,
|
|
487
|
+
textAlign: "center",
|
|
488
|
+
}}
|
|
489
|
+
>
|
|
490
|
+
All {counts.total} link{counts.total === 1 ? "" : "s"} resolve cleanly.
|
|
491
|
+
</div>
|
|
492
|
+
)}
|
|
493
|
+
</>
|
|
494
|
+
)}
|
|
495
|
+
</div>
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function StatTile({ label, value, color }: { label: string; value: number; color: string }) {
|
|
500
|
+
return (
|
|
501
|
+
<div
|
|
502
|
+
style={{
|
|
503
|
+
padding: "8px 4px",
|
|
504
|
+
background: "rgba(0,0,0,0.025)",
|
|
505
|
+
borderRadius: 8,
|
|
506
|
+
textAlign: "center",
|
|
507
|
+
}}
|
|
508
|
+
>
|
|
509
|
+
<div style={{ fontSize: 18, fontWeight: 700, color, fontVariantNumeric: "tabular-nums", lineHeight: 1 }}>{value}</div>
|
|
510
|
+
<div style={{ fontSize: 9, fontWeight: 700, color: "#4b5563", textTransform: "uppercase", letterSpacing: "0.06em", marginTop: 4 }}>
|
|
511
|
+
{label}
|
|
512
|
+
</div>
|
|
513
|
+
</div>
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function LinkIssueRow({ result }: { result: LinkCheckResult }) {
|
|
518
|
+
const map = {
|
|
519
|
+
ok: { bg: "rgba(22,163,74,0.06)", color: "#16a34a", label: "OK" },
|
|
520
|
+
redirect: { bg: "rgba(230,192,27,0.12)", color: "#8B7310", label: result.status > 0 ? String(result.status) : "REDIR" },
|
|
521
|
+
broken: { bg: "rgba(220,38,38,0.06)", color: "#dc2626", label: result.status > 0 ? String(result.status) : "404" },
|
|
522
|
+
error: { bg: "rgba(220,38,38,0.06)", color: "#dc2626", label: "ERR" },
|
|
523
|
+
} as const;
|
|
524
|
+
const c = map[result.category];
|
|
525
|
+
return (
|
|
526
|
+
<a
|
|
527
|
+
href={result.url}
|
|
528
|
+
target="_blank"
|
|
529
|
+
rel="noopener noreferrer"
|
|
530
|
+
style={{
|
|
531
|
+
display: "flex",
|
|
532
|
+
alignItems: "center",
|
|
533
|
+
gap: 8,
|
|
534
|
+
padding: "6px 10px",
|
|
535
|
+
background: c.bg,
|
|
536
|
+
borderRadius: 6,
|
|
537
|
+
textDecoration: "none",
|
|
538
|
+
}}
|
|
539
|
+
>
|
|
540
|
+
<span
|
|
541
|
+
style={{
|
|
542
|
+
fontSize: 9,
|
|
543
|
+
fontWeight: 700,
|
|
544
|
+
letterSpacing: "0.04em",
|
|
545
|
+
padding: "2px 6px",
|
|
546
|
+
borderRadius: 99,
|
|
547
|
+
background: "#ffffff",
|
|
548
|
+
color: c.color,
|
|
549
|
+
fontVariantNumeric: "tabular-nums",
|
|
550
|
+
flexShrink: 0,
|
|
551
|
+
}}
|
|
552
|
+
>
|
|
553
|
+
{c.label}
|
|
554
|
+
</span>
|
|
555
|
+
<span
|
|
556
|
+
style={{
|
|
557
|
+
fontSize: 11,
|
|
558
|
+
color: "#1f2937",
|
|
559
|
+
fontFamily: "ui-monospace, SFMono-Regular, monospace",
|
|
560
|
+
flex: 1,
|
|
561
|
+
minWidth: 0,
|
|
562
|
+
overflow: "hidden",
|
|
563
|
+
textOverflow: "ellipsis",
|
|
564
|
+
whiteSpace: "nowrap",
|
|
565
|
+
}}
|
|
566
|
+
title={result.error ? `${result.url} (${result.error})` : result.url}
|
|
567
|
+
>
|
|
568
|
+
{result.url}
|
|
569
|
+
</span>
|
|
570
|
+
</a>
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export function TechnicalTab({
|
|
575
|
+
text,
|
|
576
|
+
documentFields,
|
|
577
|
+
isLoading,
|
|
578
|
+
linkCheckResults,
|
|
579
|
+
isLinkCheckLoading,
|
|
580
|
+
linkCheckError,
|
|
581
|
+
hasRunLinkCheck,
|
|
582
|
+
onCheckLinks,
|
|
583
|
+
}: TechnicalTabProps) {
|
|
584
|
+
const headings = documentFields?.headings || [];
|
|
585
|
+
const headingsDetailed = documentFields?.headingsDetailed;
|
|
586
|
+
// Fall back gracefully if a host (e.g. older Notebook builds) doesn't supply heading
|
|
587
|
+
// levels - we still get the count audit from the flat string list.
|
|
588
|
+
const headingsForStructure: HeadingItem[] = headingsDetailed
|
|
589
|
+
? headingsDetailed
|
|
590
|
+
: headings.map((text) => ({ text, level: 2 }));
|
|
591
|
+
|
|
592
|
+
// Word count drives both the dedicated Word Count audit and the heading-density check.
|
|
593
|
+
const wordCount = text ? text.split(/\s+/).filter(Boolean).length : 0;
|
|
594
|
+
|
|
595
|
+
const structureAudits = useMemo(
|
|
596
|
+
() => computeHeadingStructureAudits(headingsForStructure, wordCount),
|
|
597
|
+
[headingsForStructure, wordCount]
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
const imageNames = documentFields?.imageNames || [];
|
|
601
|
+
// imageNames is a mixed list: when an image field has an `alt` prop, that
|
|
602
|
+
// string is pushed; when the asset's `originalFilename` is available, it gets
|
|
603
|
+
// pushed too. We classify by file extension to give targeted feedback on each.
|
|
604
|
+
const { filenames: imageFilenames, altTexts: imageAltTexts } = useMemo(
|
|
605
|
+
() => classifyImageNames(imageNames),
|
|
606
|
+
[imageNames]
|
|
607
|
+
);
|
|
608
|
+
const filenameAudit = useMemo(
|
|
609
|
+
() => imageFilenameAudit(imageFilenames),
|
|
610
|
+
[imageFilenames]
|
|
611
|
+
);
|
|
612
|
+
const altTextAudit = useMemo(
|
|
613
|
+
() => imageAltTextAudit(imageAltTexts),
|
|
614
|
+
[imageAltTexts]
|
|
615
|
+
);
|
|
616
|
+
const imageTitles = documentFields?.imageTitles || [];
|
|
617
|
+
const imageCount = documentFields?.imageCount ?? 0;
|
|
618
|
+
const imgTitleAudit = useMemo(
|
|
619
|
+
() => imageTitleAudit(imageTitles, imageCount),
|
|
620
|
+
[imageTitles, imageCount]
|
|
621
|
+
);
|
|
622
|
+
// "No images" only when neither a count nor any alt/filename entry exists.
|
|
623
|
+
const hasImages = imageCount > 0 || imageNames.length > 0;
|
|
624
|
+
const imagesAudit: TechnicalAuditItem | null = !hasImages
|
|
625
|
+
? {
|
|
626
|
+
label: "Images",
|
|
627
|
+
value: "No images detected",
|
|
628
|
+
status: "warning",
|
|
629
|
+
recommendation: "Add at least one hero image with descriptive alt text. Articles with images perform better on both reader engagement and search.",
|
|
630
|
+
}
|
|
631
|
+
: null;
|
|
632
|
+
|
|
633
|
+
// 450 is the body-text floor. 1,500+ is the competitive target for HCP clinical content.
|
|
634
|
+
const wordAudit: TechnicalAuditItem =
|
|
635
|
+
wordCount === 0
|
|
636
|
+
? {
|
|
637
|
+
label: "Word Count",
|
|
638
|
+
value: "0 words",
|
|
639
|
+
status: "error",
|
|
640
|
+
recommendation: "Start writing. A link or image on its own doesn't count - the body needs real written substance.",
|
|
641
|
+
}
|
|
642
|
+
: wordCount < 450
|
|
643
|
+
? {
|
|
644
|
+
label: "Word Count",
|
|
645
|
+
value: `${wordCount} words`,
|
|
646
|
+
status: "error",
|
|
647
|
+
recommendation: "Body copy should be at least 450 words. Add more written content.",
|
|
648
|
+
}
|
|
649
|
+
: wordCount < 1500
|
|
650
|
+
? {
|
|
651
|
+
label: "Word Count",
|
|
652
|
+
value: `${wordCount} words`,
|
|
653
|
+
status: "warning",
|
|
654
|
+
recommendation: "Above the 450-word floor. For competitive clinical content, push past 1,500 words.",
|
|
655
|
+
}
|
|
656
|
+
: { label: "Word Count", value: `${wordCount} words`, status: "good" };
|
|
657
|
+
|
|
658
|
+
const bodyLinks = documentFields?.bodyLinks || [];
|
|
659
|
+
|
|
660
|
+
// Show a loading placeholder while document fields are still loading and we don't
|
|
661
|
+
// have anything yet (avoids a flash of "Missing" cards from prior doc state).
|
|
662
|
+
const hasAnyField =
|
|
663
|
+
!!documentFields &&
|
|
664
|
+
(documentFields.title !== undefined ||
|
|
665
|
+
(documentFields.headings && documentFields.headings.length > 0) ||
|
|
666
|
+
(documentFields.imageNames && documentFields.imageNames.length > 0) ||
|
|
667
|
+
wordCount > 0);
|
|
668
|
+
if (isLoading && !hasAnyField) {
|
|
669
|
+
return (
|
|
670
|
+
<div style={{ padding: 24, textAlign: "center" }}>
|
|
671
|
+
<div style={{ fontSize: 13, color: "#4b5563", fontWeight: 500 }}>Reading document fields...</div>
|
|
672
|
+
<div style={{ fontSize: 11, color: "#4b5563", marginTop: 4 }}>Audit will run once content loads</div>
|
|
673
|
+
</div>
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return (
|
|
678
|
+
<div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
|
|
679
|
+
<AuditCard
|
|
680
|
+
anchorId="anchor-word-count"
|
|
681
|
+
label={wordAudit.label}
|
|
682
|
+
value={wordAudit.value}
|
|
683
|
+
status={wordAudit.status}
|
|
684
|
+
recommendation={wordAudit.recommendation}
|
|
685
|
+
/>
|
|
686
|
+
|
|
687
|
+
{structureAudits.map((a, i) => (
|
|
688
|
+
<AuditCard
|
|
689
|
+
key={`structure-${i}`}
|
|
690
|
+
anchorId={i === 0 ? "anchor-headings-structure" : undefined}
|
|
691
|
+
label={a.label}
|
|
692
|
+
value={a.value}
|
|
693
|
+
status={a.status}
|
|
694
|
+
recommendation={a.recommendation}
|
|
695
|
+
/>
|
|
696
|
+
))}
|
|
697
|
+
|
|
698
|
+
{headings.length > 0 && (
|
|
699
|
+
<div id="anchor-headings-outline" style={{ ...cardStyle, padding: "8px 14px" }}>
|
|
700
|
+
<div style={{ fontSize: 10, color: "#4b5563", textTransform: "uppercase", letterSpacing: "0.06em", fontWeight: 600, marginBottom: 6 }}>
|
|
701
|
+
Heading Outline
|
|
702
|
+
</div>
|
|
703
|
+
<div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
|
|
704
|
+
{(headingsDetailed
|
|
705
|
+
? headingsDetailed.slice(0, 12)
|
|
706
|
+
: headings.slice(0, 12).map((h) => ({ text: h, level: 2 }))
|
|
707
|
+
).map((h, i) => (
|
|
708
|
+
<div
|
|
709
|
+
key={i}
|
|
710
|
+
style={{
|
|
711
|
+
fontSize: 11,
|
|
712
|
+
color: h.text ? "#4b5563" : "#dc2626",
|
|
713
|
+
fontStyle: h.text ? "normal" : "italic",
|
|
714
|
+
lineHeight: 1.4,
|
|
715
|
+
paddingLeft: Math.max(0, (h.level - 2) * 12),
|
|
716
|
+
}}
|
|
717
|
+
>
|
|
718
|
+
<span style={{ fontSize: 9, fontWeight: 700, color: "#4b5563", marginRight: 6 }}>H{h.level}</span>
|
|
719
|
+
{h.text || "(empty)"}
|
|
720
|
+
</div>
|
|
721
|
+
))}
|
|
722
|
+
{headings.length > 12 && (
|
|
723
|
+
<div style={{ fontSize: 10, color: "#4b5563" }}>+ {headings.length - 12} more</div>
|
|
724
|
+
)}
|
|
725
|
+
</div>
|
|
726
|
+
</div>
|
|
727
|
+
)}
|
|
728
|
+
|
|
729
|
+
{imagesAudit && (
|
|
730
|
+
<AuditCard
|
|
731
|
+
anchorId="anchor-images"
|
|
732
|
+
label={imagesAudit.label}
|
|
733
|
+
value={imagesAudit.value}
|
|
734
|
+
status={imagesAudit.status}
|
|
735
|
+
recommendation={imagesAudit.recommendation}
|
|
736
|
+
/>
|
|
737
|
+
)}
|
|
738
|
+
{filenameAudit && (
|
|
739
|
+
<AuditCard
|
|
740
|
+
anchorId="anchor-image-filenames"
|
|
741
|
+
label={filenameAudit.label}
|
|
742
|
+
value={filenameAudit.value}
|
|
743
|
+
status={filenameAudit.status}
|
|
744
|
+
recommendation={filenameAudit.recommendation}
|
|
745
|
+
/>
|
|
746
|
+
)}
|
|
747
|
+
{altTextAudit && (
|
|
748
|
+
<AuditCard
|
|
749
|
+
anchorId="anchor-image-alt"
|
|
750
|
+
label={altTextAudit.label}
|
|
751
|
+
value={altTextAudit.value}
|
|
752
|
+
status={altTextAudit.status}
|
|
753
|
+
recommendation={altTextAudit.recommendation}
|
|
754
|
+
/>
|
|
755
|
+
)}
|
|
756
|
+
{imgTitleAudit && (
|
|
757
|
+
<AuditCard
|
|
758
|
+
anchorId="anchor-image-titles"
|
|
759
|
+
label={imgTitleAudit.label}
|
|
760
|
+
value={imgTitleAudit.value}
|
|
761
|
+
status={imgTitleAudit.status}
|
|
762
|
+
recommendation={imgTitleAudit.recommendation}
|
|
763
|
+
/>
|
|
764
|
+
)}
|
|
765
|
+
|
|
766
|
+
<LinkCheckCard
|
|
767
|
+
urls={bodyLinks}
|
|
768
|
+
results={linkCheckResults}
|
|
769
|
+
isLoading={isLinkCheckLoading}
|
|
770
|
+
error={linkCheckError}
|
|
771
|
+
hasRun={hasRunLinkCheck}
|
|
772
|
+
onCheck={onCheckLinks}
|
|
773
|
+
/>
|
|
774
|
+
</div>
|
|
775
|
+
);
|
|
776
|
+
}
|