sanity-plugin-seo-copilot 0.2.14 → 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 +868 -797
- package/dist/index.mjs +791 -720
- package/package.json +9 -8
- 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 -1233
- 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 -16
- package/src/inspector.ts +0 -58
- package/src/lib/api.ts +0 -260
- 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
|
@@ -1,933 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState } 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
|
-
import { isShortFormContent } from "../../lib/summary";
|
|
6
|
-
import { containsKeywordTokens, keywordLeadsSlug } from "../../lib/utils";
|
|
7
|
-
|
|
8
|
-
interface TechnicalTabProps {
|
|
9
|
-
text: string;
|
|
10
|
-
documentFields?: DocumentFields;
|
|
11
|
-
primaryKeyword?: string;
|
|
12
|
-
secondaryKeyword?: string;
|
|
13
|
-
isLoading?: boolean;
|
|
14
|
-
// Link-check state lifted to the panel so results survive tab switches and re-mount.
|
|
15
|
-
linkCheckResults: LinkCheckResult[];
|
|
16
|
-
isLinkCheckLoading: boolean;
|
|
17
|
-
linkCheckError: string | null;
|
|
18
|
-
hasRunLinkCheck: boolean;
|
|
19
|
-
onCheckLinks: () => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// URL Slug audit (moved here from Meta per the 6/10 director notes). Deliberately
|
|
23
|
-
// vague and non-numeric: we never cite a character count or say "too long" - just
|
|
24
|
-
// scan for the primary keyword (ideally leading the URL) and nudge toward short,
|
|
25
|
-
// descriptive slugs.
|
|
26
|
-
function urlAudit(slug?: string, primaryKeyword?: string, secondaryKeyword?: string): TechnicalAuditItem {
|
|
27
|
-
const SHORT_DESC = "Keep the URL short and descriptive - concise URLs are easier to read - and avoid trailing, duplicate, or excessive spaces.";
|
|
28
|
-
if (!slug) {
|
|
29
|
-
return {
|
|
30
|
-
label: "URL Slug",
|
|
31
|
-
value: "Missing",
|
|
32
|
-
status: "warning",
|
|
33
|
-
recommendation: `Add a URL slug that leads with your primary keyword. ${SHORT_DESC}`,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const slugAsWords = slug.replace(/-/g, " ");
|
|
37
|
-
const hasPrimary = primaryKeyword ? containsKeywordTokens(slugAsWords, primaryKeyword) : true;
|
|
38
|
-
const leads = primaryKeyword ? keywordLeadsSlug(slug, primaryKeyword) : true;
|
|
39
|
-
const hasSecondary = secondaryKeyword ? containsKeywordTokens(slugAsWords, secondaryKeyword) : true;
|
|
40
|
-
|
|
41
|
-
if (primaryKeyword && !hasPrimary) {
|
|
42
|
-
const secNote = secondaryKeyword && !hasSecondary ? ` Your secondary keyword "${secondaryKeyword}" could follow it.` : "";
|
|
43
|
-
return {
|
|
44
|
-
label: "URL Slug",
|
|
45
|
-
value: `/${slug}`,
|
|
46
|
-
status: "warning",
|
|
47
|
-
recommendation: `Work your primary keyword "${primaryKeyword}" into the URL, ideally at the start - if the address gets shortened, a leading keyword still shows.${secNote} ${SHORT_DESC}`,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (primaryKeyword && hasPrimary && !leads) {
|
|
51
|
-
return {
|
|
52
|
-
label: "URL Slug",
|
|
53
|
-
value: `/${slug}`,
|
|
54
|
-
status: "warning",
|
|
55
|
-
recommendation: `Your primary keyword is in the URL but not at the start. Leading with it reads better and holds up if the address gets shortened. ${SHORT_DESC}`,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// Primary leads (or no primary set). Clean pass.
|
|
59
|
-
return { label: "URL Slug", value: `/${slug}`, status: "good" };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Caution block that lives INSIDE the URL Slug card. Changing an indexed page's
|
|
63
|
-
// slug without a 301 redirect drops its search rankings to zero and breaks every
|
|
64
|
-
// external link to the old URL - a warning (avoidable), not an error.
|
|
65
|
-
function SlugRedirectNotice() {
|
|
66
|
-
const [expanded, setExpanded] = useState(false);
|
|
67
|
-
return (
|
|
68
|
-
<div style={{ marginTop: 10, paddingTop: 10, borderTop: "1px solid rgba(0,0,0,0.07)" }}>
|
|
69
|
-
<div style={{ padding: "8px 10px", background: "rgba(245,158,11,0.08)", borderLeft: "2px solid #f59e0b", borderRadius: 6 }}>
|
|
70
|
-
<div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 4 }}>
|
|
71
|
-
<svg width="12" height="12" viewBox="0 0 20 20" fill="#f59e0b" aria-hidden="true">
|
|
72
|
-
<path fillRule="evenodd" d="M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 5a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 5zm0 9a1 1 0 100-2 1 1 0 000 2z" clipRule="evenodd" />
|
|
73
|
-
</svg>
|
|
74
|
-
<span style={{ fontSize: 10.5, fontWeight: 700, color: "#b45309", textTransform: "uppercase", letterSpacing: "0.06em" }}>
|
|
75
|
-
Changing a URL?
|
|
76
|
-
</span>
|
|
77
|
-
</div>
|
|
78
|
-
<div style={{ fontSize: 11, color: "#1f2937", lineHeight: 1.55 }}>
|
|
79
|
-
If the page has been published and indexed, you MUST add a 301 redirect from the old slug to the new one before changing it. For a brand-new page that's never been published, no redirect needed.
|
|
80
|
-
</div>
|
|
81
|
-
<button
|
|
82
|
-
onClick={() => setExpanded((v) => !v)}
|
|
83
|
-
style={{ display: "flex", alignItems: "center", gap: 3, marginTop: 6, padding: 0, background: "none", border: "none", cursor: "pointer", fontSize: 10.5, fontWeight: 700, color: "#b45309", fontFamily: "inherit" }}
|
|
84
|
-
>
|
|
85
|
-
{expanded ? "Show less" : "Learn more"}
|
|
86
|
-
<svg width="10" height="10" viewBox="0 0 20 20" fill="currentColor" style={{ transform: expanded ? "rotate(180deg)" : "none", transition: "transform 150ms" }}>
|
|
87
|
-
<path fillRule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clipRule="evenodd" />
|
|
88
|
-
</svg>
|
|
89
|
-
</button>
|
|
90
|
-
{expanded && (
|
|
91
|
-
<ul style={{ margin: "6px 0 0", paddingLeft: 16, fontSize: 11, color: "#1f2937", lineHeight: 1.55 }}>
|
|
92
|
-
<li>Without the 301, the page loses every search ranking and every external link to it breaks.</li>
|
|
93
|
-
<li>A 301 preserves the rankings and link equity built up on the old URL.</li>
|
|
94
|
-
<li>Set this up using vanity redirects in Sanity.</li>
|
|
95
|
-
</ul>
|
|
96
|
-
)}
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const cardStyle: React.CSSProperties = {
|
|
103
|
-
borderRadius: 14,
|
|
104
|
-
background: "rgba(255,255,255,0.55)",
|
|
105
|
-
backdropFilter: "blur(16px) saturate(170%)",
|
|
106
|
-
WebkitBackdropFilter: "blur(16px) saturate(170%)",
|
|
107
|
-
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)",
|
|
108
|
-
padding: "14px",
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
function StatusBadge({ status }: { status: TechnicalAuditItem["status"] }) {
|
|
112
|
-
const map = {
|
|
113
|
-
good: { bg: "rgba(22,163,74,0.12)", color: "#16a34a", label: "Good" },
|
|
114
|
-
warning: { bg: "rgba(230,192,27,0.18)", color: "#8B7310", label: "Review" },
|
|
115
|
-
error: { bg: "rgba(220,38,38,0.1)", color: "#dc2626", label: "Fix" },
|
|
116
|
-
} as const;
|
|
117
|
-
const c = map[status];
|
|
118
|
-
return (
|
|
119
|
-
<span
|
|
120
|
-
style={{
|
|
121
|
-
fontSize: 9,
|
|
122
|
-
fontWeight: 700,
|
|
123
|
-
textTransform: "uppercase",
|
|
124
|
-
letterSpacing: "0.05em",
|
|
125
|
-
padding: "2px 7px",
|
|
126
|
-
borderRadius: 99,
|
|
127
|
-
background: c.bg,
|
|
128
|
-
color: c.color,
|
|
129
|
-
flexShrink: 0,
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
132
|
-
{c.label}
|
|
133
|
-
</span>
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function AuditCard({
|
|
138
|
-
label,
|
|
139
|
-
value,
|
|
140
|
-
status,
|
|
141
|
-
recommendation,
|
|
142
|
-
anchorId,
|
|
143
|
-
footer,
|
|
144
|
-
}: {
|
|
145
|
-
label: string;
|
|
146
|
-
value: string;
|
|
147
|
-
status: TechnicalAuditItem["status"];
|
|
148
|
-
recommendation?: string;
|
|
149
|
-
anchorId?: string;
|
|
150
|
-
footer?: React.ReactNode;
|
|
151
|
-
}) {
|
|
152
|
-
return (
|
|
153
|
-
<div id={anchorId} style={cardStyle}>
|
|
154
|
-
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
|
|
155
|
-
<span style={{ fontSize: 10.5, textTransform: "uppercase", letterSpacing: "0.06em", color: "#4b5563", fontWeight: 600 }}>
|
|
156
|
-
{label}
|
|
157
|
-
</span>
|
|
158
|
-
<StatusBadge status={status} />
|
|
159
|
-
</div>
|
|
160
|
-
<div
|
|
161
|
-
style={{
|
|
162
|
-
fontSize: 12,
|
|
163
|
-
color: status === "error" ? "#9ca3af" : "#374151",
|
|
164
|
-
lineHeight: 1.5,
|
|
165
|
-
fontStyle: status === "error" ? "italic" : "normal",
|
|
166
|
-
wordBreak: "break-word",
|
|
167
|
-
}}
|
|
168
|
-
>
|
|
169
|
-
{value}
|
|
170
|
-
</div>
|
|
171
|
-
{recommendation && (
|
|
172
|
-
<div
|
|
173
|
-
style={{
|
|
174
|
-
marginTop: 8,
|
|
175
|
-
padding: "6px 10px",
|
|
176
|
-
background: status === "error" ? "rgba(220,38,38,0.04)" : "rgba(230,192,27,0.06)",
|
|
177
|
-
borderLeft: `2px solid ${status === "error" ? "#dc2626" : "#E6C01B"}`,
|
|
178
|
-
borderRadius: 6,
|
|
179
|
-
fontSize: 11,
|
|
180
|
-
color: "#1f2937",
|
|
181
|
-
lineHeight: 1.5,
|
|
182
|
-
}}
|
|
183
|
-
>
|
|
184
|
-
{recommendation}
|
|
185
|
-
</div>
|
|
186
|
-
)}
|
|
187
|
-
{footer}
|
|
188
|
-
</div>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const IMAGE_EXT_RE = /\.(jpe?g|png|gif|webp|svg|tiff?|bmp)$/i;
|
|
193
|
-
const GENERIC_FILENAME_RE = /^(IMG_|DSC|DCIM|screenshot|photo\d*|image\d*|untitled|file_?\d+|unsplash|stock)/i;
|
|
194
|
-
|
|
195
|
-
// Split the mixed imageNames array into filename strings (have a file extension)
|
|
196
|
-
// and alt-text strings (everything else). Lets us run targeted audits on each.
|
|
197
|
-
function classifyImageNames(names: string[]): { filenames: string[]; altTexts: string[] } {
|
|
198
|
-
const filenames: string[] = [];
|
|
199
|
-
const altTexts: string[] = [];
|
|
200
|
-
for (const n of names) {
|
|
201
|
-
if (IMAGE_EXT_RE.test(n)) filenames.push(n);
|
|
202
|
-
else altTexts.push(n);
|
|
203
|
-
}
|
|
204
|
-
return { filenames, altTexts };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Filename audit. Director's ask: 2-3 hyphenated keywords, ideally including the
|
|
208
|
-
// primary keyword; no underscores or special characters. Returns null when no
|
|
209
|
-
// filenames are present (often the case since asset filenames only flow through
|
|
210
|
-
// when the asset is pre-expanded in the document pane).
|
|
211
|
-
function imageFilenameAudit(filenames: string[]): TechnicalAuditItem | null {
|
|
212
|
-
if (filenames.length === 0) return null;
|
|
213
|
-
const issues: { filename: string; reason: string }[] = [];
|
|
214
|
-
for (const f of filenames) {
|
|
215
|
-
const base = f.replace(IMAGE_EXT_RE, "");
|
|
216
|
-
if (GENERIC_FILENAME_RE.test(base)) {
|
|
217
|
-
issues.push({ filename: f, reason: "generic name from a camera or screenshot tool" });
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (/_/.test(base)) {
|
|
221
|
-
issues.push({ filename: f, reason: "uses underscores instead of hyphens" });
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
if (/\s/.test(base)) {
|
|
225
|
-
issues.push({ filename: f, reason: "contains spaces (use hyphens)" });
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
const words = base.split("-").filter(Boolean);
|
|
229
|
-
if (words.length < 2) {
|
|
230
|
-
issues.push({ filename: f, reason: "single word - use 2-3 descriptive hyphenated words" });
|
|
231
|
-
} else if (words.length > 5) {
|
|
232
|
-
issues.push({ filename: f, reason: "too many words - keep to 3-5" });
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (issues.length === 0) {
|
|
236
|
-
return {
|
|
237
|
-
label: "Image Filenames",
|
|
238
|
-
value: `${filenames.length} filename${filenames.length === 1 ? "" : "s"} look descriptive`,
|
|
239
|
-
status: "good",
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
const examples = issues.slice(0, 2).map((i) => `"${i.filename}" - ${i.reason}`).join("; ");
|
|
243
|
-
return {
|
|
244
|
-
label: "Image Filenames",
|
|
245
|
-
value: `${issues.length} of ${filenames.length} filename${filenames.length === 1 ? "" : "s"} need attention`,
|
|
246
|
-
status: "warning",
|
|
247
|
-
recommendation: `${examples}. Use 2-3 hyphenated descriptive words, ideally including the primary keyword.`,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Alt-text audit. Per director guidance, alt text should be roughly 2-5
|
|
252
|
-
// descriptive keywords - so we only flag the genuinely bad cases: a single bare
|
|
253
|
-
// word (not descriptive) or text so long Google would truncate it / it reads as
|
|
254
|
-
// keyword stuffing (>125 chars). Empty alt is intentional for decorative images
|
|
255
|
-
// and not flagged.
|
|
256
|
-
function imageAltTextAudit(altTexts: string[]): TechnicalAuditItem | null {
|
|
257
|
-
if (altTexts.length === 0) return null;
|
|
258
|
-
const issues: { alt: string; reason: string }[] = [];
|
|
259
|
-
let audited = 0; // non-empty alt texts we actually evaluate (blank = decorative, skipped)
|
|
260
|
-
for (const alt of altTexts) {
|
|
261
|
-
const trimmed = alt.trim();
|
|
262
|
-
if (!trimmed) continue; // empty alt is intentional - skip
|
|
263
|
-
audited++;
|
|
264
|
-
const len = trimmed.length;
|
|
265
|
-
const wc = trimmed.split(/\s+/).filter(Boolean).length;
|
|
266
|
-
if (len >= 125) {
|
|
267
|
-
issues.push({ alt: trimmed, reason: `${len} chars - shorten to under 125` });
|
|
268
|
-
} else if (wc < 2) {
|
|
269
|
-
issues.push({ alt: trimmed, reason: "just one word - use 2-5 descriptive keywords" });
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// Every image had an intentionally-empty (decorative) alt - nothing to audit.
|
|
273
|
-
if (audited === 0) return null;
|
|
274
|
-
if (issues.length === 0) {
|
|
275
|
-
return {
|
|
276
|
-
label: "Image Alt Text",
|
|
277
|
-
value: `${audited} alt text${audited === 1 ? "" : "s"} look well-formed`,
|
|
278
|
-
status: "good",
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
const examples = issues.slice(0, 2).map((i) => {
|
|
282
|
-
const short = i.alt.length > 50 ? `${i.alt.slice(0, 50)}...` : i.alt;
|
|
283
|
-
return `"${short}" - ${i.reason}`;
|
|
284
|
-
}).join("; ");
|
|
285
|
-
return {
|
|
286
|
-
label: "Image Alt Text",
|
|
287
|
-
value: `${issues.length} of ${audited} alt text${audited === 1 ? "" : "s"} need attention`,
|
|
288
|
-
status: "warning",
|
|
289
|
-
recommendation: `${examples}. Alt text should be 2-5 descriptive keywords that describe the image, ideally including the primary keyword, and stay under 125 characters.`,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Image title audit. Per the director, the title attribute (the tooltip shown on
|
|
294
|
-
// hover) sends an SEO signal, so each image should carry a short descriptive title.
|
|
295
|
-
// Flags images with no title, and titles that are a single bare word.
|
|
296
|
-
//
|
|
297
|
-
// MJH's image schemas (mainImage, figure) do not have a `title` field at all -
|
|
298
|
-
// only `alt`, `caption`, and `link`. When NONE of the document's images have a
|
|
299
|
-
// title, we treat that as "schema doesn't support titles" and skip the audit
|
|
300
|
-
// silently rather than flagging every image as missing a field the editor
|
|
301
|
-
// has no way to fill in. The director's intent (catch editors who set title
|
|
302
|
-
// on some images but not others) is preserved.
|
|
303
|
-
function imageTitleAudit(titles: string[], imageCount: number): TechnicalAuditItem | null {
|
|
304
|
-
if (imageCount <= 0) return null;
|
|
305
|
-
const withTitle = titles.length;
|
|
306
|
-
if (withTitle === 0) return null; // schema doesn't expose a title field - skip
|
|
307
|
-
const missing = imageCount - withTitle;
|
|
308
|
-
if (missing > 0) {
|
|
309
|
-
return {
|
|
310
|
-
label: "Image Titles",
|
|
311
|
-
value: `${withTitle} of ${imageCount} image${imageCount === 1 ? "" : "s"} ${withTitle === 1 ? "has" : "have"} a title`,
|
|
312
|
-
status: "warning",
|
|
313
|
-
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.`,
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
const sparse = titles.filter((t) => t.trim().split(/\s+/).filter(Boolean).length < 2);
|
|
317
|
-
if (sparse.length > 0) {
|
|
318
|
-
return {
|
|
319
|
-
label: "Image Titles",
|
|
320
|
-
value: `${sparse.length} image title${sparse.length === 1 ? "" : "s"} ${sparse.length === 1 ? "is" : "are"} a single word`,
|
|
321
|
-
status: "warning",
|
|
322
|
-
recommendation: "Use 2-5 descriptive keywords in each image title, not a single word.",
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
label: "Image Titles",
|
|
327
|
-
value: `All ${imageCount} image${imageCount === 1 ? "" : "s"} have a descriptive title`,
|
|
328
|
-
status: "good",
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Audits the body's heading structure: density (H2s per word count), heading-level
|
|
333
|
-
// skips, empty heading blocks, and whether a target keyword appears in a subheading.
|
|
334
|
-
function computeHeadingStructureAudits(
|
|
335
|
-
headings: HeadingItem[],
|
|
336
|
-
wordCount: number,
|
|
337
|
-
primaryKeyword?: string,
|
|
338
|
-
secondaryKeyword?: string,
|
|
339
|
-
unstyledHeadings?: string[]
|
|
340
|
-
): TechnicalAuditItem[] {
|
|
341
|
-
const audits: TechnicalAuditItem[] = [];
|
|
342
|
-
// Count H2 AND H3 as section headings: an article sectioned only with H3s is
|
|
343
|
-
// still sectioned, so it shouldn't be told it has "no section headings".
|
|
344
|
-
const sectionCount = headings.filter((h) => h.level === 2 || h.level === 3).length;
|
|
345
|
-
|
|
346
|
-
// Heading-density check. Thresholds backed by SEO best-practice research:
|
|
347
|
-
// > 2,500 words really wants 1 H2 per ~400 words; 1,500+ usually needs 3+;
|
|
348
|
-
// 1,000+ without any H2 is unreadable. Below 1,000 words structure isn't
|
|
349
|
-
// critical so we don't flag it as a density issue.
|
|
350
|
-
// Order matters: the zero-H2 case is an error and must be checked before the
|
|
351
|
-
// softer density warnings, so a long article with no headings reports "error"
|
|
352
|
-
// (matching summary.ts) rather than falling into a lower-severity branch.
|
|
353
|
-
let densityFired = false;
|
|
354
|
-
if (wordCount >= 1000 && sectionCount === 0) {
|
|
355
|
-
audits.push({
|
|
356
|
-
label: "Section Headings",
|
|
357
|
-
value: `No section headings in a ${wordCount}-word article`,
|
|
358
|
-
status: "error",
|
|
359
|
-
recommendation: "Articles this long need section headings. Add 2-3 H2 (or H3) headings to break the body into scannable sections.",
|
|
360
|
-
});
|
|
361
|
-
densityFired = true;
|
|
362
|
-
} else if (wordCount >= 2500 && sectionCount < 5) {
|
|
363
|
-
audits.push({
|
|
364
|
-
label: "Section Headings",
|
|
365
|
-
value: `${sectionCount} section heading${sectionCount === 1 ? "" : "s"} for a ${wordCount}-word article`,
|
|
366
|
-
status: "warning",
|
|
367
|
-
recommendation: "Long articles read best with 1 section heading per 300-400 words. Break the content into more named sections so readers and search engines can navigate it.",
|
|
368
|
-
});
|
|
369
|
-
densityFired = true;
|
|
370
|
-
} else if (wordCount >= 1500 && sectionCount < 3) {
|
|
371
|
-
audits.push({
|
|
372
|
-
label: "Section Headings",
|
|
373
|
-
value: `${sectionCount} section heading${sectionCount === 1 ? "" : "s"} for a ${wordCount}-word article`,
|
|
374
|
-
status: "warning",
|
|
375
|
-
recommendation: "Articles above 1,500 words usually need at least 3 named sections. Add section breaks so the outline is scannable.",
|
|
376
|
-
});
|
|
377
|
-
densityFired = true;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Lines that look like section headings but were typed as plain text (not styled as H2).
|
|
381
|
-
// Surfaced before the no-headings early-return so it fires exactly when it's most useful.
|
|
382
|
-
if (unstyledHeadings && unstyledHeadings.length > 0) {
|
|
383
|
-
const n = unstyledHeadings.length;
|
|
384
|
-
const examples = unstyledHeadings.slice(0, 2).map((t) => `"${t}"`).join(", ");
|
|
385
|
-
audits.push({
|
|
386
|
-
label: "Looks Like a Heading",
|
|
387
|
-
value: `${n} line${n === 1 ? "" : "s"} read${n === 1 ? "s" : ""} like a heading but ${n === 1 ? "isn't" : "aren't"} styled`,
|
|
388
|
-
status: "warning",
|
|
389
|
-
recommendation: `${examples}${n > 2 ? ", and more," : ""} ${n === 1 ? "looks" : "look"} like a section heading typed as plain text. In Sanity, select the line and apply the "Heading 2" style so it counts as a real heading.`,
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// If the body has no headings at all and density didn't already flag it (short article),
|
|
394
|
-
// surface a generic structure note so the editor still sees a hint.
|
|
395
|
-
if (headings.length === 0) {
|
|
396
|
-
if (!densityFired) {
|
|
397
|
-
audits.push({
|
|
398
|
-
label: "Heading Structure",
|
|
399
|
-
value: "No headings in body",
|
|
400
|
-
status: "warning",
|
|
401
|
-
recommendation: "Consider adding H2-H6 subheadings to structure the article into scannable sections.",
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
return audits;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// (No "H1 in body" warning. The article title IS the page H1, and the Heading Outline
|
|
408
|
-
// below now shows it explicitly - so a stray body H1 is displayed there, not scolded.)
|
|
409
|
-
|
|
410
|
-
// Skipped levels (e.g. H2 followed by H4 with no H3 between them).
|
|
411
|
-
let prevLevel = 0;
|
|
412
|
-
const skips: { from: number; to: number; at: string }[] = [];
|
|
413
|
-
for (const h of headings) {
|
|
414
|
-
if (prevLevel > 0 && h.level > prevLevel + 1) {
|
|
415
|
-
skips.push({ from: prevLevel, to: h.level, at: h.text || "(empty)" });
|
|
416
|
-
}
|
|
417
|
-
prevLevel = h.level;
|
|
418
|
-
}
|
|
419
|
-
if (skips.length > 0) {
|
|
420
|
-
const first = skips[0];
|
|
421
|
-
audits.push({
|
|
422
|
-
label: "Heading Hierarchy",
|
|
423
|
-
value: `${skips.length} skipped level${skips.length === 1 ? "" : "s"}`,
|
|
424
|
-
status: "warning",
|
|
425
|
-
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.`,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Empty heading blocks.
|
|
430
|
-
const empties = headings.filter((h) => !h.text.trim());
|
|
431
|
-
if (empties.length > 0) {
|
|
432
|
-
audits.push({
|
|
433
|
-
label: "Empty Headings",
|
|
434
|
-
value: `${empties.length} empty heading${empties.length === 1 ? "" : "s"}`,
|
|
435
|
-
status: "error",
|
|
436
|
-
recommendation: "Either remove the empty heading blocks or fill them with text. Empty headings confuse the outline.",
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// Clean structural bill of health (density + hierarchy + empties all passed).
|
|
441
|
-
if (audits.length === 0) {
|
|
442
|
-
audits.push({
|
|
443
|
-
label: "Heading Structure",
|
|
444
|
-
value: `${headings.length} heading${headings.length === 1 ? "" : "s"}, hierarchy is clean`,
|
|
445
|
-
status: "good",
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Keyword-in-headings nudge (separate from structural health). Reinforce relevance by
|
|
450
|
-
// working the primary and/or secondary keyword into at least one subheading. Only fires
|
|
451
|
-
// when subheadings actually exist - otherwise the "no headings" / density notes cover it.
|
|
452
|
-
const subheads = headings.filter((h) => h.level >= 2);
|
|
453
|
-
const subheadingText = subheads.map((h) => h.text).join(" ");
|
|
454
|
-
const hasPrimaryInHeads = primaryKeyword ? containsKeywordTokens(subheadingText, primaryKeyword) : false;
|
|
455
|
-
const hasSecondaryInHeads = secondaryKeyword ? containsKeywordTokens(subheadingText, secondaryKeyword) : false;
|
|
456
|
-
if (subheads.length > 0 && (primaryKeyword || secondaryKeyword) && !hasPrimaryInHeads && !hasSecondaryInHeads) {
|
|
457
|
-
const kw = [
|
|
458
|
-
primaryKeyword ? `primary keyword "${primaryKeyword}"` : "",
|
|
459
|
-
secondaryKeyword ? `secondary keyword "${secondaryKeyword}"` : "",
|
|
460
|
-
].filter(Boolean).join(" or ");
|
|
461
|
-
audits.push({
|
|
462
|
-
label: "Keywords in Headings",
|
|
463
|
-
value: "No subheading uses your target keyword",
|
|
464
|
-
status: "warning",
|
|
465
|
-
recommendation: `Work your ${kw} into at least one H2 or H3. Keywords in headers reinforce relevance for readers and search engines.`,
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return audits;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Small health badge for a checked URL (OK / 301 / 404 / BLOCKED ...).
|
|
473
|
-
function HealthBadge({ result }: { result: LinkCheckResult }) {
|
|
474
|
-
const map = {
|
|
475
|
-
ok: { color: "#16a34a", label: "OK" },
|
|
476
|
-
redirect: { color: "#8B7310", label: result.status > 0 ? String(result.status) : "REDIR" },
|
|
477
|
-
broken: { color: "#dc2626", label: result.status > 0 ? String(result.status) : "404" },
|
|
478
|
-
unverified: { color: "#b45309", label: result.status > 0 ? String(result.status) : "BLOCKED" },
|
|
479
|
-
error: { color: "#dc2626", label: "ERR" },
|
|
480
|
-
} as const;
|
|
481
|
-
const c = map[result.category];
|
|
482
|
-
return (
|
|
483
|
-
<span style={{ fontSize: 9, fontWeight: 700, letterSpacing: "0.04em", padding: "2px 6px", borderRadius: 99, background: "#ffffff", color: c.color, fontVariantNumeric: "tabular-nums", flexShrink: 0, marginTop: 1 }}>
|
|
484
|
-
{c.label}
|
|
485
|
-
</span>
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function LinkCheckCard({
|
|
490
|
-
urls,
|
|
491
|
-
linksDetailed,
|
|
492
|
-
results,
|
|
493
|
-
isLoading,
|
|
494
|
-
error,
|
|
495
|
-
hasRun,
|
|
496
|
-
onCheck,
|
|
497
|
-
}: {
|
|
498
|
-
urls: string[];
|
|
499
|
-
linksDetailed?: { url: string; hyperlinked: boolean; anchorText?: string }[];
|
|
500
|
-
results: LinkCheckResult[];
|
|
501
|
-
isLoading: boolean;
|
|
502
|
-
error: string | null;
|
|
503
|
-
hasRun: boolean;
|
|
504
|
-
onCheck: () => void;
|
|
505
|
-
}) {
|
|
506
|
-
// Which tile's link list is expanded.
|
|
507
|
-
const [openBucket, setOpenBucket] = useState<string | null>(null);
|
|
508
|
-
|
|
509
|
-
// Whether we can distinguish real hyperlinks from plain-text URLs (Portable Text only).
|
|
510
|
-
const haveTypes = !!linksDetailed;
|
|
511
|
-
const detailByUrl = useMemo(
|
|
512
|
-
() => new Map((linksDetailed || []).map((d) => [d.url, d])),
|
|
513
|
-
[linksDetailed]
|
|
514
|
-
);
|
|
515
|
-
const resultByUrl = useMemo(() => new Map(results.map((r) => [r.url, r])), [results]);
|
|
516
|
-
|
|
517
|
-
// Build the tiles. Hyperlink-type tiles are available immediately; health tiles appear
|
|
518
|
-
// after the broken-link check runs. Each tile is clickable to reveal its links.
|
|
519
|
-
// Two independent axes, shown as paired tiles so a 2-column grid stacks opposites:
|
|
520
|
-
// - Whether a URL is a real link: "Linked" (top) vs "Not linked" (bottom, RED = needs fixing)
|
|
521
|
-
// - Whether the link works: "Working" (top) vs "Broken" (bottom) [after the check]
|
|
522
|
-
// "Working" includes redirects (they still resolve - the 301 shows on the link's badge), so
|
|
523
|
-
// we don't surface the jargon word "redirect" as its own count. Order is interleaved
|
|
524
|
-
// (Working, Linked, Broken, Not linked) so the grid renders Working/Broken in the left
|
|
525
|
-
// column and Linked/Not-linked in the right column.
|
|
526
|
-
const blockedUrls = results.filter((r) => r.category === "unverified").map((r) => r.url);
|
|
527
|
-
const tiles = useMemo(() => {
|
|
528
|
-
const hyper = (linksDetailed || []).filter((l) => l.hyperlinked).map((l) => l.url);
|
|
529
|
-
const plain = (linksDetailed || []).filter((l) => !l.hyperlinked).map((l) => l.url);
|
|
530
|
-
const working = results.filter((r) => r.category === "ok" || r.category === "redirect").map((r) => r.url);
|
|
531
|
-
const broken = results.filter((r) => r.category === "broken" || r.category === "error").map((r) => r.url);
|
|
532
|
-
const t: { key: string; label: string; color: string; urls: string[]; note?: string }[] = [];
|
|
533
|
-
if (hasRun) t.push({ key: "working", label: "Working", color: "#16a34a", urls: working });
|
|
534
|
-
if (haveTypes) t.push({ key: "linked", label: "Linked", color: "#16a34a", urls: hyper });
|
|
535
|
-
if (hasRun) t.push({ key: "broken", label: "Broken", color: "#dc2626", urls: broken });
|
|
536
|
-
if (haveTypes) t.push({ key: "notlinked", label: "Not linked", color: "#dc2626", urls: plain, note: "Not links yet - hyperlink these so readers can click them and search engines can follow them." });
|
|
537
|
-
return t;
|
|
538
|
-
}, [haveTypes, linksDetailed, hasRun, results]);
|
|
539
|
-
|
|
540
|
-
const open = tiles.find((t) => t.key === openBucket) || null;
|
|
541
|
-
|
|
542
|
-
const renderLinkRow = (url: string) => {
|
|
543
|
-
const d = detailByUrl.get(url);
|
|
544
|
-
const r = resultByUrl.get(url);
|
|
545
|
-
return (
|
|
546
|
-
<a
|
|
547
|
-
key={url}
|
|
548
|
-
href={url}
|
|
549
|
-
target="_blank"
|
|
550
|
-
rel="noopener noreferrer"
|
|
551
|
-
style={{ display: "flex", gap: 8, alignItems: "flex-start", padding: "6px 8px", background: "rgba(0,0,0,0.025)", borderRadius: 6, textDecoration: "none", marginTop: 4 }}
|
|
552
|
-
>
|
|
553
|
-
{r && <HealthBadge result={r} />}
|
|
554
|
-
<div style={{ minWidth: 0, flex: 1 }}>
|
|
555
|
-
{d?.anchorText && (
|
|
556
|
-
<div style={{ fontSize: 11, color: "#1f2937", fontWeight: 600, lineHeight: 1.3, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
|
|
557
|
-
“{d.anchorText}”
|
|
558
|
-
</div>
|
|
559
|
-
)}
|
|
560
|
-
<div style={{ fontSize: 10, color: "#4b5563", fontFamily: "ui-monospace, SFMono-Regular, monospace", wordBreak: "break-all", lineHeight: 1.35 }}>
|
|
561
|
-
{url}
|
|
562
|
-
</div>
|
|
563
|
-
</div>
|
|
564
|
-
</a>
|
|
565
|
-
);
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
return (
|
|
569
|
-
<div id="anchor-link-check" style={cardStyle}>
|
|
570
|
-
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
|
|
571
|
-
<span style={{ fontSize: 10.5, textTransform: "uppercase", letterSpacing: "0.06em", color: "#4b5563", fontWeight: 600 }}>
|
|
572
|
-
Link Health
|
|
573
|
-
</span>
|
|
574
|
-
{hasRun && !isLoading && (
|
|
575
|
-
<button onClick={onCheck} style={{ background: "none", border: "none", fontSize: 10, fontWeight: 600, color: MJH_BLUE, cursor: "pointer", padding: "2px 4px" }} title="Run again">
|
|
576
|
-
Re-check
|
|
577
|
-
</button>
|
|
578
|
-
)}
|
|
579
|
-
</div>
|
|
580
|
-
|
|
581
|
-
{urls.length === 0 ? (
|
|
582
|
-
<div style={{ fontSize: 11, color: "#4b5563", lineHeight: 1.5 }}>No links found in the body.</div>
|
|
583
|
-
) : (
|
|
584
|
-
<>
|
|
585
|
-
<div style={{ fontSize: 11, color: "#4b5563", lineHeight: 1.5, marginBottom: 10 }}>
|
|
586
|
-
{urls.length} link{urls.length === 1 ? "" : "s"} in the body.{tiles.length > 0 ? " Tap a box to see which." : ""}
|
|
587
|
-
</div>
|
|
588
|
-
|
|
589
|
-
{/* Clickable count tiles - 2 columns so opposites stack (Working/Broken on the
|
|
590
|
-
left, Linked/Not-linked on the right). Each opens a list of its links below. */}
|
|
591
|
-
{tiles.length > 0 && (
|
|
592
|
-
<div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 6 }}>
|
|
593
|
-
{tiles.map((t) => {
|
|
594
|
-
const empty = t.urls.length === 0;
|
|
595
|
-
const active = openBucket === t.key && !empty;
|
|
596
|
-
return (
|
|
597
|
-
<button
|
|
598
|
-
key={t.key}
|
|
599
|
-
type="button"
|
|
600
|
-
onClick={() => !empty && setOpenBucket(active ? null : t.key)}
|
|
601
|
-
aria-expanded={active}
|
|
602
|
-
aria-label={`${t.urls.length} ${t.label} links`}
|
|
603
|
-
style={{
|
|
604
|
-
padding: "8px 4px",
|
|
605
|
-
background: active ? "rgba(0,93,172,0.08)" : "rgba(0,0,0,0.025)",
|
|
606
|
-
border: active ? `1px solid ${MJH_BLUE}55` : "1px solid transparent",
|
|
607
|
-
borderRadius: 8,
|
|
608
|
-
textAlign: "center",
|
|
609
|
-
cursor: empty ? "default" : "pointer",
|
|
610
|
-
opacity: empty ? 0.5 : 1,
|
|
611
|
-
}}
|
|
612
|
-
>
|
|
613
|
-
<div style={{ fontSize: 18, fontWeight: 700, color: t.color, fontVariantNumeric: "tabular-nums", lineHeight: 1 }}>{t.urls.length}</div>
|
|
614
|
-
<div style={{ fontSize: 9, fontWeight: 700, color: "#4b5563", textTransform: "uppercase", letterSpacing: "0.05em", marginTop: 4 }}>{t.label}</div>
|
|
615
|
-
</button>
|
|
616
|
-
);
|
|
617
|
-
})}
|
|
618
|
-
</div>
|
|
619
|
-
)}
|
|
620
|
-
|
|
621
|
-
{/* Expanded link list for the selected tile. */}
|
|
622
|
-
{open && open.urls.length > 0 && (
|
|
623
|
-
<div style={{ marginTop: 8 }}>
|
|
624
|
-
{open.note && (
|
|
625
|
-
<div style={{ fontSize: 10.5, color: "#92400e", background: "rgba(245,158,11,0.08)", border: "1px solid rgba(245,158,11,0.25)", borderRadius: 6, padding: "6px 9px", lineHeight: 1.45, marginBottom: 2 }}>
|
|
626
|
-
{open.note}
|
|
627
|
-
</div>
|
|
628
|
-
)}
|
|
629
|
-
{open.urls.map(renderLinkRow)}
|
|
630
|
-
</div>
|
|
631
|
-
)}
|
|
632
|
-
|
|
633
|
-
{/* Links we couldn't auto-check (anti-bot walls) - not counted working or broken. */}
|
|
634
|
-
{hasRun && blockedUrls.length > 0 && (
|
|
635
|
-
<div style={{ marginTop: 8, padding: "6px 10px", background: "rgba(245,158,11,0.08)", border: "1px solid rgba(245,158,11,0.25)", borderRadius: 6, fontSize: 10.5, color: "#92400e", lineHeight: 1.45 }}>
|
|
636
|
-
{blockedUrls.length} link{blockedUrls.length === 1 ? "" : "s"} couldn't be auto-checked (the destination blocks our checker) - open them to confirm.
|
|
637
|
-
</div>
|
|
638
|
-
)}
|
|
639
|
-
|
|
640
|
-
{/* Check button (pre-run). */}
|
|
641
|
-
{!hasRun && !isLoading && (
|
|
642
|
-
<button
|
|
643
|
-
onClick={onCheck}
|
|
644
|
-
style={{ width: "100%", marginTop: 10, padding: "8px 12px", fontSize: 11, fontWeight: 700, color: "#1f2937", background: MJH_GOLD, border: "none", borderRadius: 6, cursor: "pointer", letterSpacing: "0.01em" }}
|
|
645
|
-
>
|
|
646
|
-
Check {urls.length} link{urls.length === 1 ? "" : "s"} for broken / redirects
|
|
647
|
-
</button>
|
|
648
|
-
)}
|
|
649
|
-
|
|
650
|
-
{isLoading && (
|
|
651
|
-
<div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 8, padding: "16px 0" }}>
|
|
652
|
-
<LoadingBars size="xs" color={MJH_BLUE} />
|
|
653
|
-
<span style={{ fontSize: 11, color: "#4b5563" }}>Checking {urls.length} link{urls.length === 1 ? "" : "s"}...</span>
|
|
654
|
-
</div>
|
|
655
|
-
)}
|
|
656
|
-
|
|
657
|
-
{error && !isLoading && (
|
|
658
|
-
<div style={{ marginTop: 10, padding: "10px 12px", background: "rgba(220,38,38,0.04)", border: "1px solid rgba(220,38,38,0.18)", borderRadius: 8, fontSize: 11, color: "#b91c1c", lineHeight: 1.5 }}>
|
|
659
|
-
{error}
|
|
660
|
-
<button onClick={onCheck} style={{ display: "block", marginTop: 6, padding: "4px 10px", fontSize: 11, fontWeight: 700, color: "#ffffff", background: "#dc2626", border: "none", borderRadius: 5, cursor: "pointer" }}>
|
|
661
|
-
Try again
|
|
662
|
-
</button>
|
|
663
|
-
</div>
|
|
664
|
-
)}
|
|
665
|
-
</>
|
|
666
|
-
)}
|
|
667
|
-
</div>
|
|
668
|
-
);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
export function TechnicalTab({
|
|
672
|
-
text,
|
|
673
|
-
documentFields,
|
|
674
|
-
primaryKeyword,
|
|
675
|
-
secondaryKeyword,
|
|
676
|
-
isLoading,
|
|
677
|
-
linkCheckResults,
|
|
678
|
-
isLinkCheckLoading,
|
|
679
|
-
linkCheckError,
|
|
680
|
-
hasRunLinkCheck,
|
|
681
|
-
onCheckLinks,
|
|
682
|
-
}: TechnicalTabProps) {
|
|
683
|
-
const urlSlugAudit = useMemo(
|
|
684
|
-
() => urlAudit(documentFields?.slug, primaryKeyword, secondaryKeyword),
|
|
685
|
-
[documentFields?.slug, primaryKeyword, secondaryKeyword]
|
|
686
|
-
);
|
|
687
|
-
const headings = documentFields?.headings || [];
|
|
688
|
-
const headingsDetailed = documentFields?.headingsDetailed;
|
|
689
|
-
// Fall back gracefully if a host (e.g. older Notebook builds) doesn't supply heading
|
|
690
|
-
// levels - we still get the count audit from the flat string list.
|
|
691
|
-
const headingsForStructure: HeadingItem[] = useMemo(
|
|
692
|
-
() => headingsDetailed
|
|
693
|
-
? headingsDetailed
|
|
694
|
-
: headings.map((text) => ({ text, level: 2 })),
|
|
695
|
-
[headingsDetailed, headings]
|
|
696
|
-
);
|
|
697
|
-
|
|
698
|
-
// Word count drives both the dedicated Word Count audit and the heading-density check.
|
|
699
|
-
const wordCount = text ? text.split(/\s+/).filter(Boolean).length : 0;
|
|
700
|
-
|
|
701
|
-
const structureAudits = useMemo(
|
|
702
|
-
() => computeHeadingStructureAudits(headingsForStructure, wordCount, primaryKeyword, secondaryKeyword, documentFields?.unstyledHeadings),
|
|
703
|
-
[headingsForStructure, wordCount, primaryKeyword, secondaryKeyword, documentFields?.unstyledHeadings]
|
|
704
|
-
);
|
|
705
|
-
|
|
706
|
-
const imageNames = documentFields?.imageNames || [];
|
|
707
|
-
// imageNames is a mixed list: when an image field has an `alt` prop, that
|
|
708
|
-
// string is pushed; when the asset's `originalFilename` is available, it gets
|
|
709
|
-
// pushed too. We classify by file extension to give targeted feedback on each.
|
|
710
|
-
const { filenames: imageFilenames, altTexts: imageAltTexts } = useMemo(
|
|
711
|
-
() => classifyImageNames(imageNames),
|
|
712
|
-
[imageNames]
|
|
713
|
-
);
|
|
714
|
-
const filenameAudit = useMemo(
|
|
715
|
-
() => imageFilenameAudit(imageFilenames),
|
|
716
|
-
[imageFilenames]
|
|
717
|
-
);
|
|
718
|
-
const altTextAudit = useMemo(
|
|
719
|
-
() => imageAltTextAudit(imageAltTexts),
|
|
720
|
-
[imageAltTexts]
|
|
721
|
-
);
|
|
722
|
-
const imageTitles = documentFields?.imageTitles || [];
|
|
723
|
-
const imageCount = documentFields?.imageCount ?? 0;
|
|
724
|
-
const imgTitleAudit = useMemo(
|
|
725
|
-
() => imageTitleAudit(imageTitles, imageCount),
|
|
726
|
-
[imageTitles, imageCount]
|
|
727
|
-
);
|
|
728
|
-
// "No images" only when neither a count nor any alt/filename entry exists.
|
|
729
|
-
const hasImages = imageCount > 0 || imageNames.length > 0;
|
|
730
|
-
const imagesAudit: TechnicalAuditItem | null = !hasImages
|
|
731
|
-
? {
|
|
732
|
-
label: "Images",
|
|
733
|
-
value: "No images detected",
|
|
734
|
-
status: "warning",
|
|
735
|
-
recommendation: "Add at least one hero image with descriptive alt text. Articles with images perform better on both reader engagement and search.",
|
|
736
|
-
}
|
|
737
|
-
: null;
|
|
738
|
-
|
|
739
|
-
// 450 is the body-text floor. 1,500+ is the competitive target for HCP clinical content.
|
|
740
|
-
// An empty body is not an error to "Fix" - the editor simply hasn't written yet
|
|
741
|
-
// (or the body hasn't loaded). Mirror summary.ts and show no card rather than a red
|
|
742
|
-
// alarm; the Word Count card appears once there's real text to measure.
|
|
743
|
-
// Videos / podcasts / news / briefs are legitimately short (body text summarizes
|
|
744
|
-
// the media, it isn't the deliverable), so they're exempt from the word-count floor.
|
|
745
|
-
const isShortForm = isShortFormContent(documentFields, documentFields?.title);
|
|
746
|
-
const wordAudit: TechnicalAuditItem | null =
|
|
747
|
-
wordCount === 0
|
|
748
|
-
? null
|
|
749
|
-
: isShortForm
|
|
750
|
-
? { label: "Word Count", value: `${wordCount} words`, status: "good" }
|
|
751
|
-
: wordCount < 450
|
|
752
|
-
? {
|
|
753
|
-
label: "Word Count",
|
|
754
|
-
value: `${wordCount} words`,
|
|
755
|
-
status: "error",
|
|
756
|
-
recommendation: "Body copy should be at least 450 words. Add more written content.",
|
|
757
|
-
}
|
|
758
|
-
: wordCount < 1500
|
|
759
|
-
? {
|
|
760
|
-
label: "Word Count",
|
|
761
|
-
value: `${wordCount} words`,
|
|
762
|
-
status: "warning",
|
|
763
|
-
recommendation: "Above the 450-word floor. For competitive clinical content, push past 1,500 words.",
|
|
764
|
-
}
|
|
765
|
-
: { label: "Word Count", value: `${wordCount} words`, status: "good" };
|
|
766
|
-
|
|
767
|
-
const bodyLinks = documentFields?.bodyLinks || [];
|
|
768
|
-
const bodyLinksDetailed = documentFields?.bodyLinksDetailed;
|
|
769
|
-
|
|
770
|
-
// Show a loading placeholder while document fields are still loading and we don't
|
|
771
|
-
// have anything yet (avoids a flash of "Missing" cards from prior doc state).
|
|
772
|
-
const hasAnyField =
|
|
773
|
-
!!documentFields &&
|
|
774
|
-
(documentFields.title !== undefined ||
|
|
775
|
-
(documentFields.headings && documentFields.headings.length > 0) ||
|
|
776
|
-
(documentFields.imageNames && documentFields.imageNames.length > 0) ||
|
|
777
|
-
wordCount > 0);
|
|
778
|
-
if (isLoading && !hasAnyField) {
|
|
779
|
-
return (
|
|
780
|
-
<div style={{ padding: 24, textAlign: "center" }}>
|
|
781
|
-
<div style={{ fontSize: 13, color: "#4b5563", fontWeight: 500 }}>Reading document fields...</div>
|
|
782
|
-
<div style={{ fontSize: 11, color: "#4b5563", marginTop: 4 }}>Audit will run once content loads</div>
|
|
783
|
-
</div>
|
|
784
|
-
);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
return (
|
|
788
|
-
<div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
|
|
789
|
-
<AuditCard
|
|
790
|
-
anchorId="anchor-url-slug"
|
|
791
|
-
label={urlSlugAudit.label}
|
|
792
|
-
value={urlSlugAudit.value}
|
|
793
|
-
status={urlSlugAudit.status}
|
|
794
|
-
recommendation={urlSlugAudit.recommendation}
|
|
795
|
-
footer={<SlugRedirectNotice />}
|
|
796
|
-
/>
|
|
797
|
-
|
|
798
|
-
{/* Link Health sits right under URL Slug - both are about the page's links. */}
|
|
799
|
-
<LinkCheckCard
|
|
800
|
-
urls={bodyLinks}
|
|
801
|
-
linksDetailed={bodyLinksDetailed}
|
|
802
|
-
results={linkCheckResults}
|
|
803
|
-
isLoading={isLinkCheckLoading}
|
|
804
|
-
error={linkCheckError}
|
|
805
|
-
hasRun={hasRunLinkCheck}
|
|
806
|
-
onCheck={onCheckLinks}
|
|
807
|
-
/>
|
|
808
|
-
|
|
809
|
-
{wordAudit && (
|
|
810
|
-
<AuditCard
|
|
811
|
-
anchorId="anchor-word-count"
|
|
812
|
-
label={wordAudit.label}
|
|
813
|
-
value={wordAudit.value}
|
|
814
|
-
status={wordAudit.status}
|
|
815
|
-
recommendation={wordAudit.recommendation}
|
|
816
|
-
/>
|
|
817
|
-
)}
|
|
818
|
-
|
|
819
|
-
{(() => {
|
|
820
|
-
// anchor-headings-structure must land on the first STRUCTURAL card (the target of the
|
|
821
|
-
// Summary deep-links for skips/empties/density) - not on the "Keywords in Headings" or
|
|
822
|
-
// "Looks Like a Heading" cards, which have their own anchors and can sort first.
|
|
823
|
-
const structIdx = structureAudits.findIndex(
|
|
824
|
-
(a) => a.label !== "Keywords in Headings" && a.label !== "Looks Like a Heading"
|
|
825
|
-
);
|
|
826
|
-
return structureAudits.map((a, i) => (
|
|
827
|
-
<AuditCard
|
|
828
|
-
key={`structure-${i}`}
|
|
829
|
-
anchorId={
|
|
830
|
-
a.label === "Keywords in Headings"
|
|
831
|
-
? "anchor-headings-keyword"
|
|
832
|
-
: a.label === "Looks Like a Heading"
|
|
833
|
-
? "anchor-headings-unstyled"
|
|
834
|
-
: i === structIdx
|
|
835
|
-
? "anchor-headings-structure"
|
|
836
|
-
: undefined
|
|
837
|
-
}
|
|
838
|
-
label={a.label}
|
|
839
|
-
value={a.value}
|
|
840
|
-
status={a.status}
|
|
841
|
-
recommendation={a.recommendation}
|
|
842
|
-
/>
|
|
843
|
-
));
|
|
844
|
-
})()}
|
|
845
|
-
|
|
846
|
-
{(headings.length > 0 || !!documentFields?.title) && (
|
|
847
|
-
<div id="anchor-headings-outline" style={{ ...cardStyle, padding: "8px 14px" }}>
|
|
848
|
-
<div style={{ fontSize: 10, color: "#4b5563", textTransform: "uppercase", letterSpacing: "0.06em", fontWeight: 600, marginBottom: 6 }}>
|
|
849
|
-
Heading Outline
|
|
850
|
-
</div>
|
|
851
|
-
<div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
|
|
852
|
-
{/* The article title renders as the page H1 - show it first so editors can see
|
|
853
|
-
exactly what their H1 is, then the body headings the tool scanned below it. */}
|
|
854
|
-
{documentFields?.title && (
|
|
855
|
-
<div style={{ fontSize: 11, color: MJH_BLUE, fontWeight: 700, lineHeight: 1.4 }}>
|
|
856
|
-
<span style={{ fontSize: 9, fontWeight: 700, color: MJH_BLUE, marginRight: 6 }}>H1</span>
|
|
857
|
-
{documentFields.title}
|
|
858
|
-
<span style={{ fontSize: 9, color: "#6b7280", fontWeight: 500, marginLeft: 6 }}>(article title)</span>
|
|
859
|
-
</div>
|
|
860
|
-
)}
|
|
861
|
-
{(headingsDetailed
|
|
862
|
-
? headingsDetailed.slice(0, 12)
|
|
863
|
-
: headings.slice(0, 12).map((h) => ({ text: h, level: 2 }))
|
|
864
|
-
).map((h, i) => {
|
|
865
|
-
const isH1 = h.level === 1;
|
|
866
|
-
return (
|
|
867
|
-
<div
|
|
868
|
-
key={i}
|
|
869
|
-
style={{
|
|
870
|
-
fontSize: 11,
|
|
871
|
-
color: !h.text ? "#dc2626" : isH1 ? MJH_BLUE : "#4b5563",
|
|
872
|
-
fontWeight: isH1 ? 700 : 400,
|
|
873
|
-
fontStyle: h.text ? "normal" : "italic",
|
|
874
|
-
lineHeight: 1.4,
|
|
875
|
-
paddingLeft: Math.max(0, (h.level - 2) * 12),
|
|
876
|
-
}}
|
|
877
|
-
>
|
|
878
|
-
<span style={{ fontSize: 9, fontWeight: 700, color: isH1 ? MJH_BLUE : "#4b5563", marginRight: 6 }}>H{h.level}</span>
|
|
879
|
-
{h.text || "(empty)"}
|
|
880
|
-
</div>
|
|
881
|
-
);
|
|
882
|
-
})}
|
|
883
|
-
{(headingsDetailed ?? headings).length > 12 && (
|
|
884
|
-
<div style={{ fontSize: 10, color: "#4b5563" }}>+ {(headingsDetailed ?? headings).length - 12} more</div>
|
|
885
|
-
)}
|
|
886
|
-
</div>
|
|
887
|
-
<div style={{ fontSize: 10, color: "#6b7280", marginTop: 8, lineHeight: 1.4 }}>
|
|
888
|
-
{headings.length > 0
|
|
889
|
-
? "The title above is your H1; the tool scans the H2-H6 tags below it. Tip: work your primary and/or secondary keyword into a header where it reads naturally."
|
|
890
|
-
: "The title above is your H1, and there are no H2-H6 subheadings yet. Tip: work your primary and/or secondary keyword into the title where it reads naturally."}
|
|
891
|
-
</div>
|
|
892
|
-
</div>
|
|
893
|
-
)}
|
|
894
|
-
|
|
895
|
-
{imagesAudit && (
|
|
896
|
-
<AuditCard
|
|
897
|
-
anchorId="anchor-images"
|
|
898
|
-
label={imagesAudit.label}
|
|
899
|
-
value={imagesAudit.value}
|
|
900
|
-
status={imagesAudit.status}
|
|
901
|
-
recommendation={imagesAudit.recommendation}
|
|
902
|
-
/>
|
|
903
|
-
)}
|
|
904
|
-
{filenameAudit && (
|
|
905
|
-
<AuditCard
|
|
906
|
-
anchorId="anchor-image-filenames"
|
|
907
|
-
label={filenameAudit.label}
|
|
908
|
-
value={filenameAudit.value}
|
|
909
|
-
status={filenameAudit.status}
|
|
910
|
-
recommendation={filenameAudit.recommendation}
|
|
911
|
-
/>
|
|
912
|
-
)}
|
|
913
|
-
{altTextAudit && (
|
|
914
|
-
<AuditCard
|
|
915
|
-
anchorId="anchor-image-alt"
|
|
916
|
-
label={altTextAudit.label}
|
|
917
|
-
value={altTextAudit.value}
|
|
918
|
-
status={altTextAudit.status}
|
|
919
|
-
recommendation={altTextAudit.recommendation}
|
|
920
|
-
/>
|
|
921
|
-
)}
|
|
922
|
-
{imgTitleAudit && (
|
|
923
|
-
<AuditCard
|
|
924
|
-
anchorId="anchor-image-titles"
|
|
925
|
-
label={imgTitleAudit.label}
|
|
926
|
-
value={imgTitleAudit.value}
|
|
927
|
-
status={imgTitleAudit.status}
|
|
928
|
-
recommendation={imgTitleAudit.recommendation}
|
|
929
|
-
/>
|
|
930
|
-
)}
|
|
931
|
-
</div>
|
|
932
|
-
);
|
|
933
|
-
}
|