sanity-plugin-seo-copilot 0.2.1 → 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.
@@ -30,6 +30,14 @@ export const INJECTED_CSS = `
30
30
  0%, 100% { opacity: 0.5; }
31
31
  50% { opacity: 1; }
32
32
  }
33
+ @keyframes onboard-in {
34
+ from { opacity: 0; transform: translateY(-6px) scale(0.97); }
35
+ to { opacity: 1; transform: translateY(0) scale(1); }
36
+ }
37
+ @keyframes onboard-out {
38
+ from { opacity: 1; transform: translateY(0) scale(1); }
39
+ to { opacity: 0; transform: translateY(-6px) scale(0.97); }
40
+ }
33
41
  .prose-chat { font-size: 12.5px; line-height: 1.65; color: #475569; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; }
34
42
  .prose-chat h1 { font-size: 14px; font-weight: 700; color: #1e293b; margin: 10px 0 5px 0; line-height: 1.35; }
35
43
  .prose-chat h2, .prose-chat h3 { font-size: 13px; font-weight: 700; color: #1e293b; margin: 10px 0 5px 0; line-height: 1.35; }
@@ -112,9 +112,13 @@ function CopyButton({ text }: { text: string }) {
112
112
  function GEOCard({ geo, publication }: { geo: ReturnType<typeof analyzeGEO>; publication?: string }) {
113
113
  const [showDetails, setShowDetails] = usePersistentState<boolean>("seo-copilot-ui-geo-details", false);
114
114
  const fd = geo.factDensity;
115
- const fdColor = fd.status === "strong" ? "#16a34a" : fd.status === "moderate" ? "#8B7310" : "#dc2626";
116
- const fdLabel = fd.status === "strong" ? "Strong" : fd.status === "moderate" ? "Moderate" : "Weak";
117
- const fdBg = fd.status === "strong" ? "rgba(22,163,74,0.1)" : fd.status === "moderate" ? "rgba(230,192,27,0.15)" : "rgba(220,38,38,0.08)";
115
+ // Short-form content (news briefs, previews) naturally has low fact density,
116
+ // so don't show an alarming red "Weak" - present it neutrally instead.
117
+ const isShort = fd.totalWords > 0 && fd.totalWords < 600;
118
+ const effectiveStatus = fd.status === "weak" && isShort ? "moderate" : fd.status;
119
+ const fdColor = effectiveStatus === "strong" ? "#16a34a" : effectiveStatus === "moderate" ? "#8B7310" : "#dc2626";
120
+ const fdLabel = fd.status === "strong" ? "Strong" : fd.status === "moderate" ? "Moderate" : isShort ? "Light (short-form)" : "Weak";
121
+ const fdBg = effectiveStatus === "strong" ? "rgba(22,163,74,0.1)" : effectiveStatus === "moderate" ? "rgba(230,192,27,0.15)" : "rgba(220,38,38,0.08)";
118
122
 
119
123
  const goodCount = geo.headingAudit.filter((h) => h.status === "good").length;
120
124
  const totalHeadings = geo.headingAudit.length;
@@ -170,6 +174,8 @@ function GEOCard({ geo, publication }: { geo: ReturnType<typeof analyzeGEO>; pub
170
174
  ? "AI engines prefer this density."
171
175
  : fd.status === "moderate"
172
176
  ? "Aim for 8+ per 1,000 words with named sources (NEJM, JAMA, FDA, trial numbers, p-values)."
177
+ : isShort
178
+ ? "Short-form content naturally has fewer stats - fine for news and previews. Add a citation or two where you can."
173
179
  : "Vague claims get skipped. Add specific numbers, trial citations, or dates."}
174
180
  </div>
175
181
  </div>
@@ -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();
@@ -288,21 +213,21 @@ function daysSince(iso?: string): number | null {
288
213
 
289
214
  function formatDateShort(iso?: string): string {
290
215
  if (!iso) return "";
291
- try {
292
- return new Date(iso).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
293
- } catch {
294
- return "";
295
- }
216
+ const d = new Date(iso);
217
+ // toLocaleDateString does NOT throw on a bad date - it returns "Invalid Date".
218
+ // Guard explicitly so we never render that (or a blank) inside a "Good" badge.
219
+ if (isNaN(d.getTime())) return "";
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(() => {
@@ -316,7 +241,7 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
316
241
  // Don't flag as missing - just note we can't audit it here.
317
242
  items.push({ label: "Author Byline", value: "Set (reference)", status: "good", recommendation: "Author is linked as a reference, so we can't read credentials from this view. Open the linked author page to confirm name, credentials, and bio are set." });
318
243
  } else if (!author) {
319
- items.push({ label: "Author Byline", value: "Missing", status: "error", recommendation: "Add a named author. Healthcare content needs visible authorship for Google to consider it trustworthy." });
244
+ items.push({ label: "Author Byline", value: "Missing", status: "warning", recommendation: "Add a named author with credentials - healthcare (YMYL) content with visible authorship earns more trust from Google's E-E-A-T signals. Wire or news briefs published without a byline can disregard this." });
320
245
  } else if (!creds) {
321
246
  items.push({ label: "Author Byline", value: author, status: "warning", recommendation: "Author shown but credentials (MD, PharmD, RN, etc.) aren't visible. Add credential suffixes." });
322
247
  } else if (!bio) {
@@ -335,6 +260,9 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
335
260
 
336
261
  if (!published) {
337
262
  items.push({ label: "Publish Date", value: "Missing", status: "error", recommendation: "Add a visible publish date. Required for healthcare content to be cited by Google and AI search." });
263
+ } else if (daysPub === null) {
264
+ // A date is set but couldn't be parsed - don't show a blank/garbage value in a green "Good" badge.
265
+ items.push({ label: "Publish Date", value: "Unrecognized format", status: "warning", recommendation: "A publish date is set but couldn't be read as a valid date. Check the field value." });
338
266
  } else {
339
267
  items.push({ label: "Publish Date", value: formatDateShort(published), status: "good" });
340
268
  }
@@ -371,7 +299,7 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
371
299
  }
372
300
 
373
301
  // Anchor IDs let the Summary tab deep-link straight to a specific audit card.
374
- const auditAnchors = ["anchor-meta-title", "anchor-meta-description", "anchor-url-slug"];
302
+ const auditAnchors = ["anchor-meta-title", "anchor-meta-description"];
375
303
 
376
304
  return (
377
305
  <div style={{ padding: 12, display: "flex", flexDirection: "column", gap: 10 }}>
@@ -383,9 +311,6 @@ export function MetaTab({ documentFields, primaryKeyword, isLoading }: MetaTabPr
383
311
  value={a.value}
384
312
  status={a.status}
385
313
  recommendation={a.recommendation}
386
- // 301-redirect caution lives INSIDE the URL Slug card (same box, no
387
- // connector). Always present so editors see the rule before changing a URL.
388
- footer={a.label === "URL Slug" ? <SlugRedirectNotice /> : undefined}
389
314
  />
390
315
  ))}
391
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);
245
- }, [text, analysis]);
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 }}>