sanity-plugin-seo-copilot 0.2.5 → 0.2.10
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 +1310 -625
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1332 -647
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -2
- package/src/components/ChatPanel.tsx +5 -3
- package/src/components/FeedbackButton.tsx +6 -1
- package/src/components/KeywordPanel.tsx +179 -6
- package/src/components/OnboardingPopup.tsx +108 -0
- package/src/components/SEOCopilotPanel.tsx +160 -9
- package/src/components/ShimmerLoader.tsx +4 -0
- package/src/components/TabBar.tsx +3 -0
- package/src/components/styles.ts +8 -0
- package/src/components/tabs/AEOTab.tsx +4 -2
- package/src/components/tabs/LinkingTab.tsx +85 -8
- package/src/components/tabs/MetaTab.tsx +32 -119
- package/src/components/tabs/SummaryTab.tsx +19 -4
- package/src/components/tabs/TechnicalTab.tsx +118 -8
- package/src/hooks/useDocumentContent.ts +48 -47
- package/src/hooks/useKeywordAnalysis.ts +81 -48
- package/src/hooks/useSEOChat.ts +49 -9
- package/src/inspector.ts +0 -1
- package/src/lib/api.ts +30 -10
- package/src/lib/documentExtract.ts +268 -257
- package/src/lib/scoring.ts +42 -15
- package/src/lib/summary.ts +121 -41
- package/src/lib/utils.ts +35 -0
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
import { useMemo
|
|
1
|
+
import { useMemo } from "react";
|
|
2
2
|
import type { DocumentFields, TechnicalAuditItem } from "../../lib/types";
|
|
3
|
+
import { containsKeywordTokens } from "../../lib/utils";
|
|
3
4
|
|
|
4
5
|
interface MetaTabProps {
|
|
5
6
|
documentFields?: DocumentFields;
|
|
6
7
|
primaryKeyword?: string;
|
|
8
|
+
secondaryKeyword?: string;
|
|
7
9
|
isLoading?: boolean;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
// Token-based keyword match so "selinexor in myelofibrosis" still counts as containing
|
|
11
|
-
// the primary keyword "selinexor myelofibrosis" (word order / connecting words don't matter).
|
|
12
|
-
function containsKeywordTokens(haystack: string, needle?: string): boolean {
|
|
13
|
-
if (!needle) return true;
|
|
14
|
-
const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
|
|
15
|
-
if (tokens.length === 0) return true;
|
|
16
|
-
const lower = haystack.toLowerCase();
|
|
17
|
-
return tokens.every((t) => lower.includes(t));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
12
|
const cardStyle: React.CSSProperties = {
|
|
21
13
|
borderRadius: 14,
|
|
22
14
|
background: "rgba(255,255,255,0.55)",
|
|
@@ -95,23 +87,40 @@ function AuditCard({ label, value, status, recommendation, anchorId, footer }: {
|
|
|
95
87
|
);
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
|
|
90
|
+
// Builds the "primary X included, secondary Y not" clause shared across audits.
|
|
91
|
+
// Returns "" when there's nothing to flag (both present, or none set).
|
|
92
|
+
function keywordCoverageNote(haystack: string, primaryKeyword?: string, secondaryKeyword?: string): string {
|
|
93
|
+
const hasPrimary = primaryKeyword ? containsKeywordTokens(haystack, primaryKeyword) : true;
|
|
94
|
+
const hasSecondary = secondaryKeyword ? containsKeywordTokens(haystack, secondaryKeyword) : true;
|
|
95
|
+
if (primaryKeyword && !hasPrimary && secondaryKeyword && !hasSecondary) {
|
|
96
|
+
return `Neither your primary keyword "${primaryKeyword}" nor your secondary keyword "${secondaryKeyword}" appears here.`;
|
|
97
|
+
}
|
|
98
|
+
if (primaryKeyword && !hasPrimary) {
|
|
99
|
+
return `Your primary keyword "${primaryKeyword}" isn't included${secondaryKeyword ? ` (secondary keyword "${secondaryKeyword}" ${hasSecondary ? "is" : "isn't"}).` : "."}`;
|
|
100
|
+
}
|
|
101
|
+
if (secondaryKeyword && !hasSecondary) {
|
|
102
|
+
return `Your secondary keyword "${secondaryKeyword}" isn't included${primaryKeyword && hasPrimary ? ` (primary keyword "${primaryKeyword}" is present)` : ""}. Work it in if it reads naturally.`;
|
|
103
|
+
}
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function metaDescriptionAudit(meta?: string, primaryKeyword?: string, secondaryKeyword?: string): TechnicalAuditItem {
|
|
99
108
|
if (!meta) {
|
|
100
109
|
return {
|
|
101
110
|
label: "Meta Description",
|
|
102
111
|
value: "Missing",
|
|
103
112
|
status: "error",
|
|
104
|
-
recommendation:
|
|
113
|
+
recommendation: `Add a 120-160 character meta description that includes your primary keyword${secondaryKeyword ? " (and your secondary keyword if it fits)" : ""}.`,
|
|
105
114
|
};
|
|
106
115
|
}
|
|
107
116
|
const len = meta.length;
|
|
108
|
-
const
|
|
117
|
+
const kwNote = keywordCoverageNote(meta, primaryKeyword, secondaryKeyword);
|
|
109
118
|
if (len < 120) {
|
|
110
119
|
return {
|
|
111
120
|
label: "Meta Description",
|
|
112
121
|
value: `${meta} (${len} chars)`,
|
|
113
122
|
status: "warning",
|
|
114
|
-
recommendation: `
|
|
123
|
+
recommendation: `A little short - aim for 120-160 characters.${kwNote ? ` ${kwNote}` : ""}`,
|
|
115
124
|
};
|
|
116
125
|
}
|
|
117
126
|
if (len > 160) {
|
|
@@ -119,15 +128,15 @@ function metaDescriptionAudit(meta?: string, primaryKeyword?: string): Technical
|
|
|
119
128
|
label: "Meta Description",
|
|
120
129
|
value: `${meta} (${len} chars)`,
|
|
121
130
|
status: "warning",
|
|
122
|
-
recommendation: `
|
|
131
|
+
recommendation: `Over 160 characters - Google may shorten it in search, so trim it a little.${kwNote ? ` ${kwNote}` : ""}`,
|
|
123
132
|
};
|
|
124
133
|
}
|
|
125
|
-
if (
|
|
134
|
+
if (kwNote) {
|
|
126
135
|
return {
|
|
127
136
|
label: "Meta Description",
|
|
128
137
|
value: `${meta} (${len} chars)`,
|
|
129
138
|
status: "warning",
|
|
130
|
-
recommendation: `Length is good
|
|
139
|
+
recommendation: `Length is good. ${kwNote}`,
|
|
131
140
|
};
|
|
132
141
|
}
|
|
133
142
|
return {
|
|
@@ -186,99 +195,6 @@ function titleAudit(title?: string, primaryKeyword?: string): TechnicalAuditItem
|
|
|
186
195
|
return { label: "Title Tag", value: `${title} (${len} chars)`, status: "good" };
|
|
187
196
|
}
|
|
188
197
|
|
|
189
|
-
function urlAudit(slug?: string, primaryKeyword?: string): TechnicalAuditItem {
|
|
190
|
-
if (!slug) {
|
|
191
|
-
return { label: "URL Slug", value: "Missing", status: "error", recommendation: "Add a clean, hyphenated URL slug containing the primary keyword. Aim for 3-5 words." };
|
|
192
|
-
}
|
|
193
|
-
const issues: string[] = [];
|
|
194
|
-
if (slug.length > 60) issues.push("longer than 60 characters - aim for 3-5 words");
|
|
195
|
-
if (/[A-Z]/.test(slug)) issues.push("contains uppercase letters");
|
|
196
|
-
if (/_/.test(slug)) issues.push("uses underscores instead of hyphens");
|
|
197
|
-
if (/[^a-zA-Z0-9-/]/.test(slug.replace(/^\//, ""))) issues.push("contains special characters");
|
|
198
|
-
if (primaryKeyword && !containsKeywordTokens(slug.replace(/-/g, " "), primaryKeyword)) {
|
|
199
|
-
issues.push(`missing primary keyword "${primaryKeyword}"`);
|
|
200
|
-
}
|
|
201
|
-
if (issues.length === 0) {
|
|
202
|
-
return { label: "URL Slug", value: `/${slug}`, status: "good" };
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
label: "URL Slug",
|
|
206
|
-
value: `/${slug}`,
|
|
207
|
-
status: "warning",
|
|
208
|
-
recommendation: `Issues: ${issues.join(", ")}.`,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Caution block that lives INSIDE the URL Slug card (same box - no connector). A
|
|
213
|
-
// slug change on an indexed page without a 301 redirect silently drops search
|
|
214
|
-
// rankings to zero and breaks every external link to the old URL - but it's a
|
|
215
|
-
// warning (avoidable), not an error, so it's styled amber. It echoes the card's
|
|
216
|
-
// own recommendation-block pattern (amber left rail + tint) with a divider above
|
|
217
|
-
// it, so it reads as a distinct caution that's clearly part of the slug card. The
|
|
218
|
-
// headline is always visible; the "why / how" detail tucks behind Learn more.
|
|
219
|
-
function SlugRedirectNotice() {
|
|
220
|
-
const [expanded, setExpanded] = useState(false);
|
|
221
|
-
return (
|
|
222
|
-
<div
|
|
223
|
-
style={{
|
|
224
|
-
marginTop: 10,
|
|
225
|
-
paddingTop: 10,
|
|
226
|
-
borderTop: "1px solid rgba(0,0,0,0.07)",
|
|
227
|
-
}}
|
|
228
|
-
>
|
|
229
|
-
<div
|
|
230
|
-
style={{
|
|
231
|
-
padding: "8px 10px",
|
|
232
|
-
background: "rgba(245,158,11,0.08)",
|
|
233
|
-
borderLeft: "2px solid #f59e0b",
|
|
234
|
-
borderRadius: 6,
|
|
235
|
-
}}
|
|
236
|
-
>
|
|
237
|
-
<div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 4 }}>
|
|
238
|
-
<svg width="12" height="12" viewBox="0 0 20 20" fill="#f59e0b" aria-hidden="true">
|
|
239
|
-
<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" />
|
|
240
|
-
</svg>
|
|
241
|
-
<span style={{ fontSize: 10.5, fontWeight: 700, color: "#b45309", textTransform: "uppercase", letterSpacing: "0.06em" }}>
|
|
242
|
-
Changing a URL?
|
|
243
|
-
</span>
|
|
244
|
-
</div>
|
|
245
|
-
<div style={{ fontSize: 11, color: "#1f2937", lineHeight: 1.55 }}>
|
|
246
|
-
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.
|
|
247
|
-
</div>
|
|
248
|
-
<button
|
|
249
|
-
onClick={() => setExpanded((v) => !v)}
|
|
250
|
-
style={{
|
|
251
|
-
display: "flex",
|
|
252
|
-
alignItems: "center",
|
|
253
|
-
gap: 3,
|
|
254
|
-
marginTop: 6,
|
|
255
|
-
padding: 0,
|
|
256
|
-
background: "none",
|
|
257
|
-
border: "none",
|
|
258
|
-
cursor: "pointer",
|
|
259
|
-
fontSize: 10.5,
|
|
260
|
-
fontWeight: 700,
|
|
261
|
-
color: "#b45309",
|
|
262
|
-
fontFamily: "inherit",
|
|
263
|
-
}}
|
|
264
|
-
>
|
|
265
|
-
{expanded ? "Show less" : "Learn more"}
|
|
266
|
-
<svg width="10" height="10" viewBox="0 0 20 20" fill="currentColor" style={{ transform: expanded ? "rotate(180deg)" : "none", transition: "transform 150ms" }}>
|
|
267
|
-
<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" />
|
|
268
|
-
</svg>
|
|
269
|
-
</button>
|
|
270
|
-
{expanded && (
|
|
271
|
-
<ul style={{ margin: "6px 0 0", paddingLeft: 16, fontSize: 11, color: "#1f2937", lineHeight: 1.55 }}>
|
|
272
|
-
<li>Without the 301, the page loses every search ranking and every external link to it breaks.</li>
|
|
273
|
-
<li>A 301 preserves the rankings and link equity built up on the old URL.</li>
|
|
274
|
-
<li>Set this up using vanity redirects in Sanity.</li>
|
|
275
|
-
</ul>
|
|
276
|
-
)}
|
|
277
|
-
</div>
|
|
278
|
-
</div>
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
198
|
function daysSince(iso?: string): number | null {
|
|
283
199
|
if (!iso) return null;
|
|
284
200
|
const t = new Date(iso).getTime();
|
|
@@ -295,14 +211,14 @@ function formatDateShort(iso?: string): string {
|
|
|
295
211
|
return d.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
|
|
296
212
|
}
|
|
297
213
|
|
|
298
|
-
export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabProps) {
|
|
214
|
+
export function MetaTab({ documentFields, primaryKeyword, secondaryKeyword, isLoading }: MetaTabProps) {
|
|
299
215
|
const audits = useMemo<TechnicalAuditItem[]>(() => {
|
|
300
216
|
const list: TechnicalAuditItem[] = [];
|
|
301
217
|
list.push(titleAudit(documentFields?.title, primaryKeyword));
|
|
302
|
-
list.push(metaDescriptionAudit(documentFields?.metaDescription, primaryKeyword));
|
|
303
|
-
|
|
218
|
+
list.push(metaDescriptionAudit(documentFields?.metaDescription, primaryKeyword, secondaryKeyword));
|
|
219
|
+
// URL Slug audit moved to the Other Recs tab.
|
|
304
220
|
return list;
|
|
305
|
-
}, [documentFields, primaryKeyword]);
|
|
221
|
+
}, [documentFields, primaryKeyword, secondaryKeyword]);
|
|
306
222
|
|
|
307
223
|
// E-E-A-T audit - critical for healthcare YMYL-adjacent content per 2026 Google scrutiny
|
|
308
224
|
const eeatItems = useMemo(() => {
|
|
@@ -374,7 +290,7 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
|
|
|
374
290
|
}
|
|
375
291
|
|
|
376
292
|
// Anchor IDs let the Summary tab deep-link straight to a specific audit card.
|
|
377
|
-
const auditAnchors = ["anchor-meta-title", "anchor-meta-description"
|
|
293
|
+
const auditAnchors = ["anchor-meta-title", "anchor-meta-description"];
|
|
378
294
|
|
|
379
295
|
return (
|
|
380
296
|
<div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
|
|
@@ -386,9 +302,6 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
|
|
|
386
302
|
value={a.value}
|
|
387
303
|
status={a.status}
|
|
388
304
|
recommendation={a.recommendation}
|
|
389
|
-
// 301-redirect caution lives INSIDE the URL Slug card (same box, no
|
|
390
|
-
// connector). Always present so editors see the rule before changing a URL.
|
|
391
|
-
footer={a.label === "URL Slug" ? <SlugRedirectNotice /> : undefined}
|
|
392
305
|
/>
|
|
393
306
|
))}
|
|
394
307
|
|
|
@@ -21,6 +21,11 @@ interface SummaryTabProps {
|
|
|
21
21
|
documentFields?: DocumentFields;
|
|
22
22
|
linkingSuggestions: LinkingSuggestion[];
|
|
23
23
|
linkCheckResults?: LinkCheckResult[];
|
|
24
|
+
// The editor's SELECTED primary keyword (effectivePrimary). The score uses this
|
|
25
|
+
// so it updates instantly on selection instead of waiting for the re-analysis.
|
|
26
|
+
primaryKeyword?: string;
|
|
27
|
+
// Optional secondary target keyword - summary items flag where it's missing.
|
|
28
|
+
secondaryKeyword?: string;
|
|
24
29
|
isAnyLoading: boolean;
|
|
25
30
|
onGenerateAll: () => void;
|
|
26
31
|
onItemClick: (item: SummaryItem) => void;
|
|
@@ -235,14 +240,22 @@ export function SummaryTab({
|
|
|
235
240
|
documentFields,
|
|
236
241
|
linkingSuggestions,
|
|
237
242
|
linkCheckResults,
|
|
243
|
+
primaryKeyword,
|
|
244
|
+
secondaryKeyword,
|
|
238
245
|
isAnyLoading,
|
|
239
246
|
onGenerateAll,
|
|
240
247
|
onItemClick,
|
|
241
248
|
}: SummaryTabProps) {
|
|
242
249
|
const scoreDetail = useMemo(() => {
|
|
243
250
|
if (!analysis) return null;
|
|
244
|
-
|
|
245
|
-
|
|
251
|
+
// Score against the editor's SELECTED primary so the score updates the instant
|
|
252
|
+
// they pick a different candidate (no wait for the focus re-analysis round-trip).
|
|
253
|
+
const scored =
|
|
254
|
+
primaryKeyword && analysis.primaryKeyword && primaryKeyword !== analysis.primaryKeyword.term
|
|
255
|
+
? { ...analysis, primaryKeyword: { ...analysis.primaryKeyword, term: primaryKeyword } }
|
|
256
|
+
: analysis;
|
|
257
|
+
return calculateContentScoreDetailed(text, scored, documentFields);
|
|
258
|
+
}, [text, analysis, documentFields, primaryKeyword]);
|
|
246
259
|
const score = scoreDetail?.total ?? null;
|
|
247
260
|
|
|
248
261
|
const items = useMemo(
|
|
@@ -255,8 +268,10 @@ export function SummaryTab({
|
|
|
255
268
|
linkingSuggestions,
|
|
256
269
|
linkCheckResults,
|
|
257
270
|
text,
|
|
271
|
+
primaryKeyword,
|
|
272
|
+
secondaryKeyword,
|
|
258
273
|
}),
|
|
259
|
-
[analysis, deepAnalysis, documentFields, score, linkingSuggestions, linkCheckResults, text]
|
|
274
|
+
[analysis, deepAnalysis, documentFields, score, linkingSuggestions, linkCheckResults, text, primaryKeyword, secondaryKeyword]
|
|
260
275
|
);
|
|
261
276
|
|
|
262
277
|
const [filter, setFilter] = useState<FilterKey>("all");
|
|
@@ -320,7 +335,7 @@ export function SummaryTab({
|
|
|
320
335
|
letterSpacing: "0.01em",
|
|
321
336
|
}}
|
|
322
337
|
>
|
|
323
|
-
|
|
338
|
+
Run all analyses
|
|
324
339
|
</button>
|
|
325
340
|
)}
|
|
326
341
|
<div style={{ fontSize: 10.5, color: "#4b5563", marginTop: 8, lineHeight: 1.5 }}>
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
2
|
import { LoadingBars } from "../SEOCopilotPanel";
|
|
3
3
|
import { MJH_BLUE, MJH_GOLD } from "../styles";
|
|
4
4
|
import type { DocumentFields, HeadingItem, LinkCheckResult, TechnicalAuditItem } from "../../lib/types";
|
|
5
|
+
import { isShortFormContent } from "../../lib/summary";
|
|
6
|
+
import { containsKeywordTokens, keywordLeadsSlug } from "../../lib/utils";
|
|
5
7
|
|
|
6
8
|
interface TechnicalTabProps {
|
|
7
9
|
text: string;
|
|
8
10
|
documentFields?: DocumentFields;
|
|
11
|
+
primaryKeyword?: string;
|
|
12
|
+
secondaryKeyword?: string;
|
|
9
13
|
isLoading?: boolean;
|
|
10
14
|
// Link-check state lifted to the panel so results survive tab switches and re-mount.
|
|
11
15
|
linkCheckResults: LinkCheckResult[];
|
|
@@ -15,6 +19,86 @@ interface TechnicalTabProps {
|
|
|
15
19
|
onCheckLinks: () => void;
|
|
16
20
|
}
|
|
17
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
|
+
|
|
18
102
|
const cardStyle: React.CSSProperties = {
|
|
19
103
|
borderRadius: 14,
|
|
20
104
|
background: "rgba(255,255,255,0.55)",
|
|
@@ -56,12 +140,14 @@ function AuditCard({
|
|
|
56
140
|
status,
|
|
57
141
|
recommendation,
|
|
58
142
|
anchorId,
|
|
143
|
+
footer,
|
|
59
144
|
}: {
|
|
60
145
|
label: string;
|
|
61
146
|
value: string;
|
|
62
147
|
status: TechnicalAuditItem["status"];
|
|
63
148
|
recommendation?: string;
|
|
64
149
|
anchorId?: string;
|
|
150
|
+
footer?: React.ReactNode;
|
|
65
151
|
}) {
|
|
66
152
|
return (
|
|
67
153
|
<div id={anchorId} style={cardStyle}>
|
|
@@ -98,6 +184,7 @@ function AuditCard({
|
|
|
98
184
|
{recommendation}
|
|
99
185
|
</div>
|
|
100
186
|
)}
|
|
187
|
+
{footer}
|
|
101
188
|
</div>
|
|
102
189
|
);
|
|
103
190
|
}
|
|
@@ -141,7 +228,7 @@ function imageFilenameAudit(filenames: string[]): TechnicalAuditItem | null {
|
|
|
141
228
|
const words = base.split("-").filter(Boolean);
|
|
142
229
|
if (words.length < 2) {
|
|
143
230
|
issues.push({ filename: f, reason: "single word - use 2-3 descriptive hyphenated words" });
|
|
144
|
-
} else if (words.length >
|
|
231
|
+
} else if (words.length > 5) {
|
|
145
232
|
issues.push({ filename: f, reason: "too many words - keep to 3-5" });
|
|
146
233
|
}
|
|
147
234
|
}
|
|
@@ -176,7 +263,7 @@ function imageAltTextAudit(altTexts: string[]): TechnicalAuditItem | null {
|
|
|
176
263
|
audited++;
|
|
177
264
|
const len = trimmed.length;
|
|
178
265
|
const wc = trimmed.split(/\s+/).filter(Boolean).length;
|
|
179
|
-
if (len
|
|
266
|
+
if (len >= 125) {
|
|
180
267
|
issues.push({ alt: trimmed, reason: `${len} chars - shorten to under 125` });
|
|
181
268
|
} else if (wc < 2) {
|
|
182
269
|
issues.push({ alt: trimmed, reason: "just one word - use 2-5 descriptive keywords" });
|
|
@@ -614,6 +701,8 @@ function LinkIssueRow({ result }: { result: LinkCheckResult }) {
|
|
|
614
701
|
export function TechnicalTab({
|
|
615
702
|
text,
|
|
616
703
|
documentFields,
|
|
704
|
+
primaryKeyword,
|
|
705
|
+
secondaryKeyword,
|
|
617
706
|
isLoading,
|
|
618
707
|
linkCheckResults,
|
|
619
708
|
isLinkCheckLoading,
|
|
@@ -621,13 +710,20 @@ export function TechnicalTab({
|
|
|
621
710
|
hasRunLinkCheck,
|
|
622
711
|
onCheckLinks,
|
|
623
712
|
}: TechnicalTabProps) {
|
|
713
|
+
const urlSlugAudit = useMemo(
|
|
714
|
+
() => urlAudit(documentFields?.slug, primaryKeyword, secondaryKeyword),
|
|
715
|
+
[documentFields?.slug, primaryKeyword, secondaryKeyword]
|
|
716
|
+
);
|
|
624
717
|
const headings = documentFields?.headings || [];
|
|
625
718
|
const headingsDetailed = documentFields?.headingsDetailed;
|
|
626
719
|
// Fall back gracefully if a host (e.g. older Notebook builds) doesn't supply heading
|
|
627
720
|
// levels - we still get the count audit from the flat string list.
|
|
628
|
-
const headingsForStructure: HeadingItem[] =
|
|
629
|
-
|
|
630
|
-
|
|
721
|
+
const headingsForStructure: HeadingItem[] = useMemo(
|
|
722
|
+
() => headingsDetailed
|
|
723
|
+
? headingsDetailed
|
|
724
|
+
: headings.map((text) => ({ text, level: 2 })),
|
|
725
|
+
[headingsDetailed, headings]
|
|
726
|
+
);
|
|
631
727
|
|
|
632
728
|
// Word count drives both the dedicated Word Count audit and the heading-density check.
|
|
633
729
|
const wordCount = text ? text.split(/\s+/).filter(Boolean).length : 0;
|
|
@@ -674,9 +770,14 @@ export function TechnicalTab({
|
|
|
674
770
|
// An empty body is not an error to "Fix" - the editor simply hasn't written yet
|
|
675
771
|
// (or the body hasn't loaded). Mirror summary.ts and show no card rather than a red
|
|
676
772
|
// alarm; the Word Count card appears once there's real text to measure.
|
|
773
|
+
// Videos / podcasts / news / briefs are legitimately short (body text summarizes
|
|
774
|
+
// the media, it isn't the deliverable), so they're exempt from the word-count floor.
|
|
775
|
+
const isShortForm = isShortFormContent(documentFields, documentFields?.title);
|
|
677
776
|
const wordAudit: TechnicalAuditItem | null =
|
|
678
777
|
wordCount === 0
|
|
679
778
|
? null
|
|
779
|
+
: isShortForm
|
|
780
|
+
? { label: "Word Count", value: `${wordCount} words`, status: "good" }
|
|
680
781
|
: wordCount < 450
|
|
681
782
|
? {
|
|
682
783
|
label: "Word Count",
|
|
@@ -714,6 +815,15 @@ export function TechnicalTab({
|
|
|
714
815
|
|
|
715
816
|
return (
|
|
716
817
|
<div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
|
|
818
|
+
<AuditCard
|
|
819
|
+
anchorId="anchor-url-slug"
|
|
820
|
+
label={urlSlugAudit.label}
|
|
821
|
+
value={urlSlugAudit.value}
|
|
822
|
+
status={urlSlugAudit.status}
|
|
823
|
+
recommendation={urlSlugAudit.recommendation}
|
|
824
|
+
footer={<SlugRedirectNotice />}
|
|
825
|
+
/>
|
|
826
|
+
|
|
717
827
|
{wordAudit && (
|
|
718
828
|
<AuditCard
|
|
719
829
|
anchorId="anchor-word-count"
|
|
@@ -759,8 +869,8 @@ export function TechnicalTab({
|
|
|
759
869
|
{h.text || "(empty)"}
|
|
760
870
|
</div>
|
|
761
871
|
))}
|
|
762
|
-
{headings.length > 12 && (
|
|
763
|
-
<div style={{ fontSize: 10, color: "#4b5563" }}>+ {headings.length - 12} more</div>
|
|
872
|
+
{(headingsDetailed ?? headings).length > 12 && (
|
|
873
|
+
<div style={{ fontSize: 10, color: "#4b5563" }}>+ {(headingsDetailed ?? headings).length - 12} more</div>
|
|
764
874
|
)}
|
|
765
875
|
</div>
|
|
766
876
|
</div>
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import { useState, useEffect, useRef } from "react";
|
|
2
|
-
import { useDocumentPane } from "sanity/structure";
|
|
3
|
-
import type { DocumentFields } from "../lib/types";
|
|
4
|
-
import { extractText, buildDocumentFields } from "../lib/documentExtract";
|
|
5
|
-
|
|
6
|
-
export function useDocumentContent(): { text: string; isLoading: boolean; documentFields: DocumentFields; documentId: string | undefined } {
|
|
7
|
-
const { value, ready } = useDocumentPane();
|
|
8
|
-
const documentId = (value?._id as string | undefined) || undefined;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const [
|
|
13
|
-
const [
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
1
|
+
import { useState, useEffect, useRef } from "react";
|
|
2
|
+
import { useDocumentPane } from "sanity/structure";
|
|
3
|
+
import type { DocumentFields } from "../lib/types";
|
|
4
|
+
import { extractText, buildDocumentFields } from "../lib/documentExtract";
|
|
5
|
+
|
|
6
|
+
export function useDocumentContent(): { text: string; isLoading: boolean; documentFields: DocumentFields; documentId: string | undefined; documentType: string | undefined } {
|
|
7
|
+
const { value, ready } = useDocumentPane();
|
|
8
|
+
const documentId = (value?._id as string | undefined) || undefined;
|
|
9
|
+
const documentType = (value?._type as string | undefined) || undefined;
|
|
10
|
+
const title = value?.title as string | undefined;
|
|
11
|
+
const body = value?.body;
|
|
12
|
+
const [debouncedText, setDebouncedText] = useState("");
|
|
13
|
+
const [isLoading, setIsLoading] = useState(!ready);
|
|
14
|
+
const [documentFields, setDocumentFields] = useState<DocumentFields>({});
|
|
15
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
16
|
+
const prevDocIdRef = useRef<string | undefined>(documentId);
|
|
17
|
+
|
|
18
|
+
// Reset loading state on doc switch so downstream tabs can show their own loading UI
|
|
19
|
+
// instead of flashing "Missing" cards based on the previous doc's data.
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (prevDocIdRef.current !== documentId) {
|
|
22
|
+
prevDocIdRef.current = documentId;
|
|
23
|
+
setIsLoading(true);
|
|
24
|
+
}
|
|
25
|
+
}, [documentId]);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const bodyText = extractText(body);
|
|
29
|
+
const fullText = [title, bodyText].filter(Boolean).join("\n\n");
|
|
30
|
+
const fields = buildDocumentFields(value as Record<string, unknown> | undefined);
|
|
31
|
+
|
|
32
|
+
// documentFields are cheap and shown immediately so the Technical tab doesn't flash
|
|
33
|
+
// "Missing" cards while the text debounce is pending. Only debounce text since that
|
|
34
|
+
// drives the expensive AI analysis calls.
|
|
35
|
+
setDocumentFields(fields);
|
|
36
|
+
|
|
37
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
38
|
+
|
|
39
|
+
timerRef.current = setTimeout(() => {
|
|
40
|
+
setDebouncedText(fullText);
|
|
41
|
+
setIsLoading(false);
|
|
42
|
+
}, 2000);
|
|
43
|
+
|
|
44
|
+
return () => { if (timerRef.current) clearTimeout(timerRef.current); };
|
|
45
|
+
}, [title, body, value]);
|
|
46
|
+
|
|
47
|
+
return { text: debouncedText, isLoading, documentFields, documentId, documentType };
|
|
48
|
+
}
|