sanity-plugin-seo-copilot 0.2.10 → 0.2.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-seo-copilot",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "AI-powered SEO writing assistant for Sanity Studio",
5
5
  "keywords": [
6
6
  "sanity",
@@ -1,108 +1,108 @@
1
- import { MJH_BLUE } from "./styles";
2
-
3
- // Small (i) button that lives in the panel header next to the pop-out control. The
4
- // first-run popup collapses into this; clicking it re-opens the popup.
5
- export function OnboardingInfoButton({ onClick }: { onClick: () => void }) {
6
- return (
7
- <button
8
- onClick={(e) => { e.stopPropagation(); onClick(); }}
9
- onMouseDown={(e) => e.stopPropagation()}
10
- style={{
11
- background: "rgba(0,93,172,0.08)",
12
- border: "none",
13
- borderRadius: "50%",
14
- width: 20,
15
- height: 20,
16
- cursor: "pointer",
17
- padding: 0,
18
- display: "flex",
19
- alignItems: "center",
20
- justifyContent: "center",
21
- color: MJH_BLUE,
22
- flexShrink: 0,
23
- }}
24
- title="How SEO Copilot works"
25
- aria-label="How SEO Copilot works"
26
- >
27
- <svg width="13" height="13" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
28
- <path fillRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clipRule="evenodd" />
29
- </svg>
30
- </button>
31
- );
32
- }
33
-
34
- // First-run onboarding popup. Amorphous MJH-blue glass. Clicking anywhere on the
35
- // dimmed backdrop, the X, or "Got it" dismisses it (fades out to the info icon).
36
- export function OnboardingCard({ onDismiss, closing }: { onDismiss: () => void; closing: boolean }) {
37
- return (
38
- <>
39
- {/* Click-anywhere backdrop - very light so it doesn't feel like a hard modal. */}
40
- <div
41
- onClick={onDismiss}
42
- style={{
43
- position: "absolute",
44
- inset: 0,
45
- zIndex: 60,
46
- background: "transparent",
47
- cursor: "pointer",
48
- }}
49
- />
50
- <div
51
- onClick={(e) => e.stopPropagation()}
52
- style={{
53
- position: "absolute",
54
- top: 50,
55
- right: 10,
56
- left: 10,
57
- maxWidth: 320,
58
- marginLeft: "auto",
59
- zIndex: 61,
60
- borderRadius: 18,
61
- padding: "14px 16px 16px",
62
- // Amorphous blue glass
63
- background: "linear-gradient(155deg, rgba(0,93,172,0.16), rgba(0,93,172,0.08))",
64
- backdropFilter: "blur(20px) saturate(170%)",
65
- WebkitBackdropFilter: "blur(20px) saturate(170%)",
66
- boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.55), inset 1.5px 2px 1px -1px rgba(255,255,255,0.9), 0 10px 30px rgba(0,93,172,0.22), 0 2px 8px rgba(0,0,0,0.12)",
67
- animation: `${closing ? "onboard-out" : "onboard-in"} ${closing ? 200 : 240}ms ease-out forwards`,
68
- }}
69
- >
70
- <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
71
- <span style={{ fontSize: 13, fontWeight: 800, color: "#00468a", letterSpacing: "-0.01em" }}>
72
- Welcome to SEO Copilot
73
- </span>
74
- <button
75
- onClick={onDismiss}
76
- style={{ background: "none", border: "none", cursor: "pointer", padding: 2, display: "flex", color: "#00468a", opacity: 1 }}
77
- title="Dismiss"
78
- aria-label="Dismiss"
79
- >
80
- <svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
81
- <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
82
- </svg>
83
- </button>
84
- </div>
85
- <div style={{ fontSize: 11.5, color: "#13335a", lineHeight: 1.6 }}>
86
- Start on the <strong>Keywords</strong> tab. Choose one <strong>Primary</strong> keyword (required) and, optionally, one <strong>Secondary</strong> keyword. Copilot then optimizes its recommendations toward both.
87
- </div>
88
- <button
89
- onClick={onDismiss}
90
- style={{
91
- marginTop: 12,
92
- width: "100%",
93
- padding: "7px 12px",
94
- fontSize: 11.5,
95
- fontWeight: 700,
96
- color: "#ffffff",
97
- background: MJH_BLUE,
98
- border: "none",
99
- borderRadius: 8,
100
- cursor: "pointer",
101
- }}
102
- >
103
- Got it
104
- </button>
105
- </div>
106
- </>
107
- );
108
- }
1
+ import { MJH_BLUE } from "./styles";
2
+
3
+ // Small (i) button that lives in the panel header next to the pop-out control. The
4
+ // first-run popup collapses into this; clicking it re-opens the popup.
5
+ export function OnboardingInfoButton({ onClick }: { onClick: () => void }) {
6
+ return (
7
+ <button
8
+ onClick={(e) => { e.stopPropagation(); onClick(); }}
9
+ onMouseDown={(e) => e.stopPropagation()}
10
+ style={{
11
+ background: "rgba(0,93,172,0.08)",
12
+ border: "none",
13
+ borderRadius: "50%",
14
+ width: 20,
15
+ height: 20,
16
+ cursor: "pointer",
17
+ padding: 0,
18
+ display: "flex",
19
+ alignItems: "center",
20
+ justifyContent: "center",
21
+ color: MJH_BLUE,
22
+ flexShrink: 0,
23
+ }}
24
+ title="How SEO Copilot works"
25
+ aria-label="How SEO Copilot works"
26
+ >
27
+ <svg width="13" height="13" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
28
+ <path fillRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clipRule="evenodd" />
29
+ </svg>
30
+ </button>
31
+ );
32
+ }
33
+
34
+ // First-run onboarding popup. Amorphous MJH-blue glass. Clicking anywhere on the
35
+ // dimmed backdrop, the X, or "Got it" dismisses it (fades out to the info icon).
36
+ export function OnboardingCard({ onDismiss, closing }: { onDismiss: () => void; closing: boolean }) {
37
+ return (
38
+ <>
39
+ {/* Click-anywhere backdrop - very light so it doesn't feel like a hard modal. */}
40
+ <div
41
+ onClick={onDismiss}
42
+ style={{
43
+ position: "absolute",
44
+ inset: 0,
45
+ zIndex: 60,
46
+ background: "transparent",
47
+ cursor: "pointer",
48
+ }}
49
+ />
50
+ <div
51
+ onClick={(e) => e.stopPropagation()}
52
+ style={{
53
+ position: "absolute",
54
+ top: 50,
55
+ right: 10,
56
+ left: 10,
57
+ maxWidth: 320,
58
+ marginLeft: "auto",
59
+ zIndex: 61,
60
+ borderRadius: 18,
61
+ padding: "14px 16px 16px",
62
+ // Amorphous blue glass
63
+ background: "linear-gradient(155deg, rgba(0,93,172,0.16), rgba(0,93,172,0.08))",
64
+ backdropFilter: "blur(20px) saturate(170%)",
65
+ WebkitBackdropFilter: "blur(20px) saturate(170%)",
66
+ boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.55), inset 1.5px 2px 1px -1px rgba(255,255,255,0.9), 0 10px 30px rgba(0,93,172,0.22), 0 2px 8px rgba(0,0,0,0.12)",
67
+ animation: `${closing ? "onboard-out" : "onboard-in"} ${closing ? 200 : 240}ms ease-out forwards`,
68
+ }}
69
+ >
70
+ <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, marginBottom: 6 }}>
71
+ <span style={{ fontSize: 13, fontWeight: 800, color: "#00468a", letterSpacing: "-0.01em" }}>
72
+ Welcome to SEO Copilot
73
+ </span>
74
+ <button
75
+ onClick={onDismiss}
76
+ style={{ background: "none", border: "none", cursor: "pointer", padding: 2, display: "flex", color: "#00468a", opacity: 1 }}
77
+ title="Dismiss"
78
+ aria-label="Dismiss"
79
+ >
80
+ <svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor">
81
+ <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
82
+ </svg>
83
+ </button>
84
+ </div>
85
+ <div style={{ fontSize: 11.5, color: "#13335a", lineHeight: 1.6 }}>
86
+ Start on the <strong>Keywords</strong> tab. Choose one <strong>Primary</strong> keyword (required) and, optionally, one <strong>Secondary</strong> keyword. Copilot then optimizes its recommendations toward both.
87
+ </div>
88
+ <button
89
+ onClick={onDismiss}
90
+ style={{
91
+ marginTop: 12,
92
+ width: "100%",
93
+ padding: "7px 12px",
94
+ fontSize: 11.5,
95
+ fontWeight: 700,
96
+ color: "#ffffff",
97
+ background: MJH_BLUE,
98
+ border: "none",
99
+ borderRadius: 8,
100
+ cursor: "pointer",
101
+ }}
102
+ >
103
+ Got it
104
+ </button>
105
+ </div>
106
+ </>
107
+ );
108
+ }
@@ -65,10 +65,10 @@ export function ShimmerLoader({
65
65
  style.dataset.seoCopilotKeyframes = "1";
66
66
  style.innerHTML = KEYFRAMES;
67
67
  document.head.appendChild(style);
68
- return () => {
69
- try { document.head.removeChild(style); } catch { /* already removed */ }
70
- keyframesInjected = false;
71
- };
68
+ // Intentionally NOT removed on unmount. The ~100-byte keyframe block is global
69
+ // and harmless to leave in <head>. Removing it when the first loader unmounts
70
+ // would yank the animation out from under any OTHER ShimmerLoader still mounted,
71
+ // so we inject once per session and keep the flag latched true.
72
72
  }
73
73
  }, []);
74
74
 
package/src/inspector.ts CHANGED
@@ -1,50 +1,58 @@
1
- import { type DocumentInspector, type DocumentInspectorProps } from "sanity";
2
- import { createElement } from "react";
3
- import type { SEOCopilotConfig } from "./index";
4
- import SEOCopilotPanel from "./components/SEOCopilotPanel";
5
-
6
- function SEOIcon() {
7
- return createElement("svg", { viewBox: "0 0 25 25", width: "1em", height: "1em", fill: "none" },
8
- createElement("circle", { cx: "12.5", cy: "12.5", r: "11.5", fill: "#E6C01B" }),
9
- createElement("text", {
10
- x: "12.5", y: "7.5",
11
- textAnchor: "middle",
12
- dominantBaseline: "central",
13
- fill: "white",
14
- fontSize: "7",
15
- fontWeight: "900",
16
- fontFamily: "Arial Black, Impact, sans-serif",
17
- }, "S"),
18
- createElement("text", {
19
- x: "12.5", y: "12.8",
20
- textAnchor: "middle",
21
- dominantBaseline: "central",
22
- fill: "white",
23
- fontSize: "7",
24
- fontWeight: "900",
25
- fontFamily: "Arial Black, Impact, sans-serif",
26
- }, "E"),
27
- createElement("text", {
28
- x: "12.5", y: "18",
29
- textAnchor: "middle",
30
- dominantBaseline: "central",
31
- fill: "white",
32
- fontSize: "7",
33
- fontWeight: "900",
34
- fontFamily: "Arial Black, Impact, sans-serif",
35
- }, "O")
36
- );
37
- }
38
-
39
- export function seoCopilotInspector(config: SEOCopilotConfig): DocumentInspector {
40
- return {
41
- name: "seo-copilot",
42
- useMenuItem: () => ({
43
- title: "SEO Copilot",
44
- icon: SEOIcon,
45
- }),
46
- component: function SEOCopilotInspector(props: DocumentInspectorProps) {
47
- return createElement(SEOCopilotPanel, { ...props, config });
48
- },
49
- };
50
- }
1
+ import { type DocumentInspector, type DocumentInspectorProps } from "sanity";
2
+ import { createElement } from "react";
3
+ import type { SEOCopilotConfig } from "./index";
4
+ import SEOCopilotPanel from "./components/SEOCopilotPanel";
5
+
6
+ function SEOIcon() {
7
+ return createElement("svg", { viewBox: "0 0 25 25", width: "1em", height: "1em", fill: "none" },
8
+ createElement("circle", { cx: "12.5", cy: "12.5", r: "11.5", fill: "#E6C01B" }),
9
+ createElement("text", {
10
+ x: "12.5", y: "7.5",
11
+ textAnchor: "middle",
12
+ dominantBaseline: "central",
13
+ fill: "white",
14
+ fontSize: "7",
15
+ fontWeight: "900",
16
+ fontFamily: "Arial Black, Impact, sans-serif",
17
+ }, "S"),
18
+ createElement("text", {
19
+ x: "12.5", y: "12.8",
20
+ textAnchor: "middle",
21
+ dominantBaseline: "central",
22
+ fill: "white",
23
+ fontSize: "7",
24
+ fontWeight: "900",
25
+ fontFamily: "Arial Black, Impact, sans-serif",
26
+ }, "E"),
27
+ createElement("text", {
28
+ x: "12.5", y: "18",
29
+ textAnchor: "middle",
30
+ dominantBaseline: "central",
31
+ fill: "white",
32
+ fontSize: "7",
33
+ fontWeight: "900",
34
+ fontFamily: "Arial Black, Impact, sans-serif",
35
+ }, "O")
36
+ );
37
+ }
38
+
39
+ export function seoCopilotInspector(config: SEOCopilotConfig): DocumentInspector {
40
+ return {
41
+ name: "seo-copilot",
42
+ useMenuItem: () => ({
43
+ title: "SEO Copilot",
44
+ icon: SEOIcon,
45
+ // Toolbar placement test: showAsAction renders this as a button in the document
46
+ // toolbar (where editors expect it). The original crash came from passing
47
+ // showAsAction WITHOUT a tone; pairing it with a valid string tone is how Sanity's
48
+ // own built-in inspectors (Validation, etc.) keep their toolbar button safely.
49
+ // If this still crashes in Nick's studio, remove these two lines to fall back to
50
+ // the "..." overflow menu (the known-safe placement).
51
+ showAsAction: true,
52
+ tone: "default",
53
+ }),
54
+ component: function SEOCopilotInspector(props: DocumentInspectorProps) {
55
+ return createElement(SEOCopilotPanel, { ...props, config });
56
+ },
57
+ };
58
+ }
@@ -265,7 +265,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
265
265
  category: "headings",
266
266
  severity: "error",
267
267
  label: "Long article without section headings",
268
- description: `${wordCount} words and no H2 headings.`,
268
+ description: `${wordCount} words and no H2 or H3 section headings.`,
269
269
  howToFix: "Add 2-3 H2 headings to break the article into scannable sections.",
270
270
  jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
271
271
  });
@@ -275,7 +275,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
275
275
  category: "headings",
276
276
  severity: "warning",
277
277
  label: "Long article could use more section headings",
278
- description: `${h2Count} H2 heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
278
+ description: `${h2Count} section heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
279
279
  howToFix: "Long articles read best with 1 H2 per 300-400 words. Add more named section breaks.",
280
280
  jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
281
281
  });
@@ -285,7 +285,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
285
285
  category: "headings",
286
286
  severity: "warning",
287
287
  label: "Article could use more section headings",
288
- description: `${h2Count} H2 heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
288
+ description: `${h2Count} section heading${h2Count === 1 ? "" : "s"} for ${wordCount} words.`,
289
289
  howToFix: "Articles above 1,500 words usually need at least 3 H2 sections. Break the content into more named blocks.",
290
290
  jumpTo: { tab: "technical", anchorId: "anchor-headings-structure" },
291
291
  });
package/src/lib/utils.ts CHANGED
@@ -1,35 +1,35 @@
1
- // Token-based keyword match: "selinexor in myelofibrosis" still counts as containing
2
- // "selinexor myelofibrosis" because word order and connecting words don't matter.
3
- export function containsKeywordTokens(haystack: string, needle?: string): boolean {
4
- if (!needle) return true;
5
- const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
6
- if (tokens.length === 0) return true;
7
- const lower = haystack.toLowerCase();
8
- return tokens.every((t) => lower.includes(t));
9
- }
10
-
11
- // True when the primary keyword sits near the start of the slug (within the first
12
- // three slug words). Editors get the most SEO/CTR value when the keyword leads.
13
- export function keywordLeadsSlug(slug: string, primaryKeyword?: string): boolean {
14
- if (!primaryKeyword) return true;
15
- const slugWords = slug.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
16
- const tokens = primaryKeyword.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
17
- if (tokens.length === 0 || slugWords.length === 0) return true;
18
- let earliest = Infinity;
19
- for (const t of tokens) {
20
- const idx = slugWords.findIndex((w) => w.includes(t));
21
- if (idx >= 0) earliest = Math.min(earliest, idx);
22
- }
23
- return earliest <= 2;
24
- }
25
-
26
- // MJH publications that use the /view/{slug} article route (verified via CDN probe).
27
- // We only construct live URLs for known publications to avoid linking to 404s on
28
- // brands that use a different route pattern.
29
- export const KNOWN_MJH_PUBLICATIONS = new Set([
30
- "onclive",
31
- "hcplive",
32
- "ajmc",
33
- "pharmacytimes",
34
- "cancernetwork",
35
- ]);
1
+ // Token-based keyword match: "selinexor in myelofibrosis" still counts as containing
2
+ // "selinexor myelofibrosis" because word order and connecting words don't matter.
3
+ export function containsKeywordTokens(haystack: string, needle?: string): boolean {
4
+ if (!needle) return true;
5
+ const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
6
+ if (tokens.length === 0) return true;
7
+ const lower = haystack.toLowerCase();
8
+ return tokens.every((t) => lower.includes(t));
9
+ }
10
+
11
+ // True when the primary keyword sits near the start of the slug (within the first
12
+ // three slug words). Editors get the most SEO/CTR value when the keyword leads.
13
+ export function keywordLeadsSlug(slug: string, primaryKeyword?: string): boolean {
14
+ if (!primaryKeyword) return true;
15
+ const slugWords = slug.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
16
+ const tokens = primaryKeyword.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
17
+ if (tokens.length === 0 || slugWords.length === 0) return true;
18
+ let earliest = Infinity;
19
+ for (const t of tokens) {
20
+ const idx = slugWords.findIndex((w) => w.includes(t));
21
+ if (idx >= 0) earliest = Math.min(earliest, idx);
22
+ }
23
+ return earliest <= 2;
24
+ }
25
+
26
+ // MJH publications that use the /view/{slug} article route (verified via CDN probe).
27
+ // We only construct live URLs for known publications to avoid linking to 404s on
28
+ // brands that use a different route pattern.
29
+ export const KNOWN_MJH_PUBLICATIONS = new Set([
30
+ "onclive",
31
+ "hcplive",
32
+ "ajmc",
33
+ "pharmacytimes",
34
+ "cancernetwork",
35
+ ]);