sanity-plugin-seo-copilot 0.2.12 → 0.2.13
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 +203 -171
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +203 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/KeywordPanel.tsx +190 -176
- package/src/components/SEOCopilotPanel.tsx +29 -9
- package/src/components/styles.ts +7 -0
- package/src/components/tabs/AEOTab.tsx +3 -1
- package/src/hooks/useKeywordAnalysis.ts +8 -7
- package/src/lib/api.ts +3 -50
- package/src/lib/summary.ts +1 -1
package/src/lib/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SEOAnalysis, DeepAnalysis, ChatMessage, DocumentFields, ContentSuggestions,
|
|
1
|
+
import type { SEOAnalysis, DeepAnalysis, ChatMessage, DocumentFields, ContentSuggestions, LinkingSuggestion, LinkCheckResult } from "./types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Safely parse JSON from a response that may have been truncated by
|
|
@@ -30,19 +30,19 @@ export async function fetchAnalysis(
|
|
|
30
30
|
seedKeywords?: string[],
|
|
31
31
|
documentFields?: DocumentFields,
|
|
32
32
|
focusKeyword?: string,
|
|
33
|
+
secondaryKeyword?: string,
|
|
33
34
|
signal?: AbortSignal
|
|
34
35
|
): Promise<SEOAnalysis | DeepAnalysis> {
|
|
35
36
|
const response = await fetch(`${apiUrl}/api/seo-copilot/analyze`, {
|
|
36
37
|
method: "POST",
|
|
37
38
|
headers: { "Content-Type": "application/json" },
|
|
38
|
-
body: JSON.stringify({ content, mode, publication, seedKeywords, documentFields, focusKeyword }),
|
|
39
|
+
body: JSON.stringify({ content, mode, publication, seedKeywords, documentFields, focusKeyword, secondaryKeyword }),
|
|
39
40
|
signal,
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
const text = await response.text();
|
|
43
44
|
|
|
44
45
|
if (!response.ok) {
|
|
45
|
-
const err = safeParseJson<{ error?: string }>(text);
|
|
46
46
|
if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
|
|
47
47
|
if (response.status >= 500) throw new Error("Could not reach the SEO service.");
|
|
48
48
|
throw new Error("Something went wrong analyzing this document.");
|
|
@@ -74,7 +74,6 @@ export async function fetchChatStream(
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
if (!response.ok) {
|
|
77
|
-
const err = await response.json().catch(() => ({ error: "Request failed" }));
|
|
78
77
|
if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
|
|
79
78
|
if (response.status >= 500) throw new Error("Could not reach the SEO service.");
|
|
80
79
|
throw new Error("Something went wrong. Please try again.");
|
|
@@ -96,7 +95,6 @@ export async function fetchQuestions(
|
|
|
96
95
|
});
|
|
97
96
|
|
|
98
97
|
if (!response.ok) {
|
|
99
|
-
const err = await response.json().catch(() => ({ error: "Request failed" }));
|
|
100
98
|
if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
|
|
101
99
|
if (response.status >= 500) throw new Error("Could not reach the SEO service.");
|
|
102
100
|
throw new Error("Something went wrong. Please try again.");
|
|
@@ -129,7 +127,6 @@ export async function lookupKeywords(
|
|
|
129
127
|
});
|
|
130
128
|
|
|
131
129
|
if (!response.ok) {
|
|
132
|
-
const err = await response.json().catch(() => ({ error: "Request failed" }));
|
|
133
130
|
if (response.status === 429) throw new Error("Analysis service is busy. Please try again.");
|
|
134
131
|
if (response.status >= 500) throw new Error("Could not reach the SEO service.");
|
|
135
132
|
throw new Error("Something went wrong. Please try again.");
|
|
@@ -183,50 +180,6 @@ export async function fetchContentSuggestions(
|
|
|
183
180
|
}
|
|
184
181
|
}
|
|
185
182
|
|
|
186
|
-
export async function fetchInternalLinks(
|
|
187
|
-
apiUrl: string,
|
|
188
|
-
keywords: string[],
|
|
189
|
-
currentDocumentId?: string,
|
|
190
|
-
publication?: string
|
|
191
|
-
): Promise<InternalLink[]> {
|
|
192
|
-
if (!keywords || keywords.length === 0) return [];
|
|
193
|
-
try {
|
|
194
|
-
const res = await fetch(`${apiUrl}/api/seo-copilot/articles`, {
|
|
195
|
-
method: "POST",
|
|
196
|
-
headers: { "Content-Type": "application/json" },
|
|
197
|
-
body: JSON.stringify({ action: "related", keywords, publication }),
|
|
198
|
-
});
|
|
199
|
-
if (!res.ok) return [];
|
|
200
|
-
const data = await res.json().catch(() => null);
|
|
201
|
-
if (!data || typeof data !== "object") return [];
|
|
202
|
-
type ArticleResult = { _id?: string; title?: string; slug?: string; publishedAt?: string };
|
|
203
|
-
const articles: ArticleResult[] = Array.isArray(data.articles) ? data.articles : [];
|
|
204
|
-
const filtered = currentDocumentId
|
|
205
|
-
? articles.filter((a) => a._id !== currentDocumentId)
|
|
206
|
-
: articles;
|
|
207
|
-
return filtered.map((a): InternalLink => ({
|
|
208
|
-
_id: a._id,
|
|
209
|
-
title: a.title || "Untitled",
|
|
210
|
-
slug: a.slug || "",
|
|
211
|
-
publishedAt: a.publishedAt,
|
|
212
|
-
relevanceReason: matchedKeyword(a.title, keywords),
|
|
213
|
-
}));
|
|
214
|
-
} catch {
|
|
215
|
-
return [];
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function matchedKeyword(title: string | undefined, keywords: string[]): string {
|
|
220
|
-
const lower = (title || "").toLowerCase();
|
|
221
|
-
if (!lower) return "Related to current topic";
|
|
222
|
-
for (const kw of keywords) {
|
|
223
|
-
if (kw && lower.includes(kw.toLowerCase())) {
|
|
224
|
-
return `Matches "${kw}"`;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return "Related to current topic";
|
|
228
|
-
}
|
|
229
|
-
|
|
230
183
|
export async function fetchLinkingSuggestions(
|
|
231
184
|
apiUrl: string,
|
|
232
185
|
content: string,
|
package/src/lib/summary.ts
CHANGED
|
@@ -140,7 +140,7 @@ export function buildSummaryItems(input: BuildSummaryInput): SummaryItem[] {
|
|
|
140
140
|
severity: "warning",
|
|
141
141
|
label: "Meta description is short",
|
|
142
142
|
description: `Meta description is ${len} characters - below the 120-160 ideal.`,
|
|
143
|
-
howToFix: "Expand the description to 120-160 characters so
|
|
143
|
+
howToFix: "Expand the description to 120-160 characters so the full description shows in search.",
|
|
144
144
|
jumpTo: { tab: "meta", anchorId: "anchor-meta-description" },
|
|
145
145
|
});
|
|
146
146
|
} else if (len > 160) {
|