@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
@@ -0,0 +1,326 @@
1
+ /**
2
+ * File Name: TitlesTab.tsx
3
+ * Purpose: Titles & Meta (plan-seo-manager-v2 V2): every published page's SEO
4
+ * copy in the platform's own data list - search, filters, paging -
5
+ * and one row opens a Sheet to edit it. An edit writes the DRAFT, so
6
+ * the Sheet states what visitors see now beside each field and reads
7
+ * the platform's publish policy for that object: where another
8
+ * extension gates publishing (Review, for one), the Sheet says so
9
+ * rather than promising the change will appear.
10
+ *
11
+ * Author: Raghunath J
12
+ * License: MIT
13
+ */
14
+ import { useCallback, useEffect, useState } from 'react'
15
+ import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
16
+ import {
17
+ AdminPage, Button, Callout, DataList, Input, Textarea, Text,
18
+ Sheet, SheetBody, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle,
19
+ adminFetch, toast, useCan, ListChip, ListFilter, ListFilterChips, activeFilters, TEXT_LINK,
20
+ type DataListColumn, type ListFilterFacet, type ListFilterValue,
21
+ } from '@/kit'
22
+ import { IconSparkles, IconText, IconFileText, IconListChecks, IconTable } from '@tangen/icons'
23
+ import type { LifecycleActions } from '@tangen/cms'
24
+ import { TITLES_PAGE_SIZE, type TitleRow, type TitleState } from '../lib/titles'
25
+
26
+ interface Meta { total: number; scanned: number; counts: Record<TitleState, number>; types: string[] }
27
+
28
+ const STATE_LABEL: Record<TitleState, string> = { good: 'Good', 'needs-work': 'Needs work', missing: 'No metadata' }
29
+ const STATE_CLASS: Record<TitleState, string> = {
30
+ good: 'bg-success-muted text-success-fg',
31
+ 'needs-work': 'bg-warning-muted text-warning-fg',
32
+ missing: 'bg-danger-muted text-danger-fg',
33
+ }
34
+ const EMPTY_META: Meta = { total: 0, scanned: 0, counts: { good: 0, 'needs-work': 0, missing: 0 }, types: [] }
35
+
36
+ function StateBadge({ state }: { state: TitleState }) {
37
+ return <span className={`inline-flex rounded-full px-2 py-0.5 text-[11px] font-semibold ${STATE_CLASS[state]}`}>{STATE_LABEL[state]}</span>
38
+ }
39
+
40
+ export function SeoTitlesPage() {
41
+ const { hasCapability } = useCan()
42
+ const mayWrite = hasCapability('seo:write')
43
+
44
+ const [rows, setRows] = useState<TitleRow[]>([])
45
+ const [meta, setMeta] = useState<Meta>(EMPTY_META)
46
+ // A deep link may arrive already filtered (the Dashboard's "Edit all").
47
+ const [urlParams] = useSearchParams()
48
+ const [filters, setFilters] = useState<ListFilterValue>({
49
+ state: urlParams.get('state') ?? 'all',
50
+ type: urlParams.get('type') ?? 'all',
51
+ })
52
+ const state = String(filters.state ?? 'all')
53
+ const type = String(filters.type ?? 'all')
54
+ const [search, setSearch] = useState('')
55
+ const [page, setPage] = useState(1)
56
+ const [loading, setLoading] = useState(true)
57
+ const [error, setError] = useState<string | null>(null)
58
+ const [editing, setEditing] = useState<TitleRow | null>(null)
59
+ const [aiReady, setAiReady] = useState(false)
60
+ const [sort, setSort] = useState<{ field: string; direction: 'asc' | 'desc' } | undefined>(undefined)
61
+
62
+ useEffect(() => {
63
+ let alive = true
64
+ adminFetch<{ data: { generate: { available: boolean } } }>('/admin/ext/seo/ai-status')
65
+ .then((r) => { if (alive) setAiReady(r.data.generate.available) })
66
+ .catch(() => { if (alive) setAiReady(false) })
67
+ return () => { alive = false }
68
+ }, [])
69
+
70
+ const load = useCallback(async () => {
71
+ setLoading(true); setError(null)
72
+ try {
73
+ const params = new URLSearchParams({ limit: String(TITLES_PAGE_SIZE), offset: String((page - 1) * TITLES_PAGE_SIZE) })
74
+ if (state !== 'all') params.set('state', state)
75
+ if (type !== 'all') params.set('type', type)
76
+ if (search.trim()) params.set('search', search.trim())
77
+ if (sort) { params.set('sort', sort.field); params.set('dir', sort.direction) }
78
+ const res = await adminFetch<{ data: TitleRow[]; meta: Meta }>(`/admin/ext/seo/titles?${params.toString()}`)
79
+ setRows(res.data ?? [])
80
+ setMeta(res.meta ?? EMPTY_META)
81
+ } catch (e) {
82
+ setError((e as Error).message || 'The list could not be loaded.')
83
+ } finally { setLoading(false) }
84
+ }, [page, search, sort, state, type])
85
+ useEffect(() => { load() }, [load])
86
+
87
+ // The counts live in the labels, so the menu says how much each state holds.
88
+ const facets: ListFilterFacet[] = [
89
+ {
90
+ id: 'state', label: 'State', icon: <IconListChecks />,
91
+ options: [
92
+ { value: 'all', label: `All (${meta.scanned})` },
93
+ { value: 'attention', label: `Needs attention (${meta.counts.missing + meta.counts['needs-work']})` },
94
+ { value: 'missing', label: `${STATE_LABEL.missing} (${meta.counts.missing})` },
95
+ { value: 'needs-work', label: `${STATE_LABEL['needs-work']} (${meta.counts['needs-work']})` },
96
+ { value: 'good', label: `${STATE_LABEL.good} (${meta.counts.good})` },
97
+ ],
98
+ },
99
+ ...(meta.types.length > 1
100
+ ? [{ id: 'type', label: 'Content type', icon: <IconTable />, options: [{ value: 'all', label: 'All types' }, ...meta.types.map((t) => ({ value: t, label: t }))] }]
101
+ : []),
102
+ ]
103
+
104
+ const columns: DataListColumn<TitleRow>[] = [
105
+ {
106
+ key: 'page', header: 'Page', icon: <IconTable />, sortKey: 'page',
107
+ cell: (r) => (
108
+ <div className="min-w-0">
109
+ <p className="truncate font-medium text-fg">{r.objectTitle || r.id}</p>
110
+ <p className="truncate text-[11px] text-fg-subtle">{r.type}</p>
111
+ </div>
112
+ ),
113
+ },
114
+ {
115
+ key: 'title', header: 'SEO title', icon: <IconText />, sortKey: 'title',
116
+ cell: (r) => r.published.title
117
+ ? <span className="line-clamp-1 text-fg-muted">{r.published.title}</span>
118
+ : <span className="text-fg-faint">Falls back to the page title</span>,
119
+ },
120
+ {
121
+ key: 'description', header: 'Meta description', icon: <IconFileText />,
122
+ cell: (r) => r.published.description
123
+ ? <span className="line-clamp-1 text-fg-muted">{r.published.description}</span>
124
+ : <span className="text-fg-faint">Not set</span>,
125
+ },
126
+ {
127
+ key: 'state', header: 'State', icon: <IconListChecks />, sortKey: 'state',
128
+ cell: (r) => (
129
+ <span className="flex flex-wrap items-center gap-1.5">
130
+ <StateBadge state={r.state} />
131
+ {r.pending && <span className="inline-flex rounded-full bg-accent-muted px-2 py-0.5 text-[11px] font-semibold text-accent-fg">Draft waiting</span>}
132
+ </span>
133
+ ),
134
+ },
135
+ ]
136
+
137
+ return (
138
+ <AdminPage
139
+ title="Titles & Meta"
140
+ description="Every published page's SEO title and description, in one place."
141
+ access={{ capability: 'seo:read' }}
142
+ >
143
+ <div className="space-y-4">
144
+ <DataList<TitleRow>
145
+ chrome="framed"
146
+ columns={columns}
147
+ rows={rows}
148
+ rowKey={(r) => `${r.type}:${r.id}`}
149
+ loading={loading}
150
+ onRowClick={(r) => setEditing(r)}
151
+ page={page}
152
+ pageSize={TITLES_PAGE_SIZE}
153
+ total={meta.total}
154
+ onPageChange={setPage}
155
+ search={search}
156
+ searchPlaceholder="Search titles and descriptions"
157
+ onSearchChange={(v) => { setSearch(v); setPage(1) }}
158
+ filtered={state !== 'all' || type !== 'all' || search.trim() !== ''}
159
+ error={error ? { message: error, onRetry: load } : undefined}
160
+ sortConfig={sort}
161
+ onSortChange={setSort}
162
+ toolbarLeft={<ListChip icon={<IconTable />} label="Pages" count={meta.total} />}
163
+ toolbarRight={<ListFilter facets={facets} value={filters} onChange={(next) => { setFilters(next); setPage(1) }} />}
164
+ filterRow={activeFilters(facets, filters).length
165
+ ? <ListFilterChips facets={facets} value={filters} onChange={(next) => { setFilters(next); setPage(1) }} />
166
+ : undefined}
167
+ emptyState={{
168
+ title: 'Nothing to show',
169
+ description: 'Nothing is published yet. A page appears here once it is published.',
170
+ }}
171
+ filteredEmptyState={{
172
+ title: 'No page matches these filters',
173
+ description: 'Clear the filters, or search for something else.',
174
+ action: <Button size="sm" variant="secondary" onClick={() => { setFilters({ state: 'all', type: 'all' }); setSearch(''); setPage(1) }}>Clear filters</Button>,
175
+ }}
176
+ />
177
+ <Text variant="help">
178
+ An edit here is saved as a draft and reaches visitors when the page is next published, exactly as an edit in the page's own SEO panel does. Per-locale values are edited in that panel, where the locale switcher lives.
179
+ </Text>
180
+ </div>
181
+ <EditSheet
182
+ row={editing}
183
+ mayWrite={mayWrite}
184
+ aiReady={aiReady}
185
+ onClose={() => setEditing(null)}
186
+ onSaved={(next) => setRows((all) => all.map((r) => (r.id === next.id ? { ...next, objectTitle: r.objectTitle } : r)))}
187
+ />
188
+ </AdminPage>
189
+ )
190
+ }
191
+
192
+ /** What another extension's publish policy says about this object, if anything. */
193
+ function publishGateOf(actions: LifecycleActions | null | undefined): { blocked: boolean; reason?: string } {
194
+ const publish = actions?.actions?.find((a) => a.id === 'publish')
195
+ const policy = publish?.blockers?.find((b) => b.code === 'POLICY')
196
+ if (!policy) return { blocked: false }
197
+ return { blocked: true, ...(policy.reason ? { reason: policy.reason } : {}) }
198
+ }
199
+
200
+ /** One page's SEO copy: the draft being edited, the live values beside it, and who gates the publish that would apply it. */
201
+ function EditSheet({ row, mayWrite, aiReady, onClose, onSaved }: {
202
+ row: TitleRow | null
203
+ mayWrite: boolean
204
+ aiReady: boolean
205
+ onClose: () => void
206
+ onSaved: (row: TitleRow) => void
207
+ }) {
208
+ const { workspaceId = '' } = useParams<{ workspaceId: string }>()
209
+ const navigate = useNavigate()
210
+ const [title, setTitle] = useState('')
211
+ const [description, setDescription] = useState('')
212
+ const [saving, setSaving] = useState(false)
213
+ const [proposing, setProposing] = useState(false)
214
+ const [gate, setGate] = useState<{ blocked: boolean; reason?: string } | null>(null)
215
+
216
+ useEffect(() => {
217
+ if (!row) return
218
+ setTitle(row.draft.title ?? '')
219
+ setDescription(row.draft.description ?? '')
220
+ setGate(null)
221
+ let alive = true
222
+ // Ask the platform what can be done to this object, rather than guess at
223
+ // another extension's rules: a Review workflow (or any publish policy)
224
+ // shows up here as a POLICY blocker on the publish action.
225
+ adminFetch<{ data: LifecycleActions }>(`/objects/${encodeURIComponent(row.type)}/actions`, undefined, { objectId: row.id })
226
+ .then((r) => { if (alive) setGate(publishGateOf(r.data)) })
227
+ .catch(() => { if (alive) setGate(null) })
228
+ return () => { alive = false }
229
+ }, [row])
230
+
231
+ if (!row) return null
232
+ const dirty = (row.draft.title ?? '') !== title || (row.draft.description ?? '') !== description
233
+
234
+ const save = async () => {
235
+ setSaving(true)
236
+ try {
237
+ const res = await adminFetch<{ data?: TitleRow; error?: { message: string } }>('/admin/ext/seo/titles', {
238
+ method: 'PATCH', headers: { 'content-type': 'application/json' },
239
+ body: JSON.stringify({ id: row.id, type: row.type, title, description }),
240
+ })
241
+ if (res.error) toast.error(res.error.message)
242
+ else if (res.data) {
243
+ onSaved(res.data)
244
+ toast.success('Saved as a draft; it applies when this page is published')
245
+ onClose()
246
+ }
247
+ } catch (e) {
248
+ toast.error(e instanceof Error ? e.message : 'That could not be saved')
249
+ } finally { setSaving(false) }
250
+ }
251
+
252
+ const propose = async () => {
253
+ setProposing(true)
254
+ try {
255
+ const res = await adminFetch<{ data?: { proposal: { title?: string; description?: string } }; error?: { message: string } }>('/admin/ext/seo/optimize', {
256
+ method: 'POST', headers: { 'content-type': 'application/json' },
257
+ body: JSON.stringify({ id: row.id, type: row.type }),
258
+ })
259
+ if (res.error) toast.error(res.error.message)
260
+ else if (res.data) {
261
+ if (res.data.proposal.title) setTitle(res.data.proposal.title)
262
+ if (res.data.proposal.description) setDescription(res.data.proposal.description)
263
+ toast.success('Proposed. Review it, then save the draft.')
264
+ }
265
+ } catch (e) {
266
+ toast.error(e instanceof Error ? e.message : 'Nothing could be proposed for this page')
267
+ } finally { setProposing(false) }
268
+ }
269
+
270
+ return (
271
+ <Sheet open onOpenChange={(open) => { if (!open) onClose() }}>
272
+ <SheetContent size="md" dismissible>
273
+ <SheetHeader>
274
+ <SheetTitle>{row.objectTitle || row.id}</SheetTitle>
275
+ <SheetDescription>{`${row.type} · saved as a draft, applied when this page is next published`}</SheetDescription>
276
+ </SheetHeader>
277
+ <SheetBody>
278
+ <div className="space-y-4">
279
+ <div className="flex flex-wrap items-center gap-2">
280
+ <StateBadge state={row.state} />
281
+ {row.pending && <span className="inline-flex rounded-full bg-accent-muted px-2 py-0.5 text-[11px] font-semibold text-accent-fg">Draft waiting on publish</span>}
282
+ </div>
283
+ {row.issues.length > 0 && <Callout variant="warning" title="What the checks say">{row.issues.join(' ')}</Callout>}
284
+ {gate?.blocked && (
285
+ <Callout variant="info" title="Publishing this page is gated">
286
+ {`${gate.reason ?? 'Another extension controls when this page can be published.'} Your draft is saved either way, and applies when that publish happens.`}
287
+ </Callout>
288
+ )}
289
+
290
+ <div>
291
+ <div className="mb-1 flex items-center justify-between">
292
+ <label className="text-[10px] font-semibold uppercase tracking-wider text-fg-muted" htmlFor="seo-sheet-title">SEO title</label>
293
+ <span className="text-[11px] text-fg-subtle tabular-nums">{title.length}/60</span>
294
+ </div>
295
+ <Input id="seo-sheet-title" value={title} onChange={(e) => setTitle((e.target as HTMLInputElement).value)} disabled={!mayWrite} placeholder={row.objectTitle ?? 'Not set'} />
296
+ <p className="mt-1 text-[11px] text-fg-subtle">{`Live: ${row.published.title ?? 'not set, so the page title is used'}`}</p>
297
+ </div>
298
+
299
+ <div>
300
+ <div className="mb-1 flex items-center justify-between">
301
+ <label className="text-[10px] font-semibold uppercase tracking-wider text-fg-muted" htmlFor="seo-sheet-desc">Meta description</label>
302
+ <span className="text-[11px] text-fg-subtle tabular-nums">{description.length}/160</span>
303
+ </div>
304
+ <Textarea id="seo-sheet-desc" rows={4} value={description} onChange={(e) => setDescription((e.target as HTMLTextAreaElement).value)} disabled={!mayWrite} placeholder="Not set" className="resize-none" />
305
+ <p className="mt-1 text-[11px] text-fg-subtle">{`Live: ${row.published.description ?? 'not set'}`}</p>
306
+ </div>
307
+
308
+ <Text variant="help">
309
+ Canonical URLs, robots, social fields, FAQ and the answer summary live in this page's own SEO panel, along with the locale switcher.
310
+ </Text>
311
+ </div>
312
+ </SheetBody>
313
+ <SheetFooter>
314
+ <Button size="sm" variant="ghost" onClick={() => navigate(`/${workspaceId}/objects/${row.type}/${row.id}`)}>Open the page</Button>
315
+ <div className="flex-1" />
316
+ {mayWrite && aiReady && (
317
+ <Button size="sm" variant="secondary" disabled={proposing} icon={<IconSparkles className={proposing ? 'size-3.5 animate-pulse text-accent' : 'size-3.5'} />} onClick={propose}>
318
+ {proposing ? 'Writing' : 'Write with AI'}
319
+ </Button>
320
+ )}
321
+ {mayWrite && <Button size="sm" disabled={!dirty || saving} onClick={save}>{saving ? 'Saving' : 'Save draft'}</Button>}
322
+ </SheetFooter>
323
+ </SheetContent>
324
+ </Sheet>
325
+ )
326
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * File Name: ToolsTab.tsx
3
+ * Purpose: Tools (plan-seo-manager-v2 V7): the four things an operator needs
4
+ * occasionally - see what robots.txt serves, retire the cached
5
+ * answers after changing something outside Tangen, and move
6
+ * redirects in and out as a spreadsheet. Every one of them is a
7
+ * route that already governs itself; this page only asks.
8
+ *
9
+ * Author: Raghunath J
10
+ * License: MIT
11
+ */
12
+ import { useEffect, useState } from 'react'
13
+ import { Link, useParams } from 'react-router-dom'
14
+ import { AdminPage, Button, Callout, FormSection, Input, Textarea, Text, adminFetch, adminFetchFile, toast, useCan, TEXT_LINK } from '@/kit'
15
+ import { IconRefresh } from '@tangen/icons'
16
+ import { REDIRECT_CSV_HEADER } from '../lib/redirects-csv'
17
+ import { seoManagerHref } from '../lib/seo-manager-nav'
18
+
19
+ interface ImportReport {
20
+ read: number
21
+ written: number
22
+ malformed: Array<{ line: number; message: string }>
23
+ refused: Array<{ source: string; reason: string }>
24
+ }
25
+
26
+ export function SeoToolsPage() {
27
+ const { workspaceId = '' } = useParams<{ workspaceId: string }>()
28
+ const { hasCapability } = useCan()
29
+ const mayWrite = hasCapability('seo:write')
30
+
31
+ const [robots, setRobots] = useState<{ body: string; role: string | null; path: string } | null>(null)
32
+ const [refreshing, setRefreshing] = useState(false)
33
+ const [csv, setCsv] = useState('')
34
+ const [importing, setImporting] = useState(false)
35
+ const [report, setReport] = useState<ImportReport | null>(null)
36
+
37
+ useEffect(() => {
38
+ let alive = true
39
+ adminFetch<{ data: { body: string; role: string | null; path: string } }>('/admin/ext/seo/robots-preview')
40
+ .then((r) => { if (alive) setRobots(r.data) })
41
+ .catch(() => { if (alive) setRobots(null) })
42
+ return () => { alive = false }
43
+ }, [])
44
+
45
+ const refresh = async () => {
46
+ setRefreshing(true)
47
+ try {
48
+ const r = await adminFetch<{ data: { version: number } }>('/admin/ext/seo/refresh-caches', { method: 'POST' })
49
+ toast.success(`Cached answers retired (version ${r.data.version})`)
50
+ } catch (e) {
51
+ toast.error(e instanceof Error ? e.message : 'The caches could not be refreshed')
52
+ } finally { setRefreshing(false) }
53
+ }
54
+
55
+ const runImport = async () => {
56
+ setImporting(true); setReport(null)
57
+ try {
58
+ const r = await adminFetch<{ data: ImportReport }>('/admin/ext/seo/redirects/import', {
59
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ csv }),
60
+ })
61
+ setReport(r.data)
62
+ if (r.data.written) toast.success(`${r.data.written} redirect${r.data.written === 1 ? '' : 's'} imported`)
63
+ } catch (e) {
64
+ toast.error(e instanceof Error ? e.message : 'The file could not be imported')
65
+ } finally { setImporting(false) }
66
+ }
67
+
68
+ return (
69
+ <AdminPage title="Tools" description="Occasional jobs: what robots.txt serves, cached answers, and redirects as a spreadsheet." access={{ capability: 'seo:read' }}>
70
+ <div className="space-y-6">
71
+ <FormSection title="robots.txt" description={robots?.role ? `What the public route serves for a ${robots.role} deployment.` : 'What the public route serves.'}>
72
+ <Textarea rows={8} readOnly value={robots?.body ?? ''} className="resize-none font-mono text-xs" aria-label="robots.txt as served" />
73
+ <div className="flex items-center gap-2">
74
+ <Input readOnly value={robots?.path ?? ''} aria-label="The robots.txt route" className="max-w-md font-mono text-xs" />
75
+ <Button size="sm" variant="secondary" onClick={() => { void navigator.clipboard?.writeText(robots?.path ?? ''); toast.success('Path copied') }}>Copy</Button>
76
+ </div>
77
+ <Text variant="help">
78
+ The directives come from <Link className={TEXT_LINK} to={seoManagerHref(workspaceId, 'settings')}>Settings</Link>, and a non-production deployment serves the guarded version instead.
79
+ </Text>
80
+ </FormSection>
81
+
82
+ <FormSection title="Cached answers" description="Tangen caches the resolved metadata, the sitemaps and llms.txt, and retires them when content is published.">
83
+ <div>
84
+ <Button size="sm" variant="secondary" icon={<IconRefresh className="size-3.5" />} disabled={!mayWrite || refreshing} onClick={refresh}>
85
+ {refreshing ? 'Refreshing' : 'Refresh caches'}
86
+ </Button>
87
+ </div>
88
+ <Text variant="help">Use it after changing something Tangen cannot see, such as a URL your application builds differently. It costs one rebuild per answer, nothing more.</Text>
89
+ </FormSection>
90
+
91
+ <FormSection title="Redirects as a spreadsheet" description="Three columns: from, to, status. The same rules apply as in the redirect form, so a refused row says why.">
92
+ <div className="flex flex-wrap items-center gap-2">
93
+ <Button size="sm" variant="secondary" onClick={() => { void download() }}>Export CSV</Button>
94
+ <Text variant="help">{REDIRECT_CSV_HEADER}</Text>
95
+ </div>
96
+ <Textarea
97
+ rows={6}
98
+ value={csv}
99
+ onChange={(e) => setCsv((e.target as HTMLTextAreaElement).value)}
100
+ placeholder={`${REDIRECT_CSV_HEADER}\n/old-page,https://example.com/new-page,301`}
101
+ className="resize-none font-mono text-xs"
102
+ aria-label="Redirects to import"
103
+ disabled={!mayWrite}
104
+ />
105
+ <div>
106
+ <Button size="sm" disabled={!mayWrite || importing || !csv.trim()} onClick={runImport}>{importing ? 'Importing' : 'Import CSV'}</Button>
107
+ </div>
108
+ {report && (
109
+ <Callout variant={report.malformed.length || report.refused.length ? 'warning' : 'success'} title={`${report.written} of ${report.read} rows imported`}>
110
+ {report.malformed.length > 0 && (
111
+ <ul className="mt-1 list-disc pl-4">
112
+ {report.malformed.slice(0, 10).map((m) => <li key={m.line}>{`Line ${m.line}: ${m.message}`}</li>)}
113
+ </ul>
114
+ )}
115
+ {report.refused.length > 0 && (
116
+ <ul className="mt-1 list-disc pl-4">
117
+ {report.refused.slice(0, 10).map((r) => <li key={r.source}>{`${r.source}: ${r.reason}`}</li>)}
118
+ </ul>
119
+ )}
120
+ {report.malformed.length === 0 && report.refused.length === 0 && 'Every row was read and written.'}
121
+ </Callout>
122
+ )}
123
+ </FormSection>
124
+ </div>
125
+ </AdminPage>
126
+ )
127
+ }
128
+
129
+ /** The export is a file the browser saves; the route names it. */
130
+ async function download() {
131
+ try {
132
+ const res = await adminFetchFile('/admin/ext/seo/redirects/export', { headers: { accept: 'text/csv' } })
133
+ const url = URL.createObjectURL(await res.blob())
134
+ const link = document.createElement('a')
135
+ link.href = url
136
+ link.download = 'redirects.csv'
137
+ link.click()
138
+ URL.revokeObjectURL(url)
139
+ } catch (e) {
140
+ toast.error(e instanceof Error ? e.message : 'The file could not be exported')
141
+ }
142
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * File Name: manager-pages.tsx
3
+ * Purpose: The SEO Manager's child pages (plan-seo-manager-v2 V0): each is
4
+ * one AdminPage around a panel the v1 hub used to show behind a tab,
5
+ * on its own URL so the context nav, the command palette and a
6
+ * bookmark all reach it directly. Behaviour lives in the panels.
7
+ *
8
+ * Author: Raghunath J
9
+ * License: MIT
10
+ */
11
+ import type { ReactNode } from 'react'
12
+ import { useSearchParams } from 'react-router-dom'
13
+ import { AdminPage } from '@/kit'
14
+ import type { AdminPageProps } from '@/kit'
15
+ import { RedirectsPanel } from './redirects'
16
+ import { SettingsPanel } from './SettingsTab'
17
+ import { SchemasPanel } from './SchemasTab'
18
+ import { SitemapPanel } from './SitemapTab'
19
+
20
+ function ManagerPage({ title, description, width, children }: { title: string; description: string; width?: AdminPageProps['width']; children: ReactNode }) {
21
+ return (
22
+ <AdminPage title={title} description={description} width={width} access={{ capability: 'seo:read' }}>
23
+ {children}
24
+ </AdminPage>
25
+ )
26
+ }
27
+
28
+ export function SeoSchemaPage() {
29
+ return <ManagerPage title="Schema" description="Structured data per content type: the schema.org kind and which fields fill it."><SchemasPanel /></ManagerPage>
30
+ }
31
+ export function SeoSitemapPage() {
32
+ return <ManagerPage title="Sitemap" description="What the sitemap serves, what it skipped, and the URL to submit to search engines."><SitemapPanel /></ManagerPage>
33
+ }
34
+ export function SeoRedirectsPage() {
35
+ // `?source=` arrives from the 404 Monitor: open the form with that path filled in.
36
+ const [params] = useSearchParams()
37
+ return (
38
+ <ManagerPage title="Redirects" description="Old addresses that still work. Tangen stores the rule; your site performs the redirect.">
39
+ <RedirectsPanel initialSource={params.get('source') ?? undefined} />
40
+ </ManagerPage>
41
+ )
42
+ }
43
+ export function SeoSettingsPage() {
44
+ // `form` centres the column: settings read as a stack of cards down the middle of the page.
45
+ return <ManagerPage title="Settings" description="The defaults an editor changes without a code deploy, stored per workspace." width="form"><SettingsPanel /></ManagerPage>
46
+ }