sanity-plugin-seo-copilot 0.2.5 → 0.2.7

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.
@@ -15,6 +15,66 @@ interface LinkingTabProps {
15
15
  text?: string;
16
16
  documentId?: string;
17
17
  publication?: string;
18
+ /** Studio origin + basePath (e.g. https://host/studio). When present, each suggestion
19
+ * gets an "Inside Sanity" link that opens that article in a new Studio tab. */
20
+ sanityBaseUrl?: string;
21
+ /** Schema type of the current document, used to build the Sanity edit-intent link. */
22
+ documentType?: string;
23
+ }
24
+
25
+ // Build the public, reader-facing URL for a suggested article. MJH brands live at
26
+ // www.<publication>.com/view/<slug> (the standard article route). We only build a
27
+ // link when the publication is a clean token we can turn into a domain and a slug
28
+ // exists - otherwise we render no live link rather than a broken one.
29
+ function buildLiveUrl(publication?: string, slug?: string): string | null {
30
+ if (!slug) return null;
31
+ const pub = (publication || "").trim().toLowerCase();
32
+ if (!/^[a-z0-9-]+$/.test(pub)) return null;
33
+ const cleanSlug = slug.replace(/^\/+/, "");
34
+ return `https://www.${pub}.com/view/${cleanSlug}`;
35
+ }
36
+
37
+ // Build a Sanity Studio edit-intent URL that opens the article in a NEW Studio tab,
38
+ // leaving the editor's current tab undisturbed. id-only intent resolves the type
39
+ // itself, but we include type when we know it for a cleaner resolve.
40
+ function buildSanityUrl(baseUrl?: string, id?: string, type?: string): string | null {
41
+ if (!baseUrl || !id) return null;
42
+ const cleanId = id.replace(/^drafts\./, "");
43
+ const base = baseUrl.replace(/\/+$/, "");
44
+ const typePart = type ? `;type=${encodeURIComponent(type)}` : "";
45
+ return `${base}/intent/edit/id=${encodeURIComponent(cleanId)}${typePart}/`;
46
+ }
47
+
48
+ // Small outbound-link chip - both targets open in a new tab so the editor's current
49
+ // work is never disturbed.
50
+ function LinkChip({ href, label, color }: { href: string; label: string; color: string }) {
51
+ return (
52
+ <a
53
+ href={href}
54
+ target="_blank"
55
+ rel="noopener noreferrer"
56
+ style={{
57
+ display: "inline-flex",
58
+ alignItems: "center",
59
+ gap: 4,
60
+ padding: "3px 9px",
61
+ borderRadius: 99,
62
+ fontSize: 10.5,
63
+ fontWeight: 700,
64
+ color,
65
+ background: "rgba(255,255,255,0.7)",
66
+ border: `1px solid ${color}33`,
67
+ textDecoration: "none",
68
+ lineHeight: 1.2,
69
+ }}
70
+ >
71
+ {label}
72
+ <svg width="9" height="9" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
73
+ <path d="M12.5 2a.75.75 0 000 1.5h2.44l-6.97 6.97a.75.75 0 101.06 1.06L16 4.56V7a.75.75 0 001.5 0V2.75A.75.75 0 0016.75 2H12.5z" />
74
+ <path d="M4.75 4.5A2.75 2.75 0 002 7.25v8A2.75 2.75 0 004.75 18h8A2.75 2.75 0 0015.5 15.25v-3a.75.75 0 00-1.5 0v3c0 .69-.56 1.25-1.25 1.25h-8c-.69 0-1.25-.56-1.25-1.25v-8c0-.69.56-1.25 1.25-1.25h3a.75.75 0 000-1.5h-3z" />
75
+ </svg>
76
+ </a>
77
+ );
18
78
  }
19
79
 
20
80
  const cardStyle: React.CSSProperties = {
@@ -126,12 +186,14 @@ export function LinkingTab({
126
186
  text,
127
187
  documentId,
128
188
  publication,
189
+ sanityBaseUrl,
190
+ documentType,
129
191
  }: LinkingTabProps) {
130
192
  if (!analysis) {
131
193
  return (
132
194
  <div style={{ padding: 24, textAlign: "center" }}>
133
- <div style={{ fontSize: 13, color: "#4b5563", fontWeight: 500 }}>Run keyword analysis first</div>
134
- <div style={{ fontSize: 11, color: "#4b5563", marginTop: 4 }}>Internal link suggestions need keywords to start from</div>
195
+ <div style={{ fontSize: 13, color: "#4b5563", fontWeight: 500 }}>Waiting for keyword analysis</div>
196
+ <div style={{ fontSize: 11, color: "#4b5563", marginTop: 4 }}>Linking reads the article keywords and topic to find related published articles. It starts on its own once the Keywords tab finishes.</div>
135
197
  </div>
136
198
  );
137
199
  }
@@ -252,9 +314,9 @@ export function LinkingTab({
252
314
  {/* Empty - no error, just nothing matched. */}
253
315
  {!isLoading && !error && suggestions.length === 0 && (
254
316
  <div style={{ fontSize: 11, color: "#1f2937", padding: "10px 12px", lineHeight: 1.55, background: "rgba(0,93,172,0.04)", borderRadius: 8, border: "1px solid rgba(0,93,172,0.12)" }}>
255
- <div style={{ fontWeight: 700, marginBottom: 4, color: "#1f2937" }}>No related articles found yet.</div>
317
+ <div style={{ fontWeight: 700, marginBottom: 4, color: "#1f2937" }}>No closely related articles found.</div>
256
318
  <div style={{ color: "#4b5563" }}>
257
- Linking suggests published articles on closely related topics. As more related content is published, matches will appear here.
319
+ Linking searched your publication for articles on this topic and did not find a strong match. As more related content is published, suggestions will appear here.
258
320
  </div>
259
321
  </div>
260
322
  )}
@@ -294,6 +356,17 @@ export function LinkingTab({
294
356
  <div style={{ fontSize: 10, color: "#4b5563", fontFamily: "ui-monospace, SFMono-Regular, monospace", marginBottom: 6 }}>
295
357
  /{s.slug}
296
358
  </div>
359
+ {(() => {
360
+ const liveUrl = buildLiveUrl(publication, s.slug);
361
+ const sanityUrl = buildSanityUrl(sanityBaseUrl, s._id, documentType);
362
+ if (!liveUrl && !sanityUrl) return null;
363
+ return (
364
+ <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginBottom: 6 }}>
365
+ {sanityUrl && <LinkChip href={sanityUrl} label="Inside Sanity" color={MJH_BLUE} />}
366
+ {liveUrl && <LinkChip href={liveUrl} label="Live site" color="#4b5563" />}
367
+ </div>
368
+ );
369
+ })()}
297
370
  {s.relevanceReason && (
298
371
  <div style={{ fontSize: 11, color: "#1f2937", marginBottom: 6, lineHeight: 1.45 }}>
299
372
  <span style={{ fontWeight: 700, color: "#4b5563" }}>Why it fits:</span>{" "}
@@ -1,9 +1,10 @@
1
- import { useMemo, useState } from "react";
1
+ import { useMemo } from "react";
2
2
  import type { DocumentFields, TechnicalAuditItem } from "../../lib/types";
3
3
 
4
4
  interface MetaTabProps {
5
5
  documentFields?: DocumentFields;
6
6
  primaryKeyword?: string;
7
+ secondaryKeyword?: string;
7
8
  isLoading?: boolean;
8
9
  }
9
10
 
@@ -95,23 +96,40 @@ function AuditCard({ label, value, status, recommendation, anchorId, footer }: {
95
96
  );
96
97
  }
97
98
 
98
- function metaDescriptionAudit(meta?: string, primaryKeyword?: string): TechnicalAuditItem {
99
+ // Builds the "primary X included, secondary Y not" clause shared across audits.
100
+ // Returns "" when there's nothing to flag (both present, or none set).
101
+ function keywordCoverageNote(haystack: string, primaryKeyword?: string, secondaryKeyword?: string): string {
102
+ const hasPrimary = primaryKeyword ? containsKeywordTokens(haystack, primaryKeyword) : true;
103
+ const hasSecondary = secondaryKeyword ? containsKeywordTokens(haystack, secondaryKeyword) : true;
104
+ if (primaryKeyword && !hasPrimary && secondaryKeyword && !hasSecondary) {
105
+ return `Neither your primary keyword "${primaryKeyword}" nor your secondary keyword "${secondaryKeyword}" appears here.`;
106
+ }
107
+ if (primaryKeyword && !hasPrimary) {
108
+ return `Your primary keyword "${primaryKeyword}" isn't included${secondaryKeyword ? ` (secondary keyword "${secondaryKeyword}" ${hasSecondary ? "is" : "isn't"}).` : "."}`;
109
+ }
110
+ if (secondaryKeyword && !hasSecondary) {
111
+ return `Your primary keyword "${primaryKeyword}" is included, but your secondary keyword "${secondaryKeyword}" is not. Work it in if it reads naturally.`;
112
+ }
113
+ return "";
114
+ }
115
+
116
+ function metaDescriptionAudit(meta?: string, primaryKeyword?: string, secondaryKeyword?: string): TechnicalAuditItem {
99
117
  if (!meta) {
100
118
  return {
101
119
  label: "Meta Description",
102
120
  value: "Missing",
103
121
  status: "error",
104
- recommendation: "Add a 120-160 character meta description that includes your primary keyword.",
122
+ recommendation: `Add a 120-160 character meta description that includes your primary keyword${secondaryKeyword ? " (and your secondary keyword if it fits)" : ""}.`,
105
123
  };
106
124
  }
107
125
  const len = meta.length;
108
- const lacksKeyword = primaryKeyword && !containsKeywordTokens(meta, primaryKeyword);
126
+ const kwNote = keywordCoverageNote(meta, primaryKeyword, secondaryKeyword);
109
127
  if (len < 120) {
110
128
  return {
111
129
  label: "Meta Description",
112
130
  value: `${meta} (${len} chars)`,
113
131
  status: "warning",
114
- recommendation: `Too short - aim for 120-160 characters.${lacksKeyword ? ` Also missing primary keyword "${primaryKeyword}".` : ""}`,
132
+ recommendation: `A little short - aim for 120-160 characters.${kwNote ? ` ${kwNote}` : ""}`,
115
133
  };
116
134
  }
117
135
  if (len > 160) {
@@ -119,15 +137,15 @@ function metaDescriptionAudit(meta?: string, primaryKeyword?: string): Technical
119
137
  label: "Meta Description",
120
138
  value: `${meta} (${len} chars)`,
121
139
  status: "warning",
122
- recommendation: `Too long - Google may truncate beyond 160 characters.${lacksKeyword ? ` Also missing primary keyword "${primaryKeyword}".` : ""}`,
140
+ recommendation: `Over 160 characters - Google may shorten it in search, so trim it a little.${kwNote ? ` ${kwNote}` : ""}`,
123
141
  };
124
142
  }
125
- if (lacksKeyword) {
143
+ if (kwNote) {
126
144
  return {
127
145
  label: "Meta Description",
128
146
  value: `${meta} (${len} chars)`,
129
147
  status: "warning",
130
- recommendation: `Length is good but primary keyword "${primaryKeyword}" is not included.`,
148
+ recommendation: `Length is good. ${kwNote}`,
131
149
  };
132
150
  }
133
151
  return {
@@ -186,99 +204,6 @@ function titleAudit(title?: string, primaryKeyword?: string): TechnicalAuditItem
186
204
  return { label: "Title Tag", value: `${title} (${len} chars)`, status: "good" };
187
205
  }
188
206
 
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
207
  function daysSince(iso?: string): number | null {
283
208
  if (!iso) return null;
284
209
  const t = new Date(iso).getTime();
@@ -295,14 +220,14 @@ function formatDateShort(iso?: string): string {
295
220
  return d.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
296
221
  }
297
222
 
298
- export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabProps) {
223
+ export function MetaTab({ documentFields, primaryKeyword, secondaryKeyword, isLoading }: MetaTabProps) {
299
224
  const audits = useMemo<TechnicalAuditItem[]>(() => {
300
225
  const list: TechnicalAuditItem[] = [];
301
226
  list.push(titleAudit(documentFields?.title, primaryKeyword));
302
- list.push(metaDescriptionAudit(documentFields?.metaDescription, primaryKeyword));
303
- list.push(urlAudit(documentFields?.slug, primaryKeyword));
227
+ list.push(metaDescriptionAudit(documentFields?.metaDescription, primaryKeyword, secondaryKeyword));
228
+ // URL Slug audit moved to the Other Recs tab.
304
229
  return list;
305
- }, [documentFields, primaryKeyword]);
230
+ }, [documentFields, primaryKeyword, secondaryKeyword]);
306
231
 
307
232
  // E-E-A-T audit - critical for healthcare YMYL-adjacent content per 2026 Google scrutiny
308
233
  const eeatItems = useMemo(() => {
@@ -374,7 +299,7 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
374
299
  }
375
300
 
376
301
  // Anchor IDs let the Summary tab deep-link straight to a specific audit card.
377
- const auditAnchors = ["anchor-meta-title", "anchor-meta-description", "anchor-url-slug"];
302
+ const auditAnchors = ["anchor-meta-title", "anchor-meta-description"];
378
303
 
379
304
  return (
380
305
  <div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
@@ -386,9 +311,6 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
386
311
  value={a.value}
387
312
  status={a.status}
388
313
  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
314
  />
393
315
  ))}
394
316
 
@@ -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
- return calculateContentScoreDetailed(text, analysis, documentFields);
245
- }, [text, analysis, documentFields]);
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 && 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
- Generate everything
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,14 @@
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";
5
6
 
6
7
  interface TechnicalTabProps {
7
8
  text: string;
8
9
  documentFields?: DocumentFields;
10
+ primaryKeyword?: string;
11
+ secondaryKeyword?: string;
9
12
  isLoading?: boolean;
10
13
  // Link-check state lifted to the panel so results survive tab switches and re-mount.
11
14
  linkCheckResults: LinkCheckResult[];
@@ -15,6 +18,111 @@ interface TechnicalTabProps {
15
18
  onCheckLinks: () => void;
16
19
  }
17
20
 
21
+ // Token-based keyword match so "selinexor in myelofibrosis" still counts as containing
22
+ // "selinexor myelofibrosis" (word order / connecting words don't matter).
23
+ function containsKeywordTokens(haystack: string, needle?: string): boolean {
24
+ if (!needle) return true;
25
+ const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
26
+ if (tokens.length === 0) return true;
27
+ const lower = haystack.toLowerCase();
28
+ return tokens.every((t) => lower.includes(t));
29
+ }
30
+
31
+ // True when the primary keyword sits near the START of the slug. Editors get the
32
+ // most SEO/CTR value when the keyword leads the URL (and it survives truncation).
33
+ function keywordLeadsUrl(slug: string, primaryKeyword?: string): boolean {
34
+ if (!primaryKeyword) return true;
35
+ const slugWords = slug.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
36
+ const tokens = primaryKeyword.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
37
+ if (tokens.length === 0 || slugWords.length === 0) return true;
38
+ let earliest = Infinity;
39
+ for (const t of tokens) {
40
+ const idx = slugWords.findIndex((w) => w.includes(t));
41
+ if (idx >= 0) earliest = Math.min(earliest, idx);
42
+ }
43
+ return earliest <= 2; // within the first three slug words
44
+ }
45
+
46
+ // URL Slug audit (moved here from Meta per the 6/10 director notes). Deliberately
47
+ // vague and non-numeric: we never cite a character count or say "too long" - just
48
+ // scan for the primary keyword (ideally leading the URL) and nudge toward short,
49
+ // descriptive slugs.
50
+ function urlAudit(slug?: string, primaryKeyword?: string, secondaryKeyword?: string): TechnicalAuditItem {
51
+ const SHORT_DESC = "Keep the URL short and descriptive - concise URLs are easier to read - and avoid trailing, duplicate, or excessive spaces.";
52
+ if (!slug) {
53
+ return {
54
+ label: "URL Slug",
55
+ value: "Missing",
56
+ status: "warning",
57
+ recommendation: `Add a URL slug that leads with your primary keyword. ${SHORT_DESC}`,
58
+ };
59
+ }
60
+ const slugAsWords = slug.replace(/-/g, " ");
61
+ const hasPrimary = primaryKeyword ? containsKeywordTokens(slugAsWords, primaryKeyword) : true;
62
+ const leads = primaryKeyword ? keywordLeadsUrl(slug, primaryKeyword) : true;
63
+ const hasSecondary = secondaryKeyword ? containsKeywordTokens(slugAsWords, secondaryKeyword) : true;
64
+
65
+ if (primaryKeyword && !hasPrimary) {
66
+ const secNote = secondaryKeyword && !hasSecondary ? ` Your secondary keyword "${secondaryKeyword}" could follow it.` : "";
67
+ return {
68
+ label: "URL Slug",
69
+ value: `/${slug}`,
70
+ status: "warning",
71
+ 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}`,
72
+ };
73
+ }
74
+ if (primaryKeyword && hasPrimary && !leads) {
75
+ return {
76
+ label: "URL Slug",
77
+ value: `/${slug}`,
78
+ status: "warning",
79
+ 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}`,
80
+ };
81
+ }
82
+ // Primary leads (or no primary set). Clean pass.
83
+ return { label: "URL Slug", value: `/${slug}`, status: "good" };
84
+ }
85
+
86
+ // Caution block that lives INSIDE the URL Slug card. Changing an indexed page's
87
+ // slug without a 301 redirect drops its search rankings to zero and breaks every
88
+ // external link to the old URL - a warning (avoidable), not an error.
89
+ function SlugRedirectNotice() {
90
+ const [expanded, setExpanded] = useState(false);
91
+ return (
92
+ <div style={{ marginTop: 10, paddingTop: 10, borderTop: "1px solid rgba(0,0,0,0.07)" }}>
93
+ <div style={{ padding: "8px 10px", background: "rgba(245,158,11,0.08)", borderLeft: "2px solid #f59e0b", borderRadius: 6 }}>
94
+ <div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 4 }}>
95
+ <svg width="12" height="12" viewBox="0 0 20 20" fill="#f59e0b" aria-hidden="true">
96
+ <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" />
97
+ </svg>
98
+ <span style={{ fontSize: 10.5, fontWeight: 700, color: "#b45309", textTransform: "uppercase", letterSpacing: "0.06em" }}>
99
+ Changing a URL?
100
+ </span>
101
+ </div>
102
+ <div style={{ fontSize: 11, color: "#1f2937", lineHeight: 1.55 }}>
103
+ 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.
104
+ </div>
105
+ <button
106
+ onClick={() => setExpanded((v) => !v)}
107
+ 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" }}
108
+ >
109
+ {expanded ? "Show less" : "Learn more"}
110
+ <svg width="10" height="10" viewBox="0 0 20 20" fill="currentColor" style={{ transform: expanded ? "rotate(180deg)" : "none", transition: "transform 150ms" }}>
111
+ <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" />
112
+ </svg>
113
+ </button>
114
+ {expanded && (
115
+ <ul style={{ margin: "6px 0 0", paddingLeft: 16, fontSize: 11, color: "#1f2937", lineHeight: 1.55 }}>
116
+ <li>Without the 301, the page loses every search ranking and every external link to it breaks.</li>
117
+ <li>A 301 preserves the rankings and link equity built up on the old URL.</li>
118
+ <li>Set this up using vanity redirects in Sanity.</li>
119
+ </ul>
120
+ )}
121
+ </div>
122
+ </div>
123
+ );
124
+ }
125
+
18
126
  const cardStyle: React.CSSProperties = {
19
127
  borderRadius: 14,
20
128
  background: "rgba(255,255,255,0.55)",
@@ -56,12 +164,14 @@ function AuditCard({
56
164
  status,
57
165
  recommendation,
58
166
  anchorId,
167
+ footer,
59
168
  }: {
60
169
  label: string;
61
170
  value: string;
62
171
  status: TechnicalAuditItem["status"];
63
172
  recommendation?: string;
64
173
  anchorId?: string;
174
+ footer?: React.ReactNode;
65
175
  }) {
66
176
  return (
67
177
  <div id={anchorId} style={cardStyle}>
@@ -98,6 +208,7 @@ function AuditCard({
98
208
  {recommendation}
99
209
  </div>
100
210
  )}
211
+ {footer}
101
212
  </div>
102
213
  );
103
214
  }
@@ -614,6 +725,8 @@ function LinkIssueRow({ result }: { result: LinkCheckResult }) {
614
725
  export function TechnicalTab({
615
726
  text,
616
727
  documentFields,
728
+ primaryKeyword,
729
+ secondaryKeyword,
617
730
  isLoading,
618
731
  linkCheckResults,
619
732
  isLinkCheckLoading,
@@ -621,6 +734,10 @@ export function TechnicalTab({
621
734
  hasRunLinkCheck,
622
735
  onCheckLinks,
623
736
  }: TechnicalTabProps) {
737
+ const urlSlugAudit = useMemo(
738
+ () => urlAudit(documentFields?.slug, primaryKeyword, secondaryKeyword),
739
+ [documentFields?.slug, primaryKeyword, secondaryKeyword]
740
+ );
624
741
  const headings = documentFields?.headings || [];
625
742
  const headingsDetailed = documentFields?.headingsDetailed;
626
743
  // Fall back gracefully if a host (e.g. older Notebook builds) doesn't supply heading
@@ -674,9 +791,14 @@ export function TechnicalTab({
674
791
  // An empty body is not an error to "Fix" - the editor simply hasn't written yet
675
792
  // (or the body hasn't loaded). Mirror summary.ts and show no card rather than a red
676
793
  // alarm; the Word Count card appears once there's real text to measure.
794
+ // Videos / podcasts / news / briefs are legitimately short (body text summarizes
795
+ // the media, it isn't the deliverable), so they're exempt from the word-count floor.
796
+ const isShortForm = isShortFormContent(documentFields, documentFields?.title);
677
797
  const wordAudit: TechnicalAuditItem | null =
678
798
  wordCount === 0
679
799
  ? null
800
+ : isShortForm
801
+ ? { label: "Word Count", value: `${wordCount} words`, status: "good" }
680
802
  : wordCount < 450
681
803
  ? {
682
804
  label: "Word Count",
@@ -714,6 +836,15 @@ export function TechnicalTab({
714
836
 
715
837
  return (
716
838
  <div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
839
+ <AuditCard
840
+ anchorId="anchor-url-slug"
841
+ label={urlSlugAudit.label}
842
+ value={urlSlugAudit.value}
843
+ status={urlSlugAudit.status}
844
+ recommendation={urlSlugAudit.recommendation}
845
+ footer={<SlugRedirectNotice />}
846
+ />
847
+
717
848
  {wordAudit && (
718
849
  <AuditCard
719
850
  anchorId="anchor-word-count"