sanity-plugin-seo-copilot 0.2.15 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -50
- package/dist/index.js +841 -782
- package/dist/index.mjs +763 -704
- package/package.json +62 -64
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -3
- package/src/components/ChatPanel.tsx +0 -311
- package/src/components/ConfigContext.tsx +0 -22
- package/src/components/FeedbackButton.tsx +0 -218
- package/src/components/KeywordBadge.tsx +0 -50
- package/src/components/KeywordPanel.tsx +0 -1234
- package/src/components/OnboardingPopup.tsx +0 -108
- package/src/components/PlacementIndicators.tsx +0 -80
- package/src/components/ReportProblemButton.tsx +0 -212
- package/src/components/SEOCopilotPanel.tsx +0 -1287
- package/src/components/ScoreDonut.tsx +0 -158
- package/src/components/SeedKeywordInput.tsx +0 -128
- package/src/components/ShimmerLoader.tsx +0 -123
- package/src/components/TabBar.tsx +0 -373
- package/src/components/styles.ts +0 -158
- package/src/components/tabs/AEOTab.tsx +0 -585
- package/src/components/tabs/LinkingTab.tsx +0 -446
- package/src/components/tabs/MetaTab.tsx +0 -431
- package/src/components/tabs/SummaryTab.tsx +0 -405
- package/src/components/tabs/TechnicalTab.tsx +0 -933
- package/src/hooks/useDocumentContent.ts +0 -48
- package/src/hooks/useKeywordAnalysis.ts +0 -292
- package/src/hooks/useSEOChat.ts +0 -254
- package/src/index.ts +0 -18
- package/src/inspector.ts +0 -58
- package/src/lib/api.ts +0 -262
- package/src/lib/apiKey.ts +0 -30
- package/src/lib/documentExtract.ts +0 -422
- package/src/lib/geoAnalysis.ts +0 -122
- package/src/lib/persistence.ts +0 -69
- package/src/lib/scoring.ts +0 -197
- package/src/lib/summary.ts +0 -645
- package/src/lib/types.ts +0 -212
- package/src/lib/utils.ts +0 -35
- package/v2-incompatible.js +0 -10
package/src/lib/scoring.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import type { SEOAnalysis, DocumentFields } from "./types";
|
|
2
|
-
|
|
3
|
-
export interface ScoreComponent {
|
|
4
|
-
label: string;
|
|
5
|
-
points: number;
|
|
6
|
-
max: number;
|
|
7
|
-
detail: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface ContentScore {
|
|
11
|
-
total: number;
|
|
12
|
-
components: ScoreComponent[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Count whole-word / whole-phrase occurrences, anchored on word boundaries, so a
|
|
16
|
-
// short token like "as" or "cm" can't match inside "phase" or "cmv". Safari-safe:
|
|
17
|
-
// uses \b only (no lookbehind). The needle is regex-escaped.
|
|
18
|
-
function countWholeMatches(haystack: string, needle: string): number {
|
|
19
|
-
if (!needle) return 0;
|
|
20
|
-
const esc = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
|
-
const m = haystack.match(new RegExp(`\\b${esc}\\b`, "g"));
|
|
22
|
-
return m ? m.length : 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Client-side content score (0-100) with per-component breakdown.
|
|
27
|
-
* Mirrors backend scoring.ts.
|
|
28
|
-
*/
|
|
29
|
-
export function calculateContentScoreDetailed(content: string, analysis: SEOAnalysis, documentFields?: DocumentFields): ContentScore {
|
|
30
|
-
if (!content || !analysis) {
|
|
31
|
-
return { total: 0, components: [] };
|
|
32
|
-
}
|
|
33
|
-
const lowerContent = content.toLowerCase();
|
|
34
|
-
const words = content.split(/\s+/).filter(Boolean).length;
|
|
35
|
-
const components: ScoreComponent[] = [];
|
|
36
|
-
|
|
37
|
-
// 1. Primary keyword (up to 25)
|
|
38
|
-
const primaryTerm = (analysis.primaryKeyword?.term || "").toLowerCase();
|
|
39
|
-
if (primaryTerm) {
|
|
40
|
-
// A multi-word primary like "acoramidis ATTR-CM" almost never appears as an
|
|
41
|
-
// adjacent phrase, but if every token is in the body the keyword IS present.
|
|
42
|
-
// Try the exact phrase first; otherwise fall back to token co-occurrence (all
|
|
43
|
-
// tokens present) and use the rarest token as the concept's mention count.
|
|
44
|
-
// (This mirrors containsKeywordTokens() used by the Meta + Summary audits.)
|
|
45
|
-
const tokens = primaryTerm.split(/\s+/).filter((t) => t.length > 1);
|
|
46
|
-
const phraseCount = countWholeMatches(lowerContent, primaryTerm);
|
|
47
|
-
let occurrences = phraseCount;
|
|
48
|
-
let viaTokens = false;
|
|
49
|
-
if (phraseCount === 0 && tokens.length > 0) {
|
|
50
|
-
const counts = tokens.map((t) => countWholeMatches(lowerContent, t));
|
|
51
|
-
if (counts.every((c) => c > 0)) {
|
|
52
|
-
occurrences = Math.min(...counts);
|
|
53
|
-
viaTokens = true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const primaryWordCount = Math.max(1, primaryTerm.split(/\s+/).filter(Boolean).length);
|
|
57
|
-
let pts = 0;
|
|
58
|
-
let detail: string;
|
|
59
|
-
if (occurrences === 0) {
|
|
60
|
-
detail = `Primary keyword "${primaryTerm}" not found in content`;
|
|
61
|
-
} else {
|
|
62
|
-
pts += 12;
|
|
63
|
-
// Exact phrase: an N-word phrase appearing M times occupies M*N keyword-words.
|
|
64
|
-
// Token co-occurrence: tokens are spread through the body, so count each once.
|
|
65
|
-
const density = words > 0
|
|
66
|
-
? ((viaTokens ? occurrences : occurrences * primaryWordCount) / words) * 100
|
|
67
|
-
: 0;
|
|
68
|
-
if (density >= 0.5 && density <= 2.5) {
|
|
69
|
-
pts += 13;
|
|
70
|
-
detail = `Primary keyword present, density ${density.toFixed(2)}% (ideal range)`;
|
|
71
|
-
} else if (density < 0.5) {
|
|
72
|
-
pts += 7;
|
|
73
|
-
detail = `Primary keyword present but density only ${density.toFixed(2)}% - aim for 0.5-2.5%`;
|
|
74
|
-
} else if (viaTokens && density <= 6) {
|
|
75
|
-
// Tokens spread through the body is topical depth, not keyword stuffing.
|
|
76
|
-
pts += 11;
|
|
77
|
-
detail = `Primary keyword strongly represented (${density.toFixed(2)}%)`;
|
|
78
|
-
} else {
|
|
79
|
-
pts += 4;
|
|
80
|
-
detail = `Primary keyword over-used at ${density.toFixed(2)}% density - reduce to 0.5-2.5%`;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
components.push({ label: "Primary keyword usage", points: pts, max: 25, detail });
|
|
84
|
-
} else {
|
|
85
|
-
components.push({ label: "Primary keyword usage", points: 0, max: 25, detail: "No primary keyword identified yet" });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 2. Supporting keyword coverage (up to 25)
|
|
89
|
-
const supportingKws = analysis.supportingKeywords || [];
|
|
90
|
-
if (supportingKws.length > 0) {
|
|
91
|
-
const inContentCount = supportingKws.filter((kw) => kw != null && typeof kw.term === "string" && lowerContent.includes(kw.term.toLowerCase())).length;
|
|
92
|
-
const coverageRatio = inContentCount / supportingKws.length;
|
|
93
|
-
const pts = Math.round(coverageRatio * 25);
|
|
94
|
-
components.push({
|
|
95
|
-
label: "Supporting keyword coverage",
|
|
96
|
-
points: pts,
|
|
97
|
-
max: 25,
|
|
98
|
-
detail: `${inContentCount} of ${supportingKws.length} supporting keywords present (${Math.round(coverageRatio * 100)}%)`,
|
|
99
|
-
});
|
|
100
|
-
} else {
|
|
101
|
-
components.push({ label: "Supporting keyword coverage", points: 0, max: 25, detail: "No supporting keywords yet" });
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 3. Word count (up to 15)
|
|
105
|
-
// 450 is the body-text floor. 1,500+ is the competitive target for HCP clinical articles.
|
|
106
|
-
let wcPts = 0;
|
|
107
|
-
let wcDetail: string;
|
|
108
|
-
if (words >= 1500) {
|
|
109
|
-
wcPts = 15;
|
|
110
|
-
wcDetail = `${words} words - strong length for clinical content`;
|
|
111
|
-
} else if (words >= 450) {
|
|
112
|
-
wcPts = 11;
|
|
113
|
-
wcDetail = `${words} words - above the 450 floor; 1,500+ is the clinical target`;
|
|
114
|
-
} else if (words >= 200) {
|
|
115
|
-
wcPts = 5;
|
|
116
|
-
wcDetail = `${words} words - below the 450-word floor`;
|
|
117
|
-
} else {
|
|
118
|
-
wcDetail = `${words} words - start writing`;
|
|
119
|
-
}
|
|
120
|
-
components.push({ label: "Word count", points: wcPts, max: 15, detail: wcDetail });
|
|
121
|
-
|
|
122
|
-
// 4. Heading structure (up to 10)
|
|
123
|
-
// Prefer the structured heading data the plugin extracts from Portable Text.
|
|
124
|
-
// The plain `content` string has no markup, so regexing it for #/<h3> always
|
|
125
|
-
// misses real headings - fall back to the regex only for plain-text callers.
|
|
126
|
-
let hasH1orTitle: boolean;
|
|
127
|
-
let hasSubheadings: boolean;
|
|
128
|
-
if (documentFields) {
|
|
129
|
-
hasH1orTitle = !!(documentFields.title && documentFields.title.trim());
|
|
130
|
-
const det = documentFields.headingsDetailed;
|
|
131
|
-
// Any H2+ heading counts as a subheading. Fall back to the flat heading list
|
|
132
|
-
// when the detailed list is absent OR empty, so a real outline is never missed.
|
|
133
|
-
const detHasSub = Array.isArray(det) && det.some((h) => h.level >= 2);
|
|
134
|
-
hasSubheadings = detHasSub || (documentFields.headings?.length || 0) > 0;
|
|
135
|
-
} else {
|
|
136
|
-
hasH1orTitle = /^#\s|<h1/im.test(content);
|
|
137
|
-
hasSubheadings = /^##\s|^###\s|<h2|<h3/im.test(content);
|
|
138
|
-
}
|
|
139
|
-
const structurePts = (hasH1orTitle ? 5 : 0) + (hasSubheadings ? 5 : 0);
|
|
140
|
-
const structureDetail = !hasH1orTitle && !hasSubheadings
|
|
141
|
-
? "No title or subheadings detected"
|
|
142
|
-
: !hasSubheadings
|
|
143
|
-
? "Has a title but no H2/H3 subheadings - add section headings"
|
|
144
|
-
: !hasH1orTitle
|
|
145
|
-
? "Has subheadings but no title"
|
|
146
|
-
: "Title and subheadings present";
|
|
147
|
-
components.push({ label: "Heading structure", points: structurePts, max: 10, detail: structureDetail });
|
|
148
|
-
|
|
149
|
-
// 5. Missing keyword coverage (up to 15)
|
|
150
|
-
const missingCount = (analysis.missingKeywords || []).length;
|
|
151
|
-
let mPts = 0;
|
|
152
|
-
let mDetail: string;
|
|
153
|
-
if (missingCount === 0) {
|
|
154
|
-
mPts = 15;
|
|
155
|
-
mDetail = "No missing keywords flagged";
|
|
156
|
-
} else if (missingCount <= 2) {
|
|
157
|
-
mPts = 10;
|
|
158
|
-
mDetail = `${missingCount} suggested keywords missing - quick add`;
|
|
159
|
-
} else if (missingCount <= 4) {
|
|
160
|
-
mPts = 5;
|
|
161
|
-
mDetail = `${missingCount} suggested keywords missing`;
|
|
162
|
-
} else {
|
|
163
|
-
mDetail = `${missingCount} suggested keywords missing - significant gaps`;
|
|
164
|
-
}
|
|
165
|
-
components.push({ label: "Missing keyword gap", points: mPts, max: 15, detail: mDetail });
|
|
166
|
-
|
|
167
|
-
// 6. AEO signals (up to 10) - question-format headings that Google answer
|
|
168
|
-
// features and AI engines surface directly. (FAQ scoring removed May 2026 after
|
|
169
|
-
// Google sunset FAQ rich results - question headings are the modern equivalent.)
|
|
170
|
-
// Detect from the structured heading list (plain `content` has no heading
|
|
171
|
-
// markup to regex). Single clean tier: 0 / 4 / 7 / 10 for 0 / 1 / 2 / 3+.
|
|
172
|
-
let qCount: number;
|
|
173
|
-
if (documentFields) {
|
|
174
|
-
qCount = (documentFields.headings || []).filter((h) => h.trim().endsWith("?")).length;
|
|
175
|
-
} else {
|
|
176
|
-
qCount = (content.match(/^#{1,6}\s+.*\?$/gm) || []).length + (content.match(/<h[1-6][^>]*>.*\?<\/h[1-6]>/gi) || []).length;
|
|
177
|
-
}
|
|
178
|
-
let aeoPts = 0;
|
|
179
|
-
if (qCount >= 3) aeoPts = 10;
|
|
180
|
-
else if (qCount === 2) aeoPts = 7;
|
|
181
|
-
else if (qCount === 1) aeoPts = 4;
|
|
182
|
-
const aeoDetail =
|
|
183
|
-
qCount === 0
|
|
184
|
-
? "No question-style headings - AI answer engines favor them"
|
|
185
|
-
: `${qCount} question heading${qCount === 1 ? "" : "s"}`;
|
|
186
|
-
components.push({ label: "AEO signals", points: aeoPts, max: 10, detail: aeoDetail });
|
|
187
|
-
|
|
188
|
-
const total = components.reduce((sum, c) => sum + c.points, 0);
|
|
189
|
-
return { total: Math.min(100, Math.max(0, total)), components };
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Backward-compatible: returns just the numeric score.
|
|
194
|
-
*/
|
|
195
|
-
export function calculateContentScore(content: string, analysis: SEOAnalysis): number {
|
|
196
|
-
return calculateContentScoreDetailed(content, analysis).total;
|
|
197
|
-
}
|