@kurbo/dkit 0.4.0 → 0.5.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.
- package/README.md +4 -0
- package/dist/bin.js +385 -139
- package/dist/bin.js.map +1 -1
- package/package.json +4 -1
- package/vendor/registry/blocks/blog-detail/ui/minimal/next/blog-detail.tsx +0 -1
- package/vendor/registry/blocks/blog-detail/ui/shadcn/next/blog-detail.tsx +0 -1
- package/vendor/registry/blocks/blog-list/ui/minimal/next/blog-list.tsx +0 -1
- package/vendor/registry/blocks/blog-list/ui/shadcn/next/blog-list.tsx +0 -1
- package/vendor/registry/blocks/blog-list-cards/ui/minimal/next/blog-list-cards.tsx +0 -1
- package/vendor/registry/blocks/blog-list-cards/ui/shadcn/next/blog-list-cards.tsx +0 -1
- package/vendor/registry/blocks/booking-form-ui/ui/minimal/next/booking-form.tsx +0 -1
- package/vendor/registry/blocks/booking-form-ui/ui/shadcn/next/booking-form.tsx +0 -1
- package/vendor/registry/blocks/contact-form-ui/ui/minimal/next/contact-form.tsx +0 -1
- package/vendor/registry/blocks/contact-form-ui/ui/shadcn/next/contact-form.tsx +0 -1
- package/vendor/registry/blocks/faq-list/ui/minimal/next/faq-list.tsx +0 -1
- package/vendor/registry/blocks/faq-list/ui/shadcn/next/faq-list.tsx +0 -1
- package/vendor/registry/blocks/page-detail/ui/minimal/next/page-detail.tsx +0 -1
- package/vendor/registry/blocks/page-detail/ui/shadcn/next/page-detail.tsx +0 -1
- package/vendor/registry/blocks/project-detail/ui/minimal/next/project-detail.tsx +0 -1
- package/vendor/registry/blocks/project-detail/ui/shadcn/next/project-detail.tsx +0 -1
- package/vendor/registry/blocks/project-list/ui/minimal/next/project-list.tsx +0 -1
- package/vendor/registry/blocks/project-list/ui/shadcn/next/project-list.tsx +0 -1
- package/vendor/registry/blocks/project-list-cards/ui/minimal/next/project-list-cards.tsx +0 -1
- package/vendor/registry/blocks/project-list-cards/ui/shadcn/next/project-list-cards.tsx +0 -1
- package/vendor/registry/blocks/projects-carousel/ui/minimal/next/projects-carousel-client.tsx +0 -4
- package/vendor/registry/blocks/projects-carousel/ui/minimal/next/projects-carousel.tsx +0 -1
- package/vendor/registry/blocks/projects-carousel/ui/shadcn/next/projects-carousel-client.tsx +0 -1
- package/vendor/registry/blocks/projects-carousel/ui/shadcn/next/projects-carousel.tsx +0 -1
- package/vendor/registry/blocks/service-detail/ui/minimal/next/service-detail.tsx +0 -1
- package/vendor/registry/blocks/service-detail/ui/shadcn/next/service-detail.tsx +0 -1
- package/vendor/registry/blocks/service-list/ui/minimal/next/service-list.tsx +0 -1
- package/vendor/registry/blocks/service-list/ui/shadcn/next/service-list.tsx +0 -1
- package/vendor/registry/blocks/service-list-cards/ui/minimal/next/service-list-cards.tsx +0 -1
- package/vendor/registry/blocks/service-list-cards/ui/shadcn/next/service-list-cards.tsx +0 -1
- package/vendor/registry/blocks/social-links/ui/minimal/next/social-links.tsx +0 -1
- package/vendor/registry/blocks/social-links/ui/shadcn/next/social-links.tsx +0 -1
- package/vendor/registry/blocks/team-detail/ui/minimal/next/team-detail.tsx +0 -1
- package/vendor/registry/blocks/team-detail/ui/shadcn/next/team-detail.tsx +0 -1
- package/vendor/registry/blocks/team-list/ui/minimal/next/team-list.tsx +0 -1
- package/vendor/registry/blocks/team-list/ui/shadcn/next/team-list.tsx +0 -1
- package/vendor/registry/blocks/team-list-cards/ui/minimal/next/team-list-cards.tsx +0 -1
- package/vendor/registry/blocks/team-list-cards/ui/shadcn/next/team-list-cards.tsx +0 -1
- package/vendor/registry/blocks/testimonials-carousel/ui/minimal/next/testimonials-carousel-client.tsx +0 -4
- package/vendor/registry/blocks/testimonials-carousel/ui/minimal/next/testimonials-carousel.tsx +0 -1
- package/vendor/registry/blocks/testimonials-carousel/ui/shadcn/next/testimonials-carousel-client.tsx +0 -1
- package/vendor/registry/blocks/testimonials-carousel/ui/shadcn/next/testimonials-carousel.tsx +0 -1
- package/vendor/registry/blocks/testimonials-list/ui/minimal/next/testimonials-list.tsx +0 -1
- package/vendor/registry/blocks/testimonials-list/ui/shadcn/next/testimonials-list.tsx +0 -1
- package/vendor/registry/blocks/testimonials-list-cards/ui/minimal/next/testimonials-list-cards.tsx +0 -1
- package/vendor/registry/blocks/testimonials-list-cards/ui/shadcn/next/testimonials-list-cards.tsx +0 -1
- package/vendor/registry/modules/blog/lib.multilocale.ts +124 -129
- package/vendor/registry/modules/blog/lib.ts +12 -9
- package/vendor/registry/modules/blog/services/seed.json +1 -1
- package/vendor/registry/modules/blog/services/seed.multilocale.json +1 -1
- package/vendor/registry/modules/blog/types.multilocale.ts +41 -12
- package/vendor/registry/modules/blog/types.ts +8 -6
- package/vendor/registry/modules/faq/lib.multilocale.ts +30 -30
- package/vendor/registry/modules/faq/lib.ts +4 -5
- package/vendor/registry/modules/faq/types.multilocale.ts +13 -2
- package/vendor/registry/modules/faq/types.ts +4 -2
- package/vendor/registry/modules/navigation/lib.multilocale.ts +207 -76
- package/vendor/registry/modules/navigation/lib.ts +18 -17
- package/vendor/registry/modules/navigation/types.multilocale.ts +24 -4
- package/vendor/registry/modules/navigation/types.ts +6 -4
- package/vendor/registry/modules/pages/lib.multilocale.ts +34 -39
- package/vendor/registry/modules/pages/lib.ts +4 -3
- package/vendor/registry/modules/pages/types.multilocale.ts +14 -3
- package/vendor/registry/modules/pages/types.ts +5 -3
- package/vendor/registry/modules/projects/lib.multilocale.ts +149 -65
- package/vendor/registry/modules/projects/lib.ts +6 -6
- package/vendor/registry/modules/projects/services/seed.json +2 -2
- package/vendor/registry/modules/projects/services/seed.multilocale.json +2 -2
- package/vendor/registry/modules/projects/types.multilocale.ts +15 -3
- package/vendor/registry/modules/projects/types.ts +5 -3
- package/vendor/registry/modules/services/lib.multilocale.ts +143 -63
- package/vendor/registry/modules/services/lib.ts +6 -6
- package/vendor/registry/modules/services/services/seed.json +4 -4
- package/vendor/registry/modules/services/services/seed.multilocale.json +2 -2
- package/vendor/registry/modules/services/types.multilocale.ts +13 -3
- package/vendor/registry/modules/services/types.ts +5 -3
- package/vendor/registry/modules/settings/lib.multilocale.ts +159 -57
- package/vendor/registry/modules/settings/types.multilocale.ts +15 -0
- package/vendor/registry/modules/settings/types.ts +2 -2
- package/vendor/registry/modules/team/lib.multilocale.ts +116 -49
- package/vendor/registry/modules/team/lib.ts +4 -3
- package/vendor/registry/modules/team/services/seed.json +4 -4
- package/vendor/registry/modules/team/services/seed.multilocale.json +2 -2
- package/vendor/registry/modules/team/types.multilocale.ts +16 -3
- package/vendor/registry/modules/team/types.ts +5 -3
- package/vendor/registry/modules/testimonials/lib.multilocale.ts +82 -50
- package/vendor/registry/modules/testimonials/services/seed.json +4 -4
- package/vendor/registry/modules/testimonials/services/seed.multilocale.json +2 -2
- package/vendor/registry/modules/testimonials/types.multilocale.ts +14 -2
- package/vendor/registry/modules/testimonials/types.ts +4 -2
- package/vendor/registry/shared/helpers.ts +9 -3
- package/vendor/registry/shared/i18n.ts +84 -12
- package/vendor/registry/shared/prose.css +1 -1
|
@@ -9,31 +9,34 @@ import {
|
|
|
9
9
|
import { collections } from "@/lib/dkit/config";
|
|
10
10
|
import { queryLimit, statusFilter } from "@/lib/dkit/helpers";
|
|
11
11
|
import {
|
|
12
|
-
isUsableTranslation,
|
|
13
|
-
pickTranslation,
|
|
14
12
|
requireLocaleTranslation,
|
|
15
13
|
resolveLocale,
|
|
16
14
|
translationsDeepFilter,
|
|
15
|
+
withLocale,
|
|
17
16
|
} from "@/lib/dkit/i18n";
|
|
18
17
|
import type {
|
|
19
18
|
BlogAuthor,
|
|
20
|
-
|
|
19
|
+
BlogAuthorRow,
|
|
21
20
|
BlogCategory,
|
|
22
|
-
|
|
21
|
+
BlogCategoryRow,
|
|
23
22
|
BlogPost,
|
|
24
|
-
|
|
23
|
+
BlogPostRow,
|
|
25
24
|
GetBlogAuthorsOptions,
|
|
26
25
|
GetBlogBySlugOptions,
|
|
27
26
|
GetBlogCategoriesOptions,
|
|
28
27
|
GetBlogPostsOptions,
|
|
28
|
+
PostsCategoriesRow,
|
|
29
29
|
} from "./types.multilocale";
|
|
30
30
|
|
|
31
31
|
export type {
|
|
32
32
|
BlogAuthor,
|
|
33
|
+
BlogAuthorRow,
|
|
33
34
|
BlogAuthorTranslation,
|
|
34
35
|
BlogCategory,
|
|
36
|
+
BlogCategoryRow,
|
|
35
37
|
BlogCategoryTranslation,
|
|
36
38
|
BlogPost,
|
|
39
|
+
BlogPostRow,
|
|
37
40
|
BlogPostTranslation,
|
|
38
41
|
DirectusFileRef,
|
|
39
42
|
GetBlogAuthorsOptions,
|
|
@@ -43,99 +46,82 @@ export type {
|
|
|
43
46
|
PostsCategoriesRow,
|
|
44
47
|
} from "./types.multilocale";
|
|
45
48
|
|
|
46
|
-
/* ──
|
|
47
|
-
|
|
48
|
-
type JunctionCategory = {
|
|
49
|
-
id?: number | string;
|
|
50
|
-
categories_id?: BlogCategory | string | null;
|
|
51
|
-
};
|
|
49
|
+
/* ── locale → public shape ── */
|
|
52
50
|
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
): BlogPost | null {
|
|
57
|
-
const trans = pickTranslation(
|
|
58
|
-
row.translations as BlogPostTranslation[] | undefined,
|
|
51
|
+
function flattenCategory(row: BlogCategoryRow, locale: string): BlogCategory | null {
|
|
52
|
+
return withLocale(
|
|
53
|
+
row,
|
|
59
54
|
locale,
|
|
55
|
+
(r, t) => ({
|
|
56
|
+
id: r.id,
|
|
57
|
+
title: t.title,
|
|
58
|
+
slug: t.slug,
|
|
59
|
+
}),
|
|
60
|
+
{ required: ["title", "slug"] },
|
|
60
61
|
);
|
|
61
|
-
if (!isUsableTranslation(trans)) return null;
|
|
62
|
-
|
|
63
|
-
let author: BlogPost["author"] = row.author as BlogPost["author"];
|
|
64
|
-
if (author && typeof author === "object") {
|
|
65
|
-
author = flattenAuthor(author as unknown as Record<string, unknown>, locale);
|
|
66
|
-
}
|
|
67
|
-
const rawCategories = row.categories;
|
|
68
|
-
let categories: BlogPost["categories"] = null;
|
|
69
|
-
if (Array.isArray(rawCategories)) {
|
|
70
|
-
const out: BlogCategory[] = [];
|
|
71
|
-
for (const item of rawCategories) {
|
|
72
|
-
if (!item || typeof item !== "object") continue;
|
|
73
|
-
if ("title" in item && "id" in item && !("translations" in item)) {
|
|
74
|
-
if ((item as BlogCategory).title && (item as BlogCategory).slug) {
|
|
75
|
-
out.push(item as BlogCategory);
|
|
76
|
-
}
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const related =
|
|
80
|
-
"categories_id" in item
|
|
81
|
-
? (item as JunctionCategory).categories_id
|
|
82
|
-
: item;
|
|
83
|
-
if (related && typeof related === "object") {
|
|
84
|
-
const flat = flattenCategory(
|
|
85
|
-
related as unknown as Record<string, unknown>,
|
|
86
|
-
locale,
|
|
87
|
-
);
|
|
88
|
-
if (flat) out.push(flat);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
categories = out;
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
id: row.id as string,
|
|
95
|
-
status: row.status as BlogPost["status"],
|
|
96
|
-
title: trans!.title!,
|
|
97
|
-
slug: trans!.slug!,
|
|
98
|
-
excerpt: trans?.excerpt ?? null,
|
|
99
|
-
body: trans?.body ?? null,
|
|
100
|
-
published_at: (row.published_at as string | null) ?? null,
|
|
101
|
-
featured_image: row.featured_image as BlogPost["featured_image"],
|
|
102
|
-
author,
|
|
103
|
-
categories,
|
|
104
|
-
};
|
|
105
62
|
}
|
|
106
63
|
|
|
107
|
-
function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
64
|
+
function flattenAuthor(row: BlogAuthorRow, locale: string): BlogAuthor {
|
|
65
|
+
return (
|
|
66
|
+
withLocale(row, locale, (r, t) => ({
|
|
67
|
+
id: r.id,
|
|
68
|
+
status: r.status,
|
|
69
|
+
name: r.name,
|
|
70
|
+
slug: r.slug,
|
|
71
|
+
avatar: r.avatar,
|
|
72
|
+
bio: t?.bio ?? null,
|
|
73
|
+
})) ?? {
|
|
74
|
+
id: row.id,
|
|
75
|
+
status: row.status,
|
|
76
|
+
name: row.name,
|
|
77
|
+
slug: row.slug,
|
|
78
|
+
avatar: row.avatar,
|
|
79
|
+
bio: null,
|
|
80
|
+
}
|
|
114
81
|
);
|
|
115
|
-
if (!isUsableTranslation(trans)) return null;
|
|
116
|
-
return {
|
|
117
|
-
id: row.id as string,
|
|
118
|
-
title: trans!.title!,
|
|
119
|
-
slug: trans!.slug!,
|
|
120
|
-
};
|
|
121
82
|
}
|
|
122
83
|
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
): BlogAuthor {
|
|
127
|
-
const trans = pickTranslation(
|
|
128
|
-
row.translations as BlogAuthorTranslation[] | undefined,
|
|
84
|
+
function flattenPost(row: BlogPostRow, locale: string): BlogPost | null {
|
|
85
|
+
return withLocale(
|
|
86
|
+
row,
|
|
129
87
|
locale,
|
|
88
|
+
(r, t) => {
|
|
89
|
+
let author: BlogPost["author"] = null;
|
|
90
|
+
if (typeof r.author === "string") {
|
|
91
|
+
author = r.author;
|
|
92
|
+
} else if (r.author && typeof r.author === "object") {
|
|
93
|
+
author = flattenAuthor(r.author, locale);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let categories: BlogPost["categories"] = null;
|
|
97
|
+
if (Array.isArray(r.categories)) {
|
|
98
|
+
const out: BlogCategory[] = [];
|
|
99
|
+
for (const item of r.categories) {
|
|
100
|
+
if (!item || typeof item !== "object") continue;
|
|
101
|
+
const related = item.categories_id;
|
|
102
|
+
if (related && typeof related === "object") {
|
|
103
|
+
const flat = flattenCategory(related, locale);
|
|
104
|
+
if (flat) out.push(flat);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
categories = out;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
id: r.id,
|
|
112
|
+
status: r.status,
|
|
113
|
+
title: t.title,
|
|
114
|
+
slug: t.slug,
|
|
115
|
+
excerpt: t.excerpt ?? null,
|
|
116
|
+
body: t.body ?? null,
|
|
117
|
+
published_at: r.published_at ?? null,
|
|
118
|
+
featured_image: r.featured_image,
|
|
119
|
+
author,
|
|
120
|
+
categories,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
{ required: ["title", "slug"] },
|
|
130
124
|
);
|
|
131
|
-
return {
|
|
132
|
-
id: row.id as string,
|
|
133
|
-
status: row.status as BlogAuthor["status"],
|
|
134
|
-
name: row.name as string,
|
|
135
|
-
slug: row.slug as string,
|
|
136
|
-
avatar: row.avatar as BlogAuthor["avatar"],
|
|
137
|
-
bio: trans?.bio ?? null,
|
|
138
|
-
};
|
|
139
125
|
}
|
|
140
126
|
|
|
141
127
|
/* ── field lists ── */
|
|
@@ -165,7 +151,17 @@ const POST_DETAIL_FIELDS = [
|
|
|
165
151
|
{ translations: ["id", "languages_code", "bio"] },
|
|
166
152
|
],
|
|
167
153
|
},
|
|
168
|
-
{
|
|
154
|
+
{
|
|
155
|
+
categories: [
|
|
156
|
+
"id",
|
|
157
|
+
{
|
|
158
|
+
categories_id: [
|
|
159
|
+
"id",
|
|
160
|
+
{ translations: ["id", "languages_code", "title", "slug"] },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
169
165
|
{
|
|
170
166
|
translations: [
|
|
171
167
|
"id",
|
|
@@ -212,7 +208,7 @@ export function featuredImageUrl(post: BlogPost): string | null {
|
|
|
212
208
|
}
|
|
213
209
|
|
|
214
210
|
export function normalizeCategories(
|
|
215
|
-
raw: BlogPost["categories"] |
|
|
211
|
+
raw: BlogPost["categories"] | PostsCategoriesRow[] | null | undefined,
|
|
216
212
|
): BlogCategory[] {
|
|
217
213
|
if (!Array.isArray(raw)) return [];
|
|
218
214
|
const out: BlogCategory[] = [];
|
|
@@ -222,9 +218,12 @@ export function normalizeCategories(
|
|
|
222
218
|
out.push(item as BlogCategory);
|
|
223
219
|
continue;
|
|
224
220
|
}
|
|
225
|
-
const related = (item as
|
|
221
|
+
const related = (item as PostsCategoriesRow).categories_id;
|
|
226
222
|
if (related && typeof related === "object" && "id" in related) {
|
|
227
|
-
|
|
223
|
+
// Wire category without flatten — callers on public API already flat
|
|
224
|
+
if ("title" in related && "slug" in related) {
|
|
225
|
+
out.push(related as unknown as BlogCategory);
|
|
226
|
+
}
|
|
228
227
|
}
|
|
229
228
|
}
|
|
230
229
|
return out;
|
|
@@ -244,7 +243,7 @@ export async function getBlogPosts(
|
|
|
244
243
|
}
|
|
245
244
|
const locale = await resolveLocale(options.locale);
|
|
246
245
|
const status = statusFilter(options.status);
|
|
247
|
-
const and
|
|
246
|
+
const and = [requireLocaleTranslation(locale)];
|
|
248
247
|
if (status) and.unshift(status);
|
|
249
248
|
if (options.category) {
|
|
250
249
|
and.push({
|
|
@@ -260,18 +259,19 @@ export async function getBlogPosts(
|
|
|
260
259
|
},
|
|
261
260
|
});
|
|
262
261
|
}
|
|
262
|
+
const filter = { _and: and };
|
|
263
263
|
const limit = queryLimit(options.limit);
|
|
264
264
|
try {
|
|
265
265
|
const rows = await client.request(
|
|
266
266
|
readItems(collections.posts, {
|
|
267
|
-
filter
|
|
267
|
+
filter,
|
|
268
268
|
deep: translationsDeepFilter(locale),
|
|
269
269
|
fields: [...POST_LIST_FIELDS],
|
|
270
270
|
sort: options.sort ?? ["-published_at"],
|
|
271
271
|
...(limit !== undefined ? { limit } : {}),
|
|
272
272
|
}),
|
|
273
273
|
);
|
|
274
|
-
return (rows as
|
|
274
|
+
return (rows as BlogPostRow[])
|
|
275
275
|
.map((r) => flattenPost(r, locale))
|
|
276
276
|
.filter((p): p is BlogPost => p != null);
|
|
277
277
|
} catch (err) {
|
|
@@ -295,28 +295,26 @@ export async function getBlogPostBySlug(
|
|
|
295
295
|
}
|
|
296
296
|
const locale = await resolveLocale(options.locale);
|
|
297
297
|
const status = statusFilter(options.status);
|
|
298
|
-
const
|
|
299
|
-
{
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
],
|
|
306
|
-
},
|
|
298
|
+
const bySlug = {
|
|
299
|
+
translations: {
|
|
300
|
+
_and: [
|
|
301
|
+
{ languages_code: { _eq: locale } },
|
|
302
|
+
{ slug: { _eq: slug } },
|
|
303
|
+
{ title: { _nempty: true } },
|
|
304
|
+
],
|
|
307
305
|
},
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
};
|
|
307
|
+
const filter = status ? { _and: [status, bySlug] } : bySlug;
|
|
308
|
+
try {
|
|
311
309
|
const rows = await client.request(
|
|
312
310
|
readItems(collections.posts, {
|
|
313
|
-
filter
|
|
311
|
+
filter,
|
|
314
312
|
deep: translationsDeepFilter(locale),
|
|
315
313
|
fields: [...POST_DETAIL_FIELDS],
|
|
316
314
|
limit: 1,
|
|
317
315
|
}),
|
|
318
316
|
);
|
|
319
|
-
const row = (rows as
|
|
317
|
+
const row = (rows as BlogPostRow[])[0];
|
|
320
318
|
return row ? flattenPost(row, locale) : null;
|
|
321
319
|
} catch (err) {
|
|
322
320
|
dkitQueryFailed(
|
|
@@ -338,15 +336,13 @@ export async function getBlogPostById(
|
|
|
338
336
|
try {
|
|
339
337
|
const rows = await client.request(
|
|
340
338
|
readItems(collections.posts, {
|
|
341
|
-
filter: {
|
|
342
|
-
_and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)],
|
|
343
|
-
},
|
|
339
|
+
filter: { _and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)] },
|
|
344
340
|
deep: translationsDeepFilter(locale),
|
|
345
341
|
fields: [...POST_DETAIL_FIELDS],
|
|
346
342
|
limit: 1,
|
|
347
343
|
}),
|
|
348
344
|
);
|
|
349
|
-
const row = (rows as
|
|
345
|
+
const row = (rows as BlogPostRow[])[0];
|
|
350
346
|
return row ? flattenPost(row, locale) : null;
|
|
351
347
|
} catch (err) {
|
|
352
348
|
dkitQueryFailed(`getBlogPostById(${id}) failed`, err);
|
|
@@ -374,9 +370,7 @@ export async function getBlogAuthors(
|
|
|
374
370
|
...(limit !== undefined ? { limit } : {}),
|
|
375
371
|
}),
|
|
376
372
|
);
|
|
377
|
-
return (rows as
|
|
378
|
-
flattenAuthor(r, locale),
|
|
379
|
-
);
|
|
373
|
+
return (rows as BlogAuthorRow[]).map((r) => flattenAuthor(r, locale));
|
|
380
374
|
} catch (err) {
|
|
381
375
|
dkitQueryFailed(
|
|
382
376
|
`getBlogAuthors failed (collection=${collections.authors})`,
|
|
@@ -388,24 +382,26 @@ export async function getBlogAuthors(
|
|
|
388
382
|
|
|
389
383
|
export async function getBlogAuthorBySlug(
|
|
390
384
|
slug: string,
|
|
391
|
-
options:
|
|
385
|
+
options: Pick<GetBlogAuthorsOptions, "status" | "locale"> = {},
|
|
392
386
|
): Promise<BlogAuthor | null> {
|
|
393
387
|
const client = getDirectus();
|
|
394
388
|
if (!client) return null;
|
|
395
389
|
if (!collections.authors) return null;
|
|
396
390
|
const locale = await resolveLocale(options.locale);
|
|
397
391
|
const status = statusFilter(options.status);
|
|
398
|
-
const
|
|
399
|
-
|
|
392
|
+
const filter = status
|
|
393
|
+
? { _and: [status, { slug: { _eq: slug } }] }
|
|
394
|
+
: { slug: { _eq: slug } };
|
|
400
395
|
try {
|
|
401
396
|
const rows = await client.request(
|
|
402
397
|
readItems(collections.authors, {
|
|
403
|
-
filter
|
|
398
|
+
filter,
|
|
399
|
+
deep: translationsDeepFilter(locale),
|
|
404
400
|
fields: [...AUTHOR_FIELDS],
|
|
405
401
|
limit: 1,
|
|
406
402
|
}),
|
|
407
403
|
);
|
|
408
|
-
const row = (rows as
|
|
404
|
+
const row = (rows as BlogAuthorRow[])[0];
|
|
409
405
|
return row ? flattenAuthor(row, locale) : null;
|
|
410
406
|
} catch (err) {
|
|
411
407
|
dkitQueryFailed(`getBlogAuthorBySlug(${slug}) failed`, err);
|
|
@@ -415,7 +411,7 @@ export async function getBlogAuthorBySlug(
|
|
|
415
411
|
|
|
416
412
|
export async function getBlogAuthorById(
|
|
417
413
|
id: string,
|
|
418
|
-
options:
|
|
414
|
+
options: Pick<GetBlogAuthorsOptions, "locale"> = {},
|
|
419
415
|
): Promise<BlogAuthor | null> {
|
|
420
416
|
const client = getDirectus();
|
|
421
417
|
if (!client) return null;
|
|
@@ -424,10 +420,11 @@ export async function getBlogAuthorById(
|
|
|
424
420
|
try {
|
|
425
421
|
const row = await client.request(
|
|
426
422
|
readItem(collections.authors, id, {
|
|
423
|
+
deep: translationsDeepFilter(locale),
|
|
427
424
|
fields: [...AUTHOR_FIELDS],
|
|
428
425
|
}),
|
|
429
426
|
);
|
|
430
|
-
return row ? flattenAuthor(row as
|
|
427
|
+
return row ? flattenAuthor(row as BlogAuthorRow, locale) : null;
|
|
431
428
|
} catch (err) {
|
|
432
429
|
dkitQueryFailed(`getBlogAuthorById(${id}) failed`, err);
|
|
433
430
|
return null;
|
|
@@ -452,7 +449,7 @@ export async function getBlogCategories(
|
|
|
452
449
|
...(limit !== undefined ? { limit } : {}),
|
|
453
450
|
}),
|
|
454
451
|
);
|
|
455
|
-
return (rows as
|
|
452
|
+
return (rows as BlogCategoryRow[])
|
|
456
453
|
.map((r) => flattenCategory(r, locale))
|
|
457
454
|
.filter((c): c is BlogCategory => c != null);
|
|
458
455
|
} catch (err) {
|
|
@@ -489,7 +486,7 @@ export async function getBlogCategoryBySlug(
|
|
|
489
486
|
limit: 1,
|
|
490
487
|
}),
|
|
491
488
|
);
|
|
492
|
-
const row = (rows as
|
|
489
|
+
const row = (rows as BlogCategoryRow[])[0];
|
|
493
490
|
return row ? flattenCategory(row, locale) : null;
|
|
494
491
|
} catch (err) {
|
|
495
492
|
dkitQueryFailed(`getBlogCategoryBySlug(${slug}) failed`, err);
|
|
@@ -508,15 +505,13 @@ export async function getBlogCategoryById(
|
|
|
508
505
|
try {
|
|
509
506
|
const rows = await client.request(
|
|
510
507
|
readItems(collections.categories, {
|
|
511
|
-
filter: {
|
|
512
|
-
_and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)],
|
|
513
|
-
},
|
|
508
|
+
filter: { _and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)] },
|
|
514
509
|
deep: translationsDeepFilter(locale),
|
|
515
510
|
fields: [...CATEGORY_FIELDS],
|
|
516
511
|
limit: 1,
|
|
517
512
|
}),
|
|
518
513
|
);
|
|
519
|
-
const row = (rows as
|
|
514
|
+
const row = (rows as BlogCategoryRow[])[0];
|
|
520
515
|
return row ? flattenCategory(row, locale) : null;
|
|
521
516
|
} catch (err) {
|
|
522
517
|
dkitQueryFailed(`getBlogCategoryById(${id}) failed`, err);
|
|
@@ -111,7 +111,7 @@ export async function getBlogPosts(
|
|
|
111
111
|
return [];
|
|
112
112
|
}
|
|
113
113
|
const status = statusFilter(options.status);
|
|
114
|
-
const and
|
|
114
|
+
const and = [];
|
|
115
115
|
if (status) and.push(status);
|
|
116
116
|
if (options.category) {
|
|
117
117
|
and.push({
|
|
@@ -120,11 +120,12 @@ export async function getBlogPosts(
|
|
|
120
120
|
},
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
+
const filter = and.length ? { _and: and } : undefined;
|
|
123
124
|
const limit = queryLimit(options.limit);
|
|
124
125
|
try {
|
|
125
126
|
return await client.request(
|
|
126
127
|
readItems(collections.posts, {
|
|
127
|
-
filter
|
|
128
|
+
filter,
|
|
128
129
|
fields: [...POST_LIST_FIELDS],
|
|
129
130
|
sort: options.sort ?? ["-published_at"],
|
|
130
131
|
...(limit !== undefined ? { limit } : {}),
|
|
@@ -150,12 +151,13 @@ export async function getBlogPostBySlug(
|
|
|
150
151
|
return null;
|
|
151
152
|
}
|
|
152
153
|
const status = statusFilter(options.status);
|
|
153
|
-
const
|
|
154
|
-
|
|
154
|
+
const filter = status
|
|
155
|
+
? { _and: [status, { slug: { _eq: slug } }] }
|
|
156
|
+
: { slug: { _eq: slug } };
|
|
155
157
|
try {
|
|
156
158
|
const rows = await client.request(
|
|
157
159
|
readItems(collections.posts, {
|
|
158
|
-
filter
|
|
160
|
+
filter,
|
|
159
161
|
fields: [...POST_DETAIL_FIELDS],
|
|
160
162
|
limit: 1,
|
|
161
163
|
}),
|
|
@@ -215,18 +217,19 @@ export async function getBlogAuthors(
|
|
|
215
217
|
|
|
216
218
|
export async function getBlogAuthorBySlug(
|
|
217
219
|
slug: string,
|
|
218
|
-
options:
|
|
220
|
+
options: Pick<GetBlogAuthorsOptions, "status"> = {},
|
|
219
221
|
): Promise<BlogAuthor | null> {
|
|
220
222
|
const client = getDirectus();
|
|
221
223
|
if (!client) return null;
|
|
222
224
|
if (!collections.authors) return null;
|
|
223
225
|
const status = statusFilter(options.status);
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
+
const filter = status
|
|
227
|
+
? { _and: [status, { slug: { _eq: slug } }] }
|
|
228
|
+
: { slug: { _eq: slug } };
|
|
226
229
|
try {
|
|
227
230
|
const rows = await client.request(
|
|
228
231
|
readItems(collections.authors, {
|
|
229
|
-
filter
|
|
232
|
+
filter,
|
|
230
233
|
fields: [...AUTHOR_FIELDS],
|
|
231
234
|
limit: 1,
|
|
232
235
|
}),
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"title": "Sample post: getting started",
|
|
41
41
|
"slug": "sample-getting-started",
|
|
42
42
|
"excerpt": "Demo content so you can verify list/detail UI, relations, and .dkit-prose.",
|
|
43
|
-
"body": "<p>This is <strong>sample seed data</strong> from the blog module. Delete or rewrite it in Directus once your own content is ready.</p><h2>What to verify</h2><p>Use this post to confirm the public API, featured image, author relation, and rich-text rendering in your app.</p><blockquote><p>Sample HTML includes headings, quotes, and lists so you can judge layout and <code>.dkit-prose</code> immediately after install.</p></blockquote><h3>Checklist</h3><ul><li>List view shows title, excerpt, and image</li><li>Detail view renders this body</li><li>Author name and avatar resolve</li><li>Category \u201cEngineering\u201d is attached</li></ul><h3>Next steps</h3><ol><li>Edit this item in Directus</li><li>Add a second author or category</li><li>
|
|
43
|
+
"body": "<p>This is <strong>sample seed data</strong> from the blog module. Delete or rewrite it in Directus once your own content is ready.</p><h2>What to verify</h2><p>Use this post to confirm the public API, featured image, author relation, and rich-text rendering in your app.</p><blockquote><p>Sample HTML includes headings, quotes, and lists so you can judge layout and <code>.dkit-prose</code> immediately after install.</p></blockquote><h3>Checklist</h3><ul><li>List view shows title, excerpt, and image</li><li>Detail view renders this body</li><li>Author name and avatar resolve</li><li>Category \u201cEngineering\u201d is attached</li></ul><h3>Next steps</h3><ol><li>Edit this item in Directus</li><li>Add a second author or category</li><li>Fetch posts with <code>getBlogPosts</code> / <code>getBlogPostBySlug</code> from <code>lib/dkit/blog</code></li></ol><p>Replace every sample field before going to production.</p>",
|
|
44
44
|
"published_at": "2026-01-15T10:00:00.000Z",
|
|
45
45
|
"author": "11111111-1111-4111-8111-111111111111",
|
|
46
46
|
"featured_image": "55555555-5555-4555-8555-555555555555"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"title": "Sample post: getting started",
|
|
57
57
|
"slug": "sample-getting-started",
|
|
58
58
|
"excerpt": "Demo content so you can verify list/detail UI, relations, and .dkit-prose.",
|
|
59
|
-
"body": "<p>This is <strong>sample seed data</strong> from the blog module. Delete or rewrite it in Directus once your own content is ready.</p><h2>What to verify</h2><p>Use this post to confirm the public API, featured image, author relation, and rich-text rendering in your app.</p><blockquote><p>Sample HTML includes headings, quotes, and lists so you can judge layout and <code>.dkit-prose</code> immediately after install.</p></blockquote><h3>Checklist</h3><ul><li>List view shows title, excerpt, and image</li><li>Detail view renders this body</li><li>Author name and avatar resolve</li><li>Category \"Engineering\" is attached</li></ul><h3>Next steps</h3><ol><li>Edit this item in Directus</li><li>Add a second author or category</li><li>
|
|
59
|
+
"body": "<p>This is <strong>sample seed data</strong> from the blog module. Delete or rewrite it in Directus once your own content is ready.</p><h2>What to verify</h2><p>Use this post to confirm the public API, featured image, author relation, and rich-text rendering in your app.</p><blockquote><p>Sample HTML includes headings, quotes, and lists so you can judge layout and <code>.dkit-prose</code> immediately after install.</p></blockquote><h3>Checklist</h3><ul><li>List view shows title, excerpt, and image</li><li>Detail view renders this body</li><li>Author name and avatar resolve</li><li>Category \"Engineering\" is attached</li></ul><h3>Next steps</h3><ol><li>Edit this item in Directus</li><li>Add a second author or category</li><li>Fetch posts with <code>getBlogPosts</code> / <code>getBlogPostBySlug</code> from <code>lib/dkit/blog</code></li></ol><p>Replace every sample field before going to production.</p>"
|
|
60
60
|
}
|
|
61
61
|
]
|
|
62
62
|
},
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
export type DirectusFileRef = {
|
|
2
4
|
id: string;
|
|
3
5
|
};
|
|
@@ -29,6 +31,39 @@ export type BlogAuthorTranslation = {
|
|
|
29
31
|
bio?: string | null;
|
|
30
32
|
};
|
|
31
33
|
|
|
34
|
+
/* ── Wire types (Directus response / DkitSchema when multilocale) ── */
|
|
35
|
+
|
|
36
|
+
export type BlogAuthorRow = {
|
|
37
|
+
id: string;
|
|
38
|
+
status: "published" | "draft";
|
|
39
|
+
name: string;
|
|
40
|
+
slug: string;
|
|
41
|
+
avatar?: string | DirectusFileRef | null;
|
|
42
|
+
translations?: BlogAuthorTranslation[] | null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type BlogCategoryRow = {
|
|
46
|
+
id: string;
|
|
47
|
+
translations?: BlogCategoryTranslation[] | null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type PostsCategoriesRow = {
|
|
51
|
+
id: number;
|
|
52
|
+
posts_id: string | BlogPostRow;
|
|
53
|
+
categories_id: string | BlogCategoryRow;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type BlogPostRow = {
|
|
57
|
+
id: string;
|
|
58
|
+
status: "published" | "draft" | "archived";
|
|
59
|
+
published_at?: string | null;
|
|
60
|
+
featured_image?: string | DirectusFileRef | null;
|
|
61
|
+
author?: string | BlogAuthorRow | null;
|
|
62
|
+
/** M2M junction rows (expanded `categories_id` is a category wire row). */
|
|
63
|
+
categories?: PostsCategoriesRow[] | null;
|
|
64
|
+
translations?: BlogPostTranslation[] | null;
|
|
65
|
+
};
|
|
66
|
+
|
|
32
67
|
/* ── Public API types (flat — UI sees the same shape) ── */
|
|
33
68
|
|
|
34
69
|
export type BlogAuthor = {
|
|
@@ -59,38 +94,32 @@ export type BlogPost = {
|
|
|
59
94
|
categories?: Array<string | BlogCategory> | null;
|
|
60
95
|
};
|
|
61
96
|
|
|
62
|
-
export type PostsCategoriesRow = {
|
|
63
|
-
id: number;
|
|
64
|
-
posts_id: string | BlogPost;
|
|
65
|
-
categories_id: string | BlogCategory;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
97
|
/** Shared list/query options for blog fetches. */
|
|
69
98
|
export type GetBlogPostsOptions = {
|
|
70
99
|
/** Directus status filter. Default `"published"`. Pass `null` to skip. */
|
|
71
|
-
status?:
|
|
100
|
+
status?: BlogPost["status"] | null;
|
|
72
101
|
limit?: number;
|
|
73
102
|
/** Filter by category slug. */
|
|
74
103
|
category?: string;
|
|
75
|
-
sort?:
|
|
104
|
+
sort?: Array<DkitSortField<"published_at" | "id" | "status">>;
|
|
76
105
|
/** Override resolved locale (BCP 47 code). */
|
|
77
106
|
locale?: string;
|
|
78
107
|
};
|
|
79
108
|
|
|
80
109
|
export type GetBlogAuthorsOptions = {
|
|
81
|
-
status?:
|
|
110
|
+
status?: BlogAuthor["status"] | null;
|
|
82
111
|
limit?: number;
|
|
83
|
-
sort?:
|
|
112
|
+
sort?: Array<DkitSortField<"name" | "id" | "status" | "slug">>;
|
|
84
113
|
locale?: string;
|
|
85
114
|
};
|
|
86
115
|
|
|
87
116
|
export type GetBlogCategoriesOptions = {
|
|
88
117
|
limit?: number;
|
|
89
|
-
sort?:
|
|
118
|
+
sort?: Array<DkitSortField<"id">>;
|
|
90
119
|
locale?: string;
|
|
91
120
|
};
|
|
92
121
|
|
|
93
122
|
export type GetBlogBySlugOptions = {
|
|
94
|
-
status?:
|
|
123
|
+
status?: BlogPost["status"] | null;
|
|
95
124
|
locale?: string;
|
|
96
125
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
export type DirectusFileRef = {
|
|
2
4
|
id: string;
|
|
3
5
|
};
|
|
@@ -39,24 +41,24 @@ export type PostsCategoriesRow = {
|
|
|
39
41
|
/** Shared list/query options for blog fetches. */
|
|
40
42
|
export type GetBlogPostsOptions = {
|
|
41
43
|
/** Directus status filter. Default `"published"`. Pass `null` to skip. */
|
|
42
|
-
status?:
|
|
44
|
+
status?: BlogPost["status"] | null;
|
|
43
45
|
limit?: number;
|
|
44
46
|
/** Filter by category slug. */
|
|
45
47
|
category?: string;
|
|
46
|
-
sort?:
|
|
48
|
+
sort?: Array<DkitSortField<"published_at" | "id" | "status">>;
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
export type GetBlogAuthorsOptions = {
|
|
50
|
-
status?:
|
|
52
|
+
status?: BlogAuthor["status"] | null;
|
|
51
53
|
limit?: number;
|
|
52
|
-
sort?:
|
|
54
|
+
sort?: Array<DkitSortField<"name" | "id" | "status" | "slug">>;
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
export type GetBlogCategoriesOptions = {
|
|
56
58
|
limit?: number;
|
|
57
|
-
sort?:
|
|
59
|
+
sort?: Array<DkitSortField<"id">>;
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
export type GetBlogBySlugOptions = {
|
|
61
|
-
status?:
|
|
63
|
+
status?: BlogPost["status"] | null;
|
|
62
64
|
};
|