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
package/src/lib/scoring.ts
CHANGED
|
@@ -12,6 +12,16 @@ export interface ContentScore {
|
|
|
12
12
|
components: ScoreComponent[];
|
|
13
13
|
}
|
|
14
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
|
+
|
|
15
25
|
/**
|
|
16
26
|
* Client-side content score (0-100) with per-component breakdown.
|
|
17
27
|
* Mirrors backend scoring.ts.
|
|
@@ -27,27 +37,44 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
27
37
|
// 1. Primary keyword (up to 25)
|
|
28
38
|
const primaryTerm = (analysis.primaryKeyword?.term || "").toLowerCase();
|
|
29
39
|
if (primaryTerm) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
56
|
const primaryWordCount = Math.max(1, primaryTerm.split(/\s+/).filter(Boolean).length);
|
|
38
57
|
let pts = 0;
|
|
39
58
|
let detail: string;
|
|
40
|
-
if (
|
|
59
|
+
if (occurrences === 0) {
|
|
41
60
|
detail = `Primary keyword "${primaryTerm}" not found in content`;
|
|
42
61
|
} else {
|
|
43
62
|
pts += 12;
|
|
44
|
-
|
|
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;
|
|
45
68
|
if (density >= 0.5 && density <= 2.5) {
|
|
46
69
|
pts += 13;
|
|
47
70
|
detail = `Primary keyword present, density ${density.toFixed(2)}% (ideal range)`;
|
|
48
71
|
} else if (density < 0.5) {
|
|
49
72
|
pts += 7;
|
|
50
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)}%)`;
|
|
51
78
|
} else {
|
|
52
79
|
pts += 4;
|
|
53
80
|
detail = `Primary keyword over-used at ${density.toFixed(2)}% density - reduce to 0.5-2.5%`;
|
|
@@ -61,7 +88,7 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
61
88
|
// 2. Supporting keyword coverage (up to 25)
|
|
62
89
|
const supportingKws = analysis.supportingKeywords || [];
|
|
63
90
|
if (supportingKws.length > 0) {
|
|
64
|
-
const inContentCount = supportingKws.filter((kw) => lowerContent.includes(kw.term.toLowerCase())).length;
|
|
91
|
+
const inContentCount = supportingKws.filter((kw) => kw != null && typeof kw.term === "string" && lowerContent.includes(kw.term.toLowerCase())).length;
|
|
65
92
|
const coverageRatio = inContentCount / supportingKws.length;
|
|
66
93
|
const pts = Math.round(coverageRatio * 25);
|
|
67
94
|
components.push({
|
|
@@ -101,9 +128,10 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
101
128
|
if (documentFields) {
|
|
102
129
|
hasH1orTitle = !!(documentFields.title && documentFields.title.trim());
|
|
103
130
|
const det = documentFields.headingsDetailed;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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;
|
|
107
135
|
} else {
|
|
108
136
|
hasH1orTitle = /^#\s|<h1/im.test(content);
|
|
109
137
|
hasSubheadings = /^##\s|^###\s|<h2|<h3/im.test(content);
|
|
@@ -145,8 +173,7 @@ export function calculateContentScoreDetailed(content: string, analysis: SEOAnal
|
|
|
145
173
|
if (documentFields) {
|
|
146
174
|
qCount = (documentFields.headings || []).filter((h) => h.trim().endsWith("?")).length;
|
|
147
175
|
} else {
|
|
148
|
-
|
|
149
|
-
qCount = questionHeadings?.length || 0;
|
|
176
|
+
qCount = (content.match(/^#{1,6}\s+.*\?$/gm) || []).length + (content.match(/<h[1-6][^>]*>.*\?<\/h[1-6]>/gi) || []).length;
|
|
150
177
|
}
|
|
151
178
|
let aeoPts = 0;
|
|
152
179
|
if (qCount >= 3) aeoPts = 10;
|
package/src/lib/summary.ts
CHANGED
|
@@ -21,24 +21,28 @@ interface BuildSummaryInput {
|
|
|
21
21
|
// When non-empty, broken/errored entries surface here as their own issue.
|
|
22
22
|
linkCheckResults?: LinkCheckResult[];
|
|
23
23
|
text: string;
|
|
24
|
+
// The editor's SELECTED primary keyword (effectivePrimary). Falls back to the
|
|
25
|
+
// analysis' top candidate when not supplied.
|
|
26
|
+
primaryKeyword?: string;
|
|
27
|
+
// Optional secondary target keyword - items flag where it's missing.
|
|
28
|
+
secondaryKeyword?: string;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
if (!needle) return true;
|
|
28
|
-
const tokens = needle.toLowerCase().split(/\s+/).filter((t) => t.length > 1);
|
|
29
|
-
if (tokens.length === 0) return true;
|
|
30
|
-
const lower = haystack.toLowerCase();
|
|
31
|
-
return tokens.every((t) => lower.includes(t));
|
|
32
|
-
}
|
|
31
|
+
import { containsKeywordTokens, keywordLeadsSlug } from "./utils";
|
|
33
32
|
|
|
34
33
|
// Conference previews, news briefs, recaps, and listicles are legitimately short.
|
|
35
34
|
// Detect them so we don't nag "push past 1,500 words" on content that should be
|
|
36
35
|
// short. Uses the contentCategory field when present, else title-pattern signals.
|
|
37
|
-
function isShortFormContent(documentFields?: DocumentFields, title?: string): boolean {
|
|
38
|
-
|
|
39
|
-
//
|
|
36
|
+
export function isShortFormContent(documentFields?: DocumentFields, title?: string): boolean {
|
|
37
|
+
const cat = (documentFields?.contentCategory || "").toLowerCase().trim();
|
|
38
|
+
// Media formats (video / podcast / episode / webinar): the body text is a summary
|
|
39
|
+
// of the media, not the article. Match the category AS A WHOLE so a written piece
|
|
40
|
+
// in a compound category like "clinical video interviews" is NOT exempted.
|
|
41
|
+
if (/^(videos?|podcasts?|episodes?|webinars?|video series|peer exchange)$/.test(cat)) return true;
|
|
42
|
+
// Written short formats - token match (not substring) so "newsletter" doesn't match
|
|
43
|
+
// "news" and "updated-guidelines" doesn't match "update".
|
|
40
44
|
const shortFormCats = new Set(["news", "brief", "preview", "recap", "update", "announcement", "roundup", "digest", "interview"]);
|
|
41
|
-
const catTokens =
|
|
45
|
+
const catTokens = cat.split(/[^a-z]+/).filter(Boolean);
|
|
42
46
|
if (catTokens.some((tok) => shortFormCats.has(tok))) return true;
|
|
43
47
|
const t = (title || "").toLowerCase();
|
|
44
48
|
if (/\b(preview|recap|roundup|digest)\b/.test(t)) return true;
|
|
@@ -51,7 +55,18 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
51
55
|
// contentScore is in BuildSummaryInput for forward-compat but is now shown
|
|
52
56
|
// directly on the Summary tab as a card with breakdown - no echo item needed here.
|
|
53
57
|
const { analysis, deepAnalysis, documentFields, linkingSuggestions, linkCheckResults, text } = input;
|
|
54
|
-
const primaryKeyword = analysis?.primaryKeyword?.term;
|
|
58
|
+
const primaryKeyword = input.primaryKeyword || analysis?.primaryKeyword?.term;
|
|
59
|
+
const secondaryKeyword = input.secondaryKeyword || "";
|
|
60
|
+
// Body-only text: useDocumentContent prepends the document title so the AI
|
|
61
|
+
// analysis includes it, but word-count and keyword-in-body checks must not
|
|
62
|
+
// count the title as body content. Strip the title prefix when present.
|
|
63
|
+
const bodyText = (() => {
|
|
64
|
+
if (!documentFields?.title) return text;
|
|
65
|
+
if (!text.startsWith(documentFields.title)) return text;
|
|
66
|
+
const rest = text.slice(documentFields.title.length);
|
|
67
|
+
if (rest === "" || /^\s/.test(rest)) return rest.trimStart();
|
|
68
|
+
return text;
|
|
69
|
+
})();
|
|
55
70
|
|
|
56
71
|
// ---------- META: title ----------
|
|
57
72
|
// Length warnings removed - the article title IS the page title and editors
|
|
@@ -70,7 +85,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
70
85
|
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
71
86
|
});
|
|
72
87
|
} else if (primaryKeyword) {
|
|
73
|
-
if (!
|
|
88
|
+
if (!containsKeywordTokens(title, primaryKeyword)) {
|
|
74
89
|
items.push({
|
|
75
90
|
id: "meta-title-no-keyword",
|
|
76
91
|
category: "meta",
|
|
@@ -139,7 +154,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
139
154
|
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
140
155
|
});
|
|
141
156
|
}
|
|
142
|
-
if (primaryKeyword && !
|
|
157
|
+
if (primaryKeyword && !containsKeywordTokens(meta, primaryKeyword)) {
|
|
143
158
|
items.push({
|
|
144
159
|
id: "meta-desc-no-keyword",
|
|
145
160
|
category: "meta",
|
|
@@ -152,39 +167,41 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
152
167
|
}
|
|
153
168
|
}
|
|
154
169
|
|
|
155
|
-
// ----------
|
|
170
|
+
// ---------- URL slug (lives on the Other Recs tab) ----------
|
|
171
|
+
// No character-count nag and no "too long" - just scan for the primary keyword,
|
|
172
|
+
// ideally leading the URL. Keep the guidance vague (short + descriptive).
|
|
156
173
|
const slug = documentFields?.slug;
|
|
157
174
|
if (!slug) {
|
|
158
175
|
items.push({
|
|
159
176
|
id: "meta-slug-missing",
|
|
160
177
|
category: "meta",
|
|
161
|
-
severity: "
|
|
178
|
+
severity: "warning",
|
|
162
179
|
label: "URL slug missing",
|
|
163
180
|
description: "No URL slug set.",
|
|
164
|
-
howToFix: "Add a
|
|
165
|
-
jumpTo: { tab: "
|
|
181
|
+
howToFix: "Add a short, descriptive slug that leads with your primary keyword.",
|
|
182
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
166
183
|
});
|
|
167
184
|
} else {
|
|
168
|
-
|
|
185
|
+
const slugAsWords = slug.replace(/-/g, " ");
|
|
186
|
+
if (primaryKeyword && !containsKeywordTokens(slugAsWords, primaryKeyword)) {
|
|
169
187
|
items.push({
|
|
170
|
-
id: "meta-slug-
|
|
188
|
+
id: "meta-slug-no-keyword",
|
|
171
189
|
category: "meta",
|
|
172
|
-
severity: "
|
|
173
|
-
label: "
|
|
174
|
-
description: `
|
|
175
|
-
howToFix: "
|
|
176
|
-
jumpTo: { tab: "
|
|
190
|
+
severity: "opportunity",
|
|
191
|
+
label: "Primary keyword not in URL",
|
|
192
|
+
description: `The URL doesn't include "${primaryKeyword}".`,
|
|
193
|
+
howToFix: "Work the primary keyword into the URL, ideally at the start. Keep the URL short and descriptive.",
|
|
194
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
177
195
|
});
|
|
178
|
-
}
|
|
179
|
-
if (primaryKeyword && !tokensContain(slug.replace(/-/g, " "), primaryKeyword)) {
|
|
196
|
+
} else if (primaryKeyword && !keywordLeadsSlug(slug, primaryKeyword)) {
|
|
180
197
|
items.push({
|
|
181
|
-
id: "meta-slug-
|
|
198
|
+
id: "meta-slug-keyword-late",
|
|
182
199
|
category: "meta",
|
|
183
200
|
severity: "opportunity",
|
|
184
|
-
label: "Primary keyword
|
|
185
|
-
description: `
|
|
186
|
-
howToFix: "
|
|
187
|
-
jumpTo: { tab: "
|
|
201
|
+
label: "Primary keyword late in URL",
|
|
202
|
+
description: `"${primaryKeyword}" is in the URL but not near the start.`,
|
|
203
|
+
howToFix: "Lead the URL with the primary keyword so it stays visible if the address gets shortened.",
|
|
204
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
188
205
|
});
|
|
189
206
|
}
|
|
190
207
|
}
|
|
@@ -192,10 +209,13 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
192
209
|
// ---------- CONTENT: word count ----------
|
|
193
210
|
// 450 is the body-text floor (per editor guidance). 1,500+ is the competitive
|
|
194
211
|
// target for HCP clinical articles.
|
|
195
|
-
const wordCount =
|
|
212
|
+
const wordCount = bodyText ? bodyText.trim().split(/\s+/).filter(Boolean).length : 0;
|
|
213
|
+
// Videos, podcasts, news, briefs, etc. are legitimately short (the body is a
|
|
214
|
+
// summary, not the deliverable), so they're exempt from the word-count floor.
|
|
215
|
+
const isShortForm = isShortFormContent(documentFields, title);
|
|
196
216
|
if (wordCount === 0) {
|
|
197
217
|
// No item - empty doc state is handled by the empty-state UI elsewhere
|
|
198
|
-
} else if (wordCount < 450) {
|
|
218
|
+
} else if (wordCount < 450 && !isShortForm) {
|
|
199
219
|
items.push({
|
|
200
220
|
id: "content-too-short",
|
|
201
221
|
category: "content",
|
|
@@ -205,7 +225,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
205
225
|
howToFix: "Add more body text. A link or image on its own doesn't count - the article needs real written substance.",
|
|
206
226
|
jumpTo: { tab: "technical", anchorId: "anchor-word-count" },
|
|
207
227
|
});
|
|
208
|
-
} else if (wordCount < 1500 && !
|
|
228
|
+
} else if (wordCount < 1500 && !isShortForm) {
|
|
209
229
|
items.push({
|
|
210
230
|
id: "content-short-for-clinical",
|
|
211
231
|
category: "content",
|
|
@@ -227,7 +247,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
227
247
|
const h2Count = headingsDetailed
|
|
228
248
|
? headingsDetailed.filter((h) => h.level === 2 || h.level === 3).length
|
|
229
249
|
: headings.length;
|
|
230
|
-
if (
|
|
250
|
+
if (h2Count === 0 && wordCount > 200 && wordCount < 1000) {
|
|
231
251
|
items.push({
|
|
232
252
|
id: "headings-missing",
|
|
233
253
|
category: "headings",
|
|
@@ -340,7 +360,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
340
360
|
if (GENERIC_FN_RE.test(base)) return true;
|
|
341
361
|
if (/_/.test(base) || /\s/.test(base)) return true;
|
|
342
362
|
const words = base.split("-").filter(Boolean);
|
|
343
|
-
return words.length < 2 || words.length >
|
|
363
|
+
return words.length < 2 || words.length > 5;
|
|
344
364
|
});
|
|
345
365
|
if (badFilenames.length > 0) {
|
|
346
366
|
items.push({
|
|
@@ -358,7 +378,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
358
378
|
if (!trimmed) return false;
|
|
359
379
|
const len = trimmed.length;
|
|
360
380
|
const wc = trimmed.split(/\s+/).filter(Boolean).length;
|
|
361
|
-
return len
|
|
381
|
+
return len >= 125 || wc < 2;
|
|
362
382
|
});
|
|
363
383
|
if (badAlts.length > 0) {
|
|
364
384
|
items.push({
|
|
@@ -374,7 +394,11 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
374
394
|
// Image titles (the hover tooltip) - the director treats this as an SEO signal.
|
|
375
395
|
const imageTitleCount = (documentFields?.imageTitles || []).length;
|
|
376
396
|
const totalImageCount = documentFields?.imageCount ?? 0;
|
|
377
|
-
|
|
397
|
+
// Only flag missing titles when SOME image already has one (i.e. the schema
|
|
398
|
+
// actually exposes a title field). MJH combines alt + title into a single
|
|
399
|
+
// "Image ALT/Title Text" field, so imageTitleCount is always 0 there - flagging
|
|
400
|
+
// every image as "missing a title" was a false alarm. Mirrors TechnicalTab's skip.
|
|
401
|
+
const missingTitles = totalImageCount > 0 && imageTitleCount > 0 ? totalImageCount - imageTitleCount : 0;
|
|
378
402
|
if (missingTitles > 0) {
|
|
379
403
|
items.push({
|
|
380
404
|
id: "images-titles-missing",
|
|
@@ -392,7 +416,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
392
416
|
// Keywords haven't loaded - skip
|
|
393
417
|
} else {
|
|
394
418
|
// If primary is missing from body, flag it
|
|
395
|
-
if (
|
|
419
|
+
if (bodyText && !containsKeywordTokens(bodyText, primaryKeyword)) {
|
|
396
420
|
items.push({
|
|
397
421
|
id: "keywords-primary-not-in-body",
|
|
398
422
|
category: "keywords",
|
|
@@ -407,7 +431,10 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
407
431
|
// analysis has fetched real SEMrush volumes (realtime leaves volume null), so
|
|
408
432
|
// gate on deepAnalysis to avoid false warnings mid-typing.
|
|
409
433
|
const primaryVolume = analysis?.primaryKeyword?.volume;
|
|
410
|
-
|
|
434
|
+
// Only an explicit measured zero means "nobody searches this". A null volume
|
|
435
|
+
// means SEMrush simply had no data for the term (common for niche clinical
|
|
436
|
+
// phrases) - warning on null produced false positives, so we don't.
|
|
437
|
+
if (deepAnalysis && primaryVolume === 0) {
|
|
411
438
|
items.push({
|
|
412
439
|
id: "keywords-primary-zero-volume",
|
|
413
440
|
category: "keywords",
|
|
@@ -420,6 +447,59 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
420
447
|
}
|
|
421
448
|
}
|
|
422
449
|
|
|
450
|
+
// ---------- SECONDARY KEYWORD COVERAGE ----------
|
|
451
|
+
// When the editor has chosen an optional secondary keyword, flag the spots it's
|
|
452
|
+
// missing from so the "primary in, secondary out" gaps are visible at a glance.
|
|
453
|
+
if (secondaryKeyword) {
|
|
454
|
+
if (bodyText && !containsKeywordTokens(bodyText, secondaryKeyword)) {
|
|
455
|
+
items.push({
|
|
456
|
+
id: "secondary-not-in-body",
|
|
457
|
+
category: "keywords",
|
|
458
|
+
severity: "opportunity",
|
|
459
|
+
label: "Secondary keyword not in body",
|
|
460
|
+
description: `Your secondary keyword "${secondaryKeyword}" doesn't appear in the article body.`,
|
|
461
|
+
howToFix: "Work the secondary keyword into a body paragraph or two where it reads naturally.",
|
|
462
|
+
jumpTo: { tab: "keywords" },
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
const titleVal = documentFields?.title;
|
|
466
|
+
if (titleVal && !containsKeywordTokens(titleVal, secondaryKeyword)) {
|
|
467
|
+
items.push({
|
|
468
|
+
id: "secondary-not-in-title",
|
|
469
|
+
category: "meta",
|
|
470
|
+
severity: "opportunity",
|
|
471
|
+
label: "Secondary keyword not in title",
|
|
472
|
+
description: `The title doesn't include your secondary keyword "${secondaryKeyword}".`,
|
|
473
|
+
howToFix: "If it fits naturally, include the secondary keyword in the title too - but never at the cost of the primary leading.",
|
|
474
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-title" },
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
const metaVal = documentFields?.metaDescription;
|
|
478
|
+
if (metaVal && !containsKeywordTokens(metaVal, secondaryKeyword)) {
|
|
479
|
+
items.push({
|
|
480
|
+
id: "secondary-not-in-meta",
|
|
481
|
+
category: "meta",
|
|
482
|
+
severity: "opportunity",
|
|
483
|
+
label: "Secondary keyword not in meta description",
|
|
484
|
+
description: `The meta description doesn't include "${secondaryKeyword}".`,
|
|
485
|
+
howToFix: "Add the secondary keyword to the meta description if it reads naturally.",
|
|
486
|
+
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
const slugVal = documentFields?.slug;
|
|
490
|
+
if (slugVal && !containsKeywordTokens(slugVal.replace(/-/g, " "), secondaryKeyword)) {
|
|
491
|
+
items.push({
|
|
492
|
+
id: "secondary-not-in-url",
|
|
493
|
+
category: "meta",
|
|
494
|
+
severity: "opportunity",
|
|
495
|
+
label: "Secondary keyword not in URL",
|
|
496
|
+
description: `The URL doesn't include "${secondaryKeyword}".`,
|
|
497
|
+
howToFix: "Optionally include the secondary keyword in the URL after the primary - only if the slug stays short and clean.",
|
|
498
|
+
jumpTo: { tab: "technical", anchorId: "anchor-url-slug" },
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
423
503
|
// ---------- CONTENT SCORE ----------
|
|
424
504
|
// The score itself is shown as a card at the top of the Summary tab with a
|
|
425
505
|
// visible per-component breakdown, so we DON'T echo it here as a separate
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +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
|
+
]);
|