@tangen/ext-seo 0.0.0-stage → 0.2.1

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.
Files changed (56) hide show
  1. package/package.json +55 -4
  2. package/src/client.ts +48 -0
  3. package/src/components/SeoPanel.tsx +489 -0
  4. package/src/contract.ts +269 -0
  5. package/src/hooks.ts +74 -0
  6. package/src/index.ts +41 -0
  7. package/src/lib/alt-text.ts +59 -0
  8. package/src/lib/analytics.ts +236 -0
  9. package/src/lib/canonical.ts +87 -0
  10. package/src/lib/deployment-role.ts +18 -0
  11. package/src/lib/health-report.ts +93 -0
  12. package/src/lib/llms.ts +55 -0
  13. package/src/lib/metadata.ts +268 -0
  14. package/src/lib/not-found.ts +83 -0
  15. package/src/lib/object-url.ts +83 -0
  16. package/src/lib/optimize.ts +77 -0
  17. package/src/lib/redirects-csv.ts +84 -0
  18. package/src/lib/redirects.ts +178 -0
  19. package/src/lib/resolve.ts +157 -0
  20. package/src/lib/robots.ts +76 -0
  21. package/src/lib/schema-map.ts +66 -0
  22. package/src/lib/schemas.ts +114 -0
  23. package/src/lib/seo-analysis.ts +185 -0
  24. package/src/lib/seo-manager-nav.ts +72 -0
  25. package/src/lib/settings.ts +167 -0
  26. package/src/lib/sitemap-report.ts +38 -0
  27. package/src/lib/sitemap.ts +109 -0
  28. package/src/lib/structured-data.ts +93 -0
  29. package/src/lib/titles.ts +109 -0
  30. package/src/nextjs.ts +70 -0
  31. package/src/pages/AiGeoTab.tsx +78 -0
  32. package/src/pages/AnalyticsTab.tsx +192 -0
  33. package/src/pages/GeoTab.tsx +76 -0
  34. package/src/pages/NotFoundTab.tsx +120 -0
  35. package/src/pages/SchemasTab.tsx +134 -0
  36. package/src/pages/SeoManagerPage.tsx +329 -0
  37. package/src/pages/SettingsTab.tsx +298 -0
  38. package/src/pages/SitemapTab.tsx +51 -0
  39. package/src/pages/TitlesTab.tsx +326 -0
  40. package/src/pages/ToolsTab.tsx +142 -0
  41. package/src/pages/manager-pages.tsx +46 -0
  42. package/src/pages/redirects.tsx +411 -0
  43. package/src/server/analytics-read.ts +51 -0
  44. package/src/server/analytics-sync.ts +182 -0
  45. package/src/server/artifacts.ts +305 -0
  46. package/src/server/health.ts +97 -0
  47. package/src/server/not-found-store.ts +71 -0
  48. package/src/server/optimize.ts +75 -0
  49. package/src/server/redirect-store.ts +128 -0
  50. package/src/server/routes.ts +604 -0
  51. package/src/server/search-console.ts +148 -0
  52. package/src/server/sitemap-source.ts +153 -0
  53. package/src/server/titles.ts +88 -0
  54. package/src/server.ts +47 -0
  55. package/tangen.extension.ts +153 -0
  56. package/README.md +0 -3
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@tangen/ext-seo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "description": "Production SEO for a Tangen site: metadata, canonical URLs, robots, sitemaps, redirects and structured data",
5
+ "homepage": "https://github.com/raghunathj/tangen#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/raghunathj/tangen/issues"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/raghunathj/tangen.git",
13
+ "directory": "extensions/seo"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "!**/__tests__/**",
18
+ "!**/*.test.ts",
19
+ "tangen.extension.ts"
20
+ ],
21
+ "main": "./src/index.ts",
22
+ "types": "./src/index.ts",
23
+ "exports": {
24
+ ".": "./src/index.ts",
25
+ "./tangen.extension": "./tangen.extension.ts",
26
+ "./hooks": "./src/hooks.ts",
27
+ "./server": "./src/server.ts",
28
+ "./contract": "./src/contract.ts",
29
+ "./client": "./src/client.ts",
30
+ "./nextjs": "./src/nextjs.ts"
31
+ },
32
+ "scripts": {
33
+ "test": "bun test"
34
+ },
35
+ "peerDependencies": {
36
+ "@tangen/cms": "*",
37
+ "@tangen/icons": "*",
38
+ "@tangen/ui": "*",
39
+ "react": "*",
40
+ "@tangen/sdk": "*"
41
+ },
42
+ "dependencies": {
43
+ "clsx": "^2.1.1"
44
+ },
45
+ "devDependencies": {
46
+ "@tangen/cms": "^0.2.1",
47
+ "@tangen/extension-testkit": "0.2.0",
48
+ "@tangen/ui": "^0.2.1",
49
+ "@types/react": "^18.3.3",
50
+ "clsx": "^2.1.1",
51
+ "bun-types": "^1.1.0",
52
+ "react": "^18.3.1",
53
+ "@tangen/icons": "^0.0.26",
54
+ "react-router-dom": "^7.18.0",
55
+ "@tangen/sdk": "^0.1.45"
56
+ }
57
+ }
package/src/client.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * File Name: client.ts
3
+ * Purpose: The SEO extension's OWN client SDK (plan-seo-next Phase 6). A Tangen
4
+ * SDK plugin - the site mounts it with
5
+ * `createClient({ plugins: [seoPlugin] })` and calls
6
+ * `client.seo.resolve(type, id, locale)`. It uses only the generic
7
+ * `http` transport the seam hands it, so nothing SEO-specific lives in
8
+ * the core SDK. Published data only, keyed off the client's API key.
9
+ *
10
+ * Author: Raghunath J
11
+ * License: MIT
12
+ *
13
+ * Dependencies/Notes: @tangen/sdk is a peer dependency - the consuming site
14
+ * already has it. Import only the plugin seam, never core internals.
15
+ */
16
+ import { defineClientPlugin, TangenError } from '@tangen/sdk'
17
+ import type { ResolvedSeo } from './contract'
18
+
19
+ export interface SeoClientApi {
20
+ /**
21
+ * The resolved SEO for one object, precedence already applied. `{ data: null }`
22
+ * when the object has no published SEO. Pass a locale for a localized site.
23
+ */
24
+ resolve(type: string, id: string, locale?: string): Promise<{ data: ResolvedSeo | null }>
25
+ /**
26
+ * Every enabled redirect, resolved to a URL - what a site needs to build its
27
+ * own redirect map (a Next.js `redirects()`, an edge middleware) instead of
28
+ * asking per request. A destination the app cannot place is left out.
29
+ */
30
+ redirects(): Promise<{ data: Array<{ from: string; to: string; status: 301 | 302 }> }>
31
+ }
32
+
33
+ /** The SEO client SDK, mounted at `client.seo`. */
34
+ export const seoPlugin = defineClientPlugin('seo', ({ http }): SeoClientApi => ({
35
+ async resolve(type, id, locale) {
36
+ const q = new URLSearchParams({ type, id, ...(locale ? { locale } : {}) })
37
+ try {
38
+ return (await http.get(`/ext/seo/resolve?${q.toString()}`)) as { data: ResolvedSeo }
39
+ } catch (e) {
40
+ // A 404 (no published SEO for this object) is a normal answer, not an error.
41
+ if (e instanceof TangenError && e.status === 404) return { data: null }
42
+ throw e
43
+ }
44
+ },
45
+ async redirects() {
46
+ return (await http.get('/ext/seo/redirects.json')) as { data: Array<{ from: string; to: string; status: 301 | 302 }> }
47
+ },
48
+ }))
@@ -0,0 +1,489 @@
1
+ 'use client'
2
+
3
+ import { useState, useMemo, useEffect, useRef } from 'react'
4
+ import { clsx } from 'clsx'
5
+ import { Accordion, AccordionItem, AccordionTrigger, AccordionContent, Button, Input, Textarea, Tabs, TabsList, TabsTrigger } from '@tangen/ui'
6
+ import { IconSparkles } from '@tangen/icons'
7
+ import { adminFetch, toast } from '@/kit'
8
+ import {
9
+ analyzeTitleLength, analyzeMetaDescLength,
10
+ analyzeKeywordInTitle, analyzeKeywordInMetaDesc,
11
+ analyzeKeywordDensity, analyzeReadability,
12
+ computeOverallScore,
13
+ type SeoCheck, type SeoScore,
14
+ } from '../lib/seo-analysis'
15
+ import { panelToScopedFull, scopedToPanelFull } from '../lib/metadata'
16
+ import type { SeoPanelFields, SeoPanelLocaleFields } from '../lib/metadata'
17
+
18
+ export interface SeoPanelProps {
19
+ title?: string
20
+ content?: string
21
+ ai?: { available: boolean; fill: (instruction: string) => Promise<string>; openAssistant?: () => void }
22
+ fieldValues?: Record<string, unknown>
23
+ objectUrl?: string
24
+ /** The object's id ('' on the /new editor): what the alt-text route describes the share image of (S3). */
25
+ objectId?: string
26
+ /**
27
+ * Pre-loaded panel data from app_data (focusKeyword, seoTitle, metaDescription).
28
+ * The editor fetches this on load and passes it here.
29
+ */
30
+ panelData?: Record<string, unknown>
31
+ /**
32
+ * Called whenever the user changes a SEO field. The editor batches these
33
+ * and sends them as __seoPanelData on the next save so the hook can persist them.
34
+ */
35
+ onPanelDataChange?: (data: Record<string, unknown>) => void
36
+ /** The locale the editor is working in; the default locale (or unset) means the base. */
37
+ activeLocale?: string | null
38
+ /** The workspace's configured locales; a switcher shows when there is more than one. */
39
+ locales?: { code: string; label: string }[]
40
+ /** The default (base) locale, or null when localization is off. */
41
+ defaultLocale?: string | null
42
+ }
43
+
44
+ function ScoreDot({ score }: { score: SeoScore }) {
45
+ return (
46
+ <span className={clsx('inline-block w-2 h-2 rounded-full shrink-0', {
47
+ 'bg-success': score === 'good',
48
+ 'bg-warning': score === 'ok',
49
+ 'bg-red-400': score === 'poor',
50
+ })} />
51
+ )
52
+ }
53
+
54
+ function OverallBadge({ score }: { score: SeoScore }) {
55
+ const labels: Record<SeoScore, string> = { good: 'Good', ok: 'Needs improvement', poor: 'Poor' }
56
+ return (
57
+ <div className={clsx(
58
+ 'flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium',
59
+ {
60
+ 'bg-success-muted text-success-fg': score === 'good',
61
+ 'bg-warning-muted text-warning-fg': score === 'ok',
62
+ 'bg-danger-muted text-danger-fg': score === 'poor',
63
+ },
64
+ )}>
65
+ <ScoreDot score={score} />
66
+ {labels[score]}
67
+ </div>
68
+ )
69
+ }
70
+
71
+ function GooglePreview({ title, metaDesc, url }: { title: string; metaDesc: string; url: string }) {
72
+ return (
73
+ <div className="rounded-lg border border-border bg-surface p-3 text-left space-y-0.5">
74
+ <p className="text-[10px] text-fg-subtle font-medium uppercase tracking-wider mb-1.5">Google preview</p>
75
+ <p className="text-[13px] text-info-fg hover:underline cursor-pointer leading-tight truncate">{title || 'Page title'}</p>
76
+ <p className="text-[11px] text-success-fg truncate">{url || 'https://example.com/page'}</p>
77
+ <p className="text-[11px] text-fg-muted leading-relaxed line-clamp-2">{metaDesc || 'Meta description will appear here…'}</p>
78
+ </div>
79
+ )
80
+ }
81
+
82
+ function ChecklistItem({ check }: { check: SeoCheck }) {
83
+ return (
84
+ <AccordionItem value={check.key}>
85
+ <AccordionTrigger>
86
+ <span className="flex items-center gap-2">
87
+ <ScoreDot score={check.score} />
88
+ {check.label}
89
+ </span>
90
+ </AccordionTrigger>
91
+ <AccordionContent>
92
+ <p className="text-[11px] text-fg-muted leading-relaxed">{check.message}</p>
93
+ </AccordionContent>
94
+ </AccordionItem>
95
+ )
96
+ }
97
+
98
+ export function SeoPanel({
99
+ title = '',
100
+ content = '',
101
+ fieldValues = {},
102
+ objectUrl = '',
103
+ objectId = '',
104
+ panelData,
105
+ onPanelDataChange,
106
+ ai,
107
+ activeLocale = null,
108
+ locales = [],
109
+ defaultLocale = null,
110
+ }: SeoPanelProps) {
111
+ const [aiBusy, setAiBusy] = useState(false)
112
+ // S3: whether this installation can describe an image (both optional grants + a provider that can see).
113
+ const [vision, setVision] = useState<{ available: boolean; provider?: string } | null>(null)
114
+ const [altBusy, setAltBusy] = useState(false)
115
+ const [activeTab, setActiveTab] = useState<'seo' | 'readability'>('seo')
116
+ const showAssistantButton = ai?.available && typeof ai.openAssistant === 'function'
117
+
118
+ // The full editable state: base fields plus per-locale slices. title and
119
+ // description are per locale; the focus keyphrase is a base-only editorial aid.
120
+ const [base, setBase] = useState<SeoPanelFields>({})
121
+ const [localeData, setLocaleData] = useState<Record<string, SeoPanelLocaleFields>>({})
122
+ // Which locale is being edited. The default locale edits the base.
123
+ const [active, setActive] = useState<string>(activeLocale || defaultLocale || '')
124
+ const localized = locales.length > 1
125
+ const isBase = !active || active === defaultLocale
126
+
127
+ const seoTitle = (isBase ? base.seoTitle : localeData[active]?.seoTitle) ?? ''
128
+ const metaDesc = (isBase ? base.metaDescription : localeData[active]?.metaDescription) ?? ''
129
+ const focusKeyword = base.focusKeyword ?? ''
130
+
131
+ // One commit point: set state AND emit the COMPLETE scoped shape (every
132
+ // locale), because writeDraft replaces the whole draft.
133
+ function commit(nextBase: SeoPanelFields, nextLocales: Record<string, SeoPanelLocaleFields>) {
134
+ setBase(nextBase)
135
+ setLocaleData(nextLocales)
136
+ onPanelDataChange?.(panelToScopedFull(nextBase, nextLocales) as unknown as Record<string, unknown>)
137
+ }
138
+ function setTitleValue(v: string) {
139
+ if (isBase) commit({ ...base, seoTitle: v }, localeData)
140
+ else commit(base, { ...localeData, [active]: { ...localeData[active], seoTitle: v } })
141
+ }
142
+ function setDescValue(v: string) {
143
+ if (isBase) commit({ ...base, metaDescription: v }, localeData)
144
+ else commit(base, { ...localeData, [active]: { ...localeData[active], metaDescription: v } })
145
+ }
146
+ function setFocusValue(v: string) {
147
+ commit({ ...base, focusKeyword: v }, localeData)
148
+ }
149
+
150
+ // FAQ pairs are base-only (shared across locales) - edited on the base view.
151
+ const faqList = base.faqs ?? []
152
+ function setFaqs(next: { question: string; answer: string }[]) {
153
+ commit({ ...base, faqs: next }, localeData)
154
+ }
155
+ const updateFaq = (i: number, patch: { question?: string; answer?: string }) =>
156
+ setFaqs(faqList.map((f, idx) => (idx === i ? { ...f, ...patch } : f)))
157
+ const addFaq = () => setFaqs([...faqList, { question: '', answer: '' }])
158
+ const removeFaq = (i: number) => setFaqs(faqList.filter((_, idx) => idx !== i))
159
+
160
+ // The GEO answer summary (base-only). AI-fillable when a provider is configured.
161
+ const answerSummary = base.answerSummary ?? ''
162
+ function setAnswerSummary(v: string) {
163
+ commit({ ...base, answerSummary: v }, localeData)
164
+ }
165
+ async function aiWriteAnswer() {
166
+ if (!ai?.available || aiBusy) return
167
+ setAiBusy(true)
168
+ try {
169
+ const text = await ai.fill(
170
+ `Write a concise, factual answer summary of this content for AI answer engines: 2 to 4 sentences, plain text, no marketing language.${focusKeyword ? ` Focus: "${focusKeyword}".` : ''}`,
171
+ )
172
+ setAnswerSummary(text)
173
+ } catch {
174
+ // the host surfaces API errors via toasts
175
+ } finally {
176
+ setAiBusy(false)
177
+ }
178
+ }
179
+
180
+ // S3: the share image's alt text (og:image:alt, base-only). A vision provider can write it from the image itself.
181
+ const imageAlt = base.imageAlt ?? ''
182
+ function setImageAlt(v: string) {
183
+ commit({ ...base, imageAlt: v }, localeData)
184
+ }
185
+ useEffect(() => {
186
+ if (!objectId) return
187
+ let alive = true
188
+ adminFetch<{ data: { available: boolean; provider?: string } }>('/admin/ext/seo/vision-status')
189
+ .then((r) => { if (alive) setVision(r.data) })
190
+ .catch(() => { if (alive) setVision({ available: false }) })
191
+ return () => { alive = false }
192
+ }, [objectId])
193
+ async function describeImage() {
194
+ if (!objectId || altBusy) return
195
+ setAltBusy(true)
196
+ try {
197
+ const r = await adminFetch<{ data?: { alt: string }; error?: { message: string } }>('/admin/ext/seo/alt-text', {
198
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: objectId, title, locale: isBase ? null : active }),
199
+ })
200
+ if (r.error) toast.error(r.error.message)
201
+ else if (r.data) setImageAlt(r.data.alt)
202
+ } catch (e) {
203
+ toast.error(e instanceof Error ? e.message : 'The image could not be described')
204
+ } finally {
205
+ setAltBusy(false)
206
+ }
207
+ }
208
+
209
+ async function aiWriteTitle() {
210
+ if (!ai?.available || aiBusy) return
211
+ setAiBusy(true)
212
+ try {
213
+ const text = await ai.fill(
214
+ `Write an SEO title for this content: max 60 characters, no quotes, compelling.${focusKeyword ? ` Include the focus keyword "${focusKeyword}".` : ''}`,
215
+ )
216
+ setTitleValue(text)
217
+ } catch {
218
+ // the host surfaces API errors via toasts
219
+ } finally {
220
+ setAiBusy(false)
221
+ }
222
+ }
223
+
224
+ async function aiWriteMetaDesc() {
225
+ if (!ai?.available || aiBusy) return
226
+ setAiBusy(true)
227
+ try {
228
+ const text = await ai.fill(
229
+ `Write an SEO meta description for this content: 120-160 characters, plain text, compelling, no quotes.${focusKeyword ? ` Include the focus keyword "${focusKeyword}".` : ''}`,
230
+ )
231
+ setDescValue(text)
232
+ } catch {
233
+ // panel stays usable; the host page surfaces API errors via toasts
234
+ } finally {
235
+ setAiBusy(false)
236
+ }
237
+ }
238
+
239
+ // Initialise from pre-loaded panelData once when it first arrives. The store
240
+ // speaks the scoped {draft:{base,locales}} shape; scopedToPanelFull maps it
241
+ // back to the fields this panel edits (and tolerates legacy flat rows).
242
+ const initializedRef = useRef(false)
243
+ useEffect(() => {
244
+ if (initializedRef.current || !panelData) return
245
+ const full = scopedToPanelFull(panelData)
246
+ const hasAny = full.base.seoTitle || full.base.metaDescription || full.base.focusKeyword || full.base.answerSummary || full.base.imageAlt || full.base.faqs?.length || Object.keys(full.locales).length > 0
247
+ if (hasAny) {
248
+ setBase(full.base)
249
+ setLocaleData(full.locales)
250
+ initializedRef.current = true
251
+ }
252
+ }, [panelData])
253
+
254
+ const effectiveTitle = seoTitle || title
255
+
256
+ const seoChecks = useMemo<SeoCheck[]>(() => [
257
+ analyzeTitleLength(effectiveTitle),
258
+ analyzeMetaDescLength(metaDesc),
259
+ analyzeKeywordInTitle(effectiveTitle, focusKeyword),
260
+ analyzeKeywordInMetaDesc(metaDesc, focusKeyword),
261
+ analyzeKeywordDensity(content, focusKeyword),
262
+ ], [effectiveTitle, metaDesc, focusKeyword, content])
263
+
264
+ const readabilityChecks = useMemo<SeoCheck[]>(() => [
265
+ analyzeReadability(content),
266
+ ], [content])
267
+
268
+ const activeChecks = activeTab === 'seo' ? seoChecks : readabilityChecks
269
+ const overallScore = computeOverallScore(activeChecks)
270
+
271
+
272
+ const overallSeoScore = computeOverallScore(seoChecks)
273
+
274
+ return (
275
+ <div className="space-y-4">
276
+ {/* The panel's own header line (the design's score pill): where this page stands, before the fields. */}
277
+ <div className="flex items-center gap-2 border-b border-border-subtle pb-2">
278
+ <span className="text-[10px] font-semibold uppercase tracking-wider text-fg-muted">Search appearance</span>
279
+ <span className="ml-auto"><OverallBadge score={overallSeoScore} /></span>
280
+ </div>
281
+ {showAssistantButton && (
282
+ <div className="flex justify-end">
283
+ <Button type="button" variant="ghost" size="xs" icon={<IconSparkles className="w-3.5 h-3.5" />} onClick={() => ai!.openAssistant!()}>
284
+ Generate SEO with Gen AI
285
+ </Button>
286
+ </div>
287
+ )}
288
+ {/* Locale switcher - title and description are stored per locale. */}
289
+ {localized && (
290
+ <div>
291
+ <div className="flex flex-wrap gap-1 rounded-md bg-surface-sunken p-0.5">
292
+ {locales.map((l) => {
293
+ const on = l.code === (active || defaultLocale)
294
+ return (
295
+ <Button key={l.code} type="button" size="xs" variant={on ? 'secondary' : 'ghost'} aria-pressed={on} onClick={() => setActive(l.code)}>
296
+ {l.label}
297
+ </Button>
298
+ )
299
+ })}
300
+ </div>
301
+ {!isBase && (
302
+ <p className="mt-1 text-[10px] text-fg-subtle">
303
+ Overrides for this locale. Leave a field empty to fall back to the default.
304
+ </p>
305
+ )}
306
+ </div>
307
+ )}
308
+
309
+ {/* Focus keyword */}
310
+ <div>
311
+ <label className="block text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1">
312
+ Focus keyphrase
313
+ </label>
314
+ <Input
315
+ type="text"
316
+ value={focusKeyword}
317
+ onChange={(e) => setFocusValue(e.currentTarget.value)}
318
+ placeholder="e.g. headless CMS"
319
+ />
320
+ </div>
321
+
322
+ {/* The design's check lines: the three that matter, right where the keyphrase is typed. */}
323
+ {isBase && (
324
+ <ul className="space-y-1.5">
325
+ {seoChecks.slice(0, 3).map((check) => (
326
+ <li key={check.key} className="flex items-start gap-2 text-[11px] font-medium text-fg-muted">
327
+ <ScoreDot score={check.score} />
328
+ <span className="mt-[-2px]">{check.message}</span>
329
+ </li>
330
+ ))}
331
+ </ul>
332
+ )}
333
+
334
+ {/* SEO title */}
335
+ <div>
336
+ <div className="flex items-center justify-between mb-1">
337
+ <label className="flex items-center text-[10px] font-semibold text-fg-muted uppercase tracking-wider">
338
+ SEO title
339
+ {ai?.available && (
340
+ <Button type="button" variant="ghost" size="xs" className="ml-1.5 h-5 px-1.5 align-middle text-[10px] font-semibold normal-case tracking-normal text-accent-fg" title="Write with AI" disabled={aiBusy} onClick={aiWriteTitle}
341
+ icon={<IconSparkles className={aiBusy ? 'w-3.5 h-3.5 animate-pulse text-accent' : 'w-3.5 h-3.5'} />}>AI</Button>
342
+ )}
343
+ </label>
344
+ <span className={clsx('text-[10px] font-medium', {
345
+ 'text-success-fg': seoTitle.length >= 50 && seoTitle.length <= 60,
346
+ 'text-warning': (seoTitle.length > 0 && seoTitle.length < 50) || (seoTitle.length > 60 && seoTitle.length <= 70),
347
+ 'text-danger-fg': seoTitle.length > 70,
348
+ 'text-fg-subtle': seoTitle.length === 0,
349
+ })}>
350
+ {seoTitle.length || effectiveTitle.length}/60
351
+ </span>
352
+ </div>
353
+ <Input
354
+ type="text"
355
+ value={seoTitle}
356
+ onChange={(e) => setTitleValue(e.currentTarget.value)}
357
+ placeholder={title || 'SEO title…'}
358
+ />
359
+ </div>
360
+
361
+ {/* Meta description */}
362
+ <div>
363
+ <div className="flex items-center justify-between mb-1">
364
+ <label className="text-[10px] font-semibold text-fg-muted uppercase tracking-wider">
365
+ Meta description
366
+ {ai?.available && (
367
+ <Button type="button" variant="ghost" size="xs" className="ml-1.5 h-5 px-1.5 align-middle text-[10px] font-semibold normal-case tracking-normal text-accent-fg" title="Write with AI" disabled={aiBusy} onClick={aiWriteMetaDesc}
368
+ icon={<IconSparkles className={aiBusy ? 'w-3.5 h-3.5 animate-pulse text-accent' : 'w-3.5 h-3.5'} />}>AI</Button>
369
+ )}
370
+ </label>
371
+ <span className={clsx('text-[10px] font-medium', {
372
+ 'text-success-fg': metaDesc.length >= 120 && metaDesc.length <= 160,
373
+ 'text-warning': (metaDesc.length >= 80 && metaDesc.length < 120) || (metaDesc.length > 160 && metaDesc.length <= 180),
374
+ 'text-danger-fg': (metaDesc.length > 0 && metaDesc.length < 80) || metaDesc.length > 180,
375
+ 'text-fg-subtle': metaDesc.length === 0,
376
+ })}>
377
+ {metaDesc.length}/160
378
+ </span>
379
+ </div>
380
+ <Textarea
381
+ rows={3}
382
+ value={metaDesc}
383
+ onChange={(e) => setDescValue(e.currentTarget.value)}
384
+ placeholder="Write a compelling description for search results…"
385
+ className="resize-none"
386
+ />
387
+ </div>
388
+
389
+ {/* GEO answer summary - base-only; surfaced in the resolved output. */}
390
+ {isBase && (
391
+ <div>
392
+ <label className="flex items-center text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1">
393
+ AI answer summary
394
+ {ai?.available && (
395
+ <Button type="button" variant="ghost" size="xs" className="ml-1.5 h-5 px-1.5 align-middle text-[10px] font-semibold normal-case tracking-normal text-accent-fg" title="Write with AI" disabled={aiBusy} onClick={aiWriteAnswer}
396
+ icon={<IconSparkles className={aiBusy ? 'w-3.5 h-3.5 animate-pulse text-accent' : 'w-3.5 h-3.5'} />}>AI</Button>
397
+ )}
398
+ </label>
399
+ <Textarea
400
+ rows={3}
401
+ value={answerSummary}
402
+ onChange={(e) => setAnswerSummary(e.currentTarget.value)}
403
+ placeholder="A concise, factual summary AI answer engines can cite…"
404
+ className="resize-none"
405
+ />
406
+ </div>
407
+ )}
408
+
409
+ {/* S3: share image alt text - og:image:alt. The Describe button exists only when the installation can see. */}
410
+ {isBase && (
411
+ <div>
412
+ <label className="flex items-center text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1">
413
+ Share image alt text
414
+ {vision?.available && objectId && (
415
+ <Button type="button" variant="ghost" size="xs" className="ml-1.5 h-5 px-1.5 align-middle text-[10px] font-semibold normal-case tracking-normal text-accent-fg" title="Describe the share image with AI" disabled={altBusy} onClick={describeImage}
416
+ icon={<IconSparkles className={altBusy ? 'w-3.5 h-3.5 animate-pulse text-accent' : 'w-3.5 h-3.5'} />}>Describe</Button>
417
+ )}
418
+ </label>
419
+ <Input
420
+ type="text"
421
+ value={imageAlt}
422
+ onChange={(e) => setImageAlt(e.currentTarget.value)}
423
+ placeholder="What the share image shows, in one sentence"
424
+ maxLength={125}
425
+ />
426
+ </div>
427
+ )}
428
+
429
+ {/* FAQ - base-only; rendered as FAQPage JSON-LD for rich results and GEO. */}
430
+ {isBase && (
431
+ <div>
432
+ <label className="block text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1">
433
+ FAQ (rich results and AI answers)
434
+ </label>
435
+ <div className="space-y-2">
436
+ {faqList.map((f, i) => (
437
+ <div key={i} className="rounded-md border border-border p-2 space-y-1.5">
438
+ <div className="flex items-start gap-1">
439
+ <Input
440
+ type="text"
441
+ value={f.question}
442
+ onChange={(e) => updateFaq(i, { question: e.currentTarget.value })}
443
+ placeholder="Question"
444
+ />
445
+ <Button type="button" variant="ghost" size="xs" className="shrink-0" aria-label="Remove question" icon={<span aria-hidden="true">&times;</span>} onClick={() => removeFaq(i)} />
446
+ </div>
447
+ <Textarea
448
+ rows={2}
449
+ value={f.answer}
450
+ onChange={(e) => updateFaq(i, { answer: e.currentTarget.value })}
451
+ placeholder="Answer"
452
+ className="resize-none"
453
+ />
454
+ </div>
455
+ ))}
456
+ <Button type="button" variant="ghost" size="xs" onClick={addFaq}>
457
+ + Add question
458
+ </Button>
459
+ </div>
460
+ </div>
461
+ )}
462
+
463
+ {/* Google preview */}
464
+ <GooglePreview title={effectiveTitle} metaDesc={metaDesc} url={objectUrl} />
465
+
466
+ {/* Analysis tabs + checklist */}
467
+ <div>
468
+ <div className="flex items-end border-b border-border mb-2">
469
+ <Tabs value={activeTab} onValueChange={(v) => setActiveTab(v as 'seo' | 'readability')}>
470
+ <TabsList>
471
+ <TabsTrigger value="seo">SEO analysis</TabsTrigger>
472
+ <TabsTrigger value="readability">Readability</TabsTrigger>
473
+ </TabsList>
474
+ </Tabs>
475
+ <div className="flex-1" />
476
+ <div className="flex items-center pb-1.5">
477
+ <OverallBadge score={overallScore} />
478
+ </div>
479
+ </div>
480
+
481
+ <Accordion type="multiple" className="border-t border-border">
482
+ {activeChecks.map((check) => (
483
+ <ChecklistItem key={check.key} check={check} />
484
+ ))}
485
+ </Accordion>
486
+ </div>
487
+ </div>
488
+ )
489
+ }