@actuate-media/cms-admin 0.18.0 → 0.20.0
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/AdminRoot.d.ts.map +1 -1
- package/dist/AdminRoot.js +9 -5
- package/dist/AdminRoot.js.map +1 -1
- package/dist/__tests__/lib/post-editor-service.test.js +75 -23
- package/dist/__tests__/lib/post-editor-service.test.js.map +1 -1
- package/dist/__tests__/lib/posts-service.test.js +132 -142
- package/dist/__tests__/lib/posts-service.test.js.map +1 -1
- package/dist/__tests__/views/posts-list-view.render.test.d.ts +2 -0
- package/dist/__tests__/views/posts-list-view.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/posts-list-view.render.test.js +73 -0
- package/dist/__tests__/views/posts-list-view.render.test.js.map +1 -0
- package/dist/actuate-admin.css +1 -1
- package/dist/components/seo/Drawer.d.ts +11 -0
- package/dist/components/seo/Drawer.d.ts.map +1 -0
- package/dist/components/seo/Drawer.js +13 -0
- package/dist/components/seo/Drawer.js.map +1 -0
- package/dist/components/seo/RedirectEditorDrawer.d.ts +9 -0
- package/dist/components/seo/RedirectEditorDrawer.d.ts.map +1 -0
- package/dist/components/seo/RedirectEditorDrawer.js +94 -0
- package/dist/components/seo/RedirectEditorDrawer.js.map +1 -0
- package/dist/components/seo/SeoCopilotDrawer.d.ts +10 -0
- package/dist/components/seo/SeoCopilotDrawer.d.ts.map +1 -0
- package/dist/components/seo/SeoCopilotDrawer.js +34 -0
- package/dist/components/seo/SeoCopilotDrawer.js.map +1 -0
- package/dist/components/seo/SeoEditorDrawer.d.ts +8 -0
- package/dist/components/seo/SeoEditorDrawer.d.ts.map +1 -0
- package/dist/components/seo/SeoEditorDrawer.js +111 -0
- package/dist/components/seo/SeoEditorDrawer.js.map +1 -0
- package/dist/components/seo/SeoIssueFixDrawer.d.ts +8 -0
- package/dist/components/seo/SeoIssueFixDrawer.d.ts.map +1 -0
- package/dist/components/seo/SeoIssueFixDrawer.js +111 -0
- package/dist/components/seo/SeoIssueFixDrawer.js.map +1 -0
- package/dist/components/seo/primitives.d.ts +53 -0
- package/dist/components/seo/primitives.d.ts.map +1 -0
- package/dist/components/seo/primitives.js +100 -0
- package/dist/components/seo/primitives.js.map +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/layout/Sidebar.d.ts.map +1 -1
- package/dist/layout/Sidebar.js +3 -0
- package/dist/layout/Sidebar.js.map +1 -1
- package/dist/lib/post-editor-service.d.ts +6 -4
- package/dist/lib/post-editor-service.d.ts.map +1 -1
- package/dist/lib/post-editor-service.js +32 -37
- package/dist/lib/post-editor-service.js.map +1 -1
- package/dist/lib/posts-service.d.ts.map +1 -1
- package/dist/lib/posts-service.js +91 -160
- package/dist/lib/posts-service.js.map +1 -1
- package/dist/lib/seo-service.d.ts +322 -0
- package/dist/lib/seo-service.d.ts.map +1 -0
- package/dist/lib/seo-service.js +295 -0
- package/dist/lib/seo-service.js.map +1 -0
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +4 -1
- package/dist/router/index.js.map +1 -1
- package/dist/views/MediaBrowser.d.ts.map +1 -1
- package/dist/views/MediaBrowser.js +36 -25
- package/dist/views/MediaBrowser.js.map +1 -1
- package/dist/views/Posts/NewPostPicker.d.ts +5 -4
- package/dist/views/Posts/NewPostPicker.d.ts.map +1 -1
- package/dist/views/Posts/NewPostPicker.js +5 -4
- package/dist/views/Posts/NewPostPicker.js.map +1 -1
- package/dist/views/Posts/NewPostTypeInstructions.js +2 -2
- package/dist/views/Posts/PostTypesView.d.ts +5 -4
- package/dist/views/Posts/PostTypesView.d.ts.map +1 -1
- package/dist/views/Posts/PostTypesView.js.map +1 -1
- package/dist/views/Posts/PostsListView.d.ts.map +1 -1
- package/dist/views/Posts/PostsListView.js +8 -0
- package/dist/views/Posts/PostsListView.js.map +1 -1
- package/dist/views/Posts/post-type-presets.d.ts +5 -0
- package/dist/views/Posts/post-type-presets.d.ts.map +1 -1
- package/dist/views/Posts/post-type-presets.js +10 -64
- package/dist/views/Posts/post-type-presets.js.map +1 -1
- package/dist/views/SEO.d.ts.map +1 -1
- package/dist/views/SEO.js +89 -132
- package/dist/views/SEO.js.map +1 -1
- package/dist/views/page-editor/sections/ArticleBodySection.d.ts +6 -2
- package/dist/views/page-editor/sections/ArticleBodySection.d.ts.map +1 -1
- package/dist/views/page-editor/sections/ArticleBodySection.js +8 -8
- package/dist/views/page-editor/sections/ArticleBodySection.js.map +1 -1
- package/dist/views/post-editor/PostEditorCanvas.js +7 -1
- package/dist/views/post-editor/PostEditorCanvas.js.map +1 -1
- package/dist/views/post-editor/PostFieldsModal.d.ts.map +1 -1
- package/dist/views/post-editor/PostFieldsModal.js +10 -4
- package/dist/views/post-editor/PostFieldsModal.js.map +1 -1
- package/dist/views/post-editor/PostHeader.d.ts.map +1 -1
- package/dist/views/post-editor/PostHeader.js +4 -3
- package/dist/views/post-editor/PostHeader.js.map +1 -1
- package/dist/views/post-editor/PostPreview.d.ts.map +1 -1
- package/dist/views/post-editor/PostPreview.js +11 -1
- package/dist/views/post-editor/PostPreview.js.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.d.ts +22 -2
- package/dist/views/post-editor/PostSectionEditor.d.ts.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.js +4 -1
- package/dist/views/post-editor/PostSectionEditor.js.map +1 -1
- package/dist/views/seo/AuditTab.d.ts +6 -0
- package/dist/views/seo/AuditTab.d.ts.map +1 -0
- package/dist/views/seo/AuditTab.js +57 -0
- package/dist/views/seo/AuditTab.js.map +1 -0
- package/dist/views/seo/ContentTab.d.ts +5 -0
- package/dist/views/seo/ContentTab.d.ts.map +1 -0
- package/dist/views/seo/ContentTab.js +27 -0
- package/dist/views/seo/ContentTab.js.map +1 -0
- package/dist/views/seo/OverviewTab.d.ts +8 -0
- package/dist/views/seo/OverviewTab.d.ts.map +1 -0
- package/dist/views/seo/OverviewTab.js +35 -0
- package/dist/views/seo/OverviewTab.js.map +1 -0
- package/dist/views/seo/RedirectsTab.d.ts +2 -0
- package/dist/views/seo/RedirectsTab.d.ts.map +1 -0
- package/dist/views/seo/RedirectsTab.js +124 -0
- package/dist/views/seo/RedirectsTab.js.map +1 -0
- package/dist/views/seo/TechnicalTab.d.ts +2 -0
- package/dist/views/seo/TechnicalTab.d.ts.map +1 -0
- package/dist/views/seo/TechnicalTab.js +102 -0
- package/dist/views/seo/TechnicalTab.js.map +1 -0
- package/dist/views/seo/useSeoResource.d.ts +8 -0
- package/dist/views/seo/useSeoResource.d.ts.map +1 -0
- package/dist/views/seo/useSeoResource.js +42 -0
- package/dist/views/seo/useSeoResource.js.map +1 -0
- package/package.json +2 -2
- package/src/AdminRoot.tsx +9 -5
- package/src/__tests__/lib/post-editor-service.test.ts +78 -23
- package/src/__tests__/lib/posts-service.test.ts +134 -163
- package/src/__tests__/views/posts-list-view.render.test.tsx +84 -0
- package/src/components/seo/Drawer.tsx +61 -0
- package/src/components/seo/RedirectEditorDrawer.tsx +235 -0
- package/src/components/seo/SeoCopilotDrawer.tsx +76 -0
- package/src/components/seo/SeoEditorDrawer.tsx +347 -0
- package/src/components/seo/SeoIssueFixDrawer.tsx +244 -0
- package/src/components/seo/primitives.tsx +237 -0
- package/src/index.ts +0 -2
- package/src/layout/Sidebar.tsx +3 -0
- package/src/lib/post-editor-service.ts +41 -40
- package/src/lib/posts-service.ts +109 -180
- package/src/lib/seo-service.ts +623 -0
- package/src/router/index.ts +4 -1
- package/src/views/MediaBrowser.tsx +89 -67
- package/src/views/Posts/NewPostPicker.tsx +5 -4
- package/src/views/Posts/NewPostTypeInstructions.tsx +2 -2
- package/src/views/Posts/PostTypesView.tsx +5 -4
- package/src/views/Posts/PostsListView.tsx +9 -0
- package/src/views/Posts/post-type-presets.ts +15 -64
- package/src/views/SEO.tsx +186 -863
- package/src/views/page-editor/sections/ArticleBodySection.tsx +12 -16
- package/src/views/post-editor/PostEditorCanvas.tsx +7 -1
- package/src/views/post-editor/PostFieldsModal.tsx +36 -21
- package/src/views/post-editor/PostHeader.tsx +4 -4
- package/src/views/post-editor/PostPreview.tsx +12 -1
- package/src/views/post-editor/PostSectionEditor.tsx +22 -5
- package/src/views/seo/AuditTab.tsx +229 -0
- package/src/views/seo/ContentTab.tsx +164 -0
- package/src/views/seo/OverviewTab.tsx +257 -0
- package/src/views/seo/RedirectsTab.tsx +392 -0
- package/src/views/seo/TechnicalTab.tsx +303 -0
- package/src/views/seo/useSeoResource.ts +52 -0
- package/dist/views/PostEditor.d.ts +0 -6
- package/dist/views/PostEditor.d.ts.map +0 -1
- package/dist/views/PostEditor.js +0 -79
- package/dist/views/PostEditor.js.map +0 -1
- package/dist/views/Posts.d.ts +0 -5
- package/dist/views/Posts.d.ts.map +0 -1
- package/dist/views/Posts.js +0 -73
- package/dist/views/Posts.js.map +0 -1
- package/src/views/PostEditor.tsx +0 -257
- package/src/views/Posts.tsx +0 -375
package/src/lib/posts-service.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Posts service — thin client over the
|
|
3
|
-
*
|
|
2
|
+
* Posts service — thin client over the CMS REST endpoints, shaped around the
|
|
3
|
+
* data the Posts admin area needs.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* `fetchPosts` calls the server-side aggregate endpoint `GET /posts`, which
|
|
6
|
+
* does the cross-collection filter / sort / paginate at the DB level (one
|
|
7
|
+
* query + one count) and returns the post rows alongside dataset-wide type
|
|
8
|
+
* counts and the contributor list. This keeps the Posts list O(page) instead
|
|
9
|
+
* of pulling every document per type into the browser, and lets it scale past
|
|
10
|
+
* the old ~500-row-per-type client cap.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* across collections must respect per-collection `read` rules.
|
|
15
|
-
* The existing endpoint enforces this per-call; mixing them
|
|
16
|
-
* server-side would need a new auth boundary.
|
|
17
|
-
* - V1 traffic is small (the seed is 15 rows); a few extra
|
|
18
|
-
* parallel requests are well under the rate-limit budget.
|
|
19
|
-
*
|
|
20
|
-
* Promote to a single endpoint when:
|
|
21
|
-
* - Any post-type collection grows past ~5k rows, OR
|
|
22
|
-
* - Page-load latency exceeds 300ms in the admin metrics.
|
|
12
|
+
* Access control still lives server-side: the endpoint only returns rows from
|
|
13
|
+
* collections the caller's scope can read.
|
|
23
14
|
*/
|
|
24
15
|
import { cmsApi } from './api.js'
|
|
25
16
|
|
|
@@ -133,204 +124,142 @@ function collectionToPostType(c: CollectionApiRow, count = 0): PostType {
|
|
|
133
124
|
}
|
|
134
125
|
}
|
|
135
126
|
|
|
136
|
-
// ───
|
|
127
|
+
// ─── Authors ─────────────────────────────────────────────────────────
|
|
137
128
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
function initialsFromName(name: string | null | undefined): string {
|
|
130
|
+
const trimmed = name?.trim()
|
|
131
|
+
if (!trimmed) return '?'
|
|
132
|
+
const parts = trimmed.split(/\s+/)
|
|
133
|
+
const first = parts[0]?.[0] ?? ''
|
|
134
|
+
const last = parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? '') : ''
|
|
135
|
+
return (first + last).toUpperCase() || '?'
|
|
142
136
|
}
|
|
143
137
|
|
|
144
|
-
|
|
145
|
-
if (name && name.trim().length > 0) {
|
|
146
|
-
const parts = name.trim().split(/\s+/)
|
|
147
|
-
const first = parts[0]?.[0] ?? ''
|
|
148
|
-
const last = parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? '') : ''
|
|
149
|
-
return (first + last).toUpperCase() || (email[0] ?? '?').toUpperCase()
|
|
150
|
-
}
|
|
151
|
-
return (email[0] ?? '?').toUpperCase()
|
|
152
|
-
}
|
|
138
|
+
// ─── Posts (server-side aggregate) ───────────────────────────────────
|
|
153
139
|
|
|
154
|
-
|
|
155
|
-
const res = await cmsApi<{ users: UserApiRow[] } | UserApiRow[]>('/users?pageSize=200')
|
|
156
|
-
const list: UserApiRow[] = Array.isArray(res.data)
|
|
157
|
-
? res.data
|
|
158
|
-
: ((res.data as { users?: UserApiRow[] } | null)?.users ?? [])
|
|
159
|
-
const map = new Map<string, PostAuthor>()
|
|
160
|
-
for (const u of list) {
|
|
161
|
-
map.set(u.id, {
|
|
162
|
-
id: u.id,
|
|
163
|
-
name: u.name?.trim() || u.email,
|
|
164
|
-
initials: initialsFromName(u.name, u.email),
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
return map
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ─── Posts ───────────────────────────────────────────────────────────
|
|
171
|
-
|
|
172
|
-
interface DocumentApiRow {
|
|
140
|
+
interface PostsApiPost {
|
|
173
141
|
id: string
|
|
174
142
|
collection: string
|
|
175
143
|
title: string | null
|
|
176
144
|
slug: string | null
|
|
177
145
|
status: PostStatus
|
|
178
|
-
createdById: string | null
|
|
179
|
-
updatedById: string | null
|
|
180
146
|
publishedAt: string | null
|
|
181
147
|
scheduledAt: string | null
|
|
182
148
|
createdAt: string
|
|
183
149
|
updatedAt: string
|
|
184
|
-
|
|
150
|
+
seoScore: number | null
|
|
151
|
+
author: { id: string; name: string } | null
|
|
185
152
|
}
|
|
186
153
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
154
|
+
interface PostsApiType {
|
|
155
|
+
slug: string
|
|
156
|
+
singular: string
|
|
157
|
+
plural: string
|
|
158
|
+
description: string | null
|
|
159
|
+
urlPrefix: string
|
|
160
|
+
color: string | null
|
|
161
|
+
icon: string | null
|
|
162
|
+
fieldCount: number
|
|
163
|
+
count: number
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface PostsApiResponse {
|
|
167
|
+
posts: PostsApiPost[]
|
|
168
|
+
total: number
|
|
169
|
+
page: number
|
|
170
|
+
pageSize: number
|
|
171
|
+
types: PostsApiType[]
|
|
172
|
+
authors: Array<{ id: string; name: string }>
|
|
195
173
|
}
|
|
196
174
|
|
|
197
|
-
|
|
175
|
+
/** Display date matches the old client behaviour: scheduled/published date when set, else updated. */
|
|
176
|
+
function pickDisplayDate(d: PostsApiPost): string {
|
|
198
177
|
if (d.status === 'SCHEDULED' && d.scheduledAt) return d.scheduledAt
|
|
199
178
|
if (d.status === 'PUBLISHED' && d.publishedAt) return d.publishedAt
|
|
200
179
|
return d.updatedAt
|
|
201
180
|
}
|
|
202
181
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
182
|
+
function buildPostsQueryString(query: PostsQuery): string {
|
|
183
|
+
const params = new URLSearchParams()
|
|
184
|
+
if (query.search?.trim()) params.set('search', query.search.trim())
|
|
185
|
+
if (query.postType && query.postType !== 'all') params.set('postType', query.postType)
|
|
186
|
+
if (query.status && query.status !== 'all') params.set('status', query.status)
|
|
187
|
+
if (query.author && query.author !== 'all') params.set('author', query.author)
|
|
188
|
+
if (query.sortBy) params.set('sortBy', query.sortBy)
|
|
189
|
+
if (query.sortDirection) params.set('sortDirection', query.sortDirection)
|
|
190
|
+
params.set('page', String(Math.max(1, query.page ?? 1)))
|
|
191
|
+
params.set('pageSize', String(Math.max(1, query.pageSize ?? 10)))
|
|
192
|
+
const qs = params.toString()
|
|
193
|
+
return qs ? `?${qs}` : ''
|
|
206
194
|
}
|
|
207
195
|
|
|
208
196
|
export async function fetchPosts(query: PostsQuery = {}): Promise<PostsResult> {
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
// Pull every doc for each post type (cap at 500 to avoid runaway
|
|
213
|
-
// requests; pagination + filtering still happens client-side over
|
|
214
|
-
// this set). When a type grows past 500 docs we'll need the
|
|
215
|
-
// server-side aggregate endpoint described in this file's header.
|
|
216
|
-
const perTypeRaw = await Promise.all(
|
|
217
|
-
cols.map(async (c) => {
|
|
218
|
-
const res = await cmsApi<ListEnvelope>(
|
|
219
|
-
`/collections/${encodeURIComponent(c.slug)}?pageSize=500&sort=updatedAt&order=desc`,
|
|
220
|
-
)
|
|
221
|
-
const docs = (res.data?.docs ?? []) as DocumentApiRow[]
|
|
222
|
-
return { col: c, docs }
|
|
223
|
-
}),
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
// Map docs → Post objects.
|
|
227
|
-
const allPosts: Post[] = []
|
|
228
|
-
for (const { col, docs } of perTypeRaw) {
|
|
229
|
-
for (const d of docs) {
|
|
230
|
-
const author = (d.createdById && authorsMap.get(d.createdById)) ||
|
|
231
|
-
(d.updatedById && authorsMap.get(d.updatedById)) || {
|
|
232
|
-
id: '',
|
|
233
|
-
name: 'Unknown',
|
|
234
|
-
initials: '??',
|
|
235
|
-
}
|
|
236
|
-
allPosts.push({
|
|
237
|
-
id: d.id,
|
|
238
|
-
title: d.title ?? (d.data?.title as string) ?? '(untitled)',
|
|
239
|
-
slug: d.slug ?? (d.data?.slug as string) ?? '',
|
|
240
|
-
postTypeId: col.slug,
|
|
241
|
-
postTypeName: col.labels.singular,
|
|
242
|
-
postTypeAccentColor: col.color ?? null,
|
|
243
|
-
authorId: author.id,
|
|
244
|
-
authorName: author.name,
|
|
245
|
-
authorInitials: author.initials,
|
|
246
|
-
status: d.status,
|
|
247
|
-
publishDate: d.publishedAt ?? d.scheduledAt ?? null,
|
|
248
|
-
updatedDate: pickDisplayDate(d),
|
|
249
|
-
seoScore: extractSeoScore(d.data),
|
|
250
|
-
createdAt: d.createdAt,
|
|
251
|
-
updatedAt: d.updatedAt,
|
|
252
|
-
})
|
|
253
|
-
}
|
|
254
|
-
}
|
|
197
|
+
const page = Math.max(1, query.page ?? 1)
|
|
198
|
+
const pageSize = Math.max(1, query.pageSize ?? 10)
|
|
255
199
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
for (const p of allPosts) {
|
|
260
|
-
countsBySlug.set(p.postTypeId, (countsBySlug.get(p.postTypeId) ?? 0) + 1)
|
|
200
|
+
const res = await cmsApi<PostsApiResponse>(`/posts${buildPostsQueryString(query)}`)
|
|
201
|
+
if (res.error || !res.data) {
|
|
202
|
+
throw new Error(res.error ?? 'Failed to load posts')
|
|
261
203
|
}
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
204
|
+
const r = res.data
|
|
205
|
+
|
|
206
|
+
const typeBySlug = new Map<string, PostsApiType>()
|
|
207
|
+
for (const t of r.types) typeBySlug.set(t.slug, t)
|
|
208
|
+
|
|
209
|
+
const types: PostType[] = r.types.map((t) => ({
|
|
210
|
+
id: t.slug,
|
|
211
|
+
slug: t.slug,
|
|
212
|
+
name: t.plural,
|
|
213
|
+
singularName: t.singular,
|
|
214
|
+
description: t.description ?? null,
|
|
215
|
+
urlBase: `/${t.urlPrefix || t.slug}`,
|
|
216
|
+
accentColor: t.color ?? null,
|
|
217
|
+
icon: t.icon ?? null,
|
|
218
|
+
postCount: t.count,
|
|
219
|
+
fieldCount: t.fieldCount,
|
|
220
|
+
active: true,
|
|
221
|
+
}))
|
|
222
|
+
|
|
223
|
+
const posts: Post[] = r.posts.map((d) => {
|
|
224
|
+
const type = typeBySlug.get(d.collection)
|
|
225
|
+
const authorName = d.author?.name?.trim() || 'Unknown'
|
|
226
|
+
return {
|
|
227
|
+
id: d.id,
|
|
228
|
+
title: d.title ?? '(untitled)',
|
|
229
|
+
slug: d.slug ?? '',
|
|
230
|
+
postTypeId: d.collection,
|
|
231
|
+
postTypeName: type?.singular ?? d.collection,
|
|
232
|
+
postTypeAccentColor: type?.color ?? null,
|
|
233
|
+
authorId: d.author?.id ?? '',
|
|
234
|
+
authorName,
|
|
235
|
+
authorInitials: d.author ? initialsFromName(d.author.name) : '??',
|
|
236
|
+
status: d.status,
|
|
237
|
+
publishDate: d.publishedAt ?? d.scheduledAt ?? null,
|
|
238
|
+
updatedDate: pickDisplayDate(d),
|
|
239
|
+
seoScore: d.seoScore,
|
|
240
|
+
createdAt: d.createdAt,
|
|
241
|
+
updatedAt: d.updatedAt,
|
|
273
242
|
}
|
|
274
|
-
return true
|
|
275
243
|
})
|
|
276
244
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// Paginate.
|
|
286
|
-
const page = Math.max(1, query.page ?? 1)
|
|
287
|
-
const pageSize = Math.max(1, query.pageSize ?? 10)
|
|
288
|
-
const start = (page - 1) * pageSize
|
|
289
|
-
const paged = filtered.slice(start, start + pageSize)
|
|
290
|
-
|
|
291
|
-
// Unique authors from the full set (so the dropdown lists every
|
|
292
|
-
// contributor, not just the currently visible page).
|
|
293
|
-
const authorIds = new Set<string>()
|
|
294
|
-
const authors: PostAuthor[] = []
|
|
295
|
-
for (const p of allPosts) {
|
|
296
|
-
if (p.authorId && !authorIds.has(p.authorId)) {
|
|
297
|
-
authorIds.add(p.authorId)
|
|
298
|
-
authors.push({ id: p.authorId, name: p.authorName, initials: p.authorInitials })
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
authors.sort((a, b) => a.name.localeCompare(b.name))
|
|
245
|
+
const authors: PostAuthor[] = r.authors
|
|
246
|
+
.map((a) => ({
|
|
247
|
+
id: a.id,
|
|
248
|
+
name: a.name?.trim() || 'Unknown',
|
|
249
|
+
initials: initialsFromName(a.name),
|
|
250
|
+
}))
|
|
251
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
302
252
|
|
|
303
253
|
return {
|
|
304
|
-
posts
|
|
305
|
-
total:
|
|
306
|
-
page,
|
|
307
|
-
pageSize,
|
|
254
|
+
posts,
|
|
255
|
+
total: r.total,
|
|
256
|
+
page: r.page ?? page,
|
|
257
|
+
pageSize: r.pageSize ?? pageSize,
|
|
308
258
|
types,
|
|
309
259
|
authors,
|
|
310
260
|
}
|
|
311
261
|
}
|
|
312
262
|
|
|
313
|
-
function comparePostsFor(by: NonNullable<PostsQuery['sortBy']>, a: Post, b: Post): number {
|
|
314
|
-
switch (by) {
|
|
315
|
-
case 'title':
|
|
316
|
-
return a.title.localeCompare(b.title)
|
|
317
|
-
case 'type':
|
|
318
|
-
return a.postTypeName.localeCompare(b.postTypeName)
|
|
319
|
-
case 'author':
|
|
320
|
-
return a.authorName.localeCompare(b.authorName)
|
|
321
|
-
case 'status':
|
|
322
|
-
return a.status.localeCompare(b.status)
|
|
323
|
-
case 'seo': {
|
|
324
|
-
const av = a.seoScore ?? -1
|
|
325
|
-
const bv = b.seoScore ?? -1
|
|
326
|
-
return av - bv
|
|
327
|
-
}
|
|
328
|
-
case 'date':
|
|
329
|
-
default:
|
|
330
|
-
return new Date(a.updatedDate).getTime() - new Date(b.updatedDate).getTime()
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
263
|
// ─── Bulk mutations ──────────────────────────────────────────────────
|
|
335
264
|
|
|
336
265
|
export async function bulkUpdatePosts(
|