@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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
export type NavMenu = {
|
|
2
4
|
id: string;
|
|
3
5
|
status: "published" | "draft" | "archived";
|
|
@@ -28,17 +30,17 @@ export type NavMenuTree = {
|
|
|
28
30
|
|
|
29
31
|
export type GetNavMenusOptions = {
|
|
30
32
|
/** Directus status filter. Default `"published"`. Pass `null` to skip. */
|
|
31
|
-
status?:
|
|
33
|
+
status?: NavMenu["status"] | null;
|
|
32
34
|
limit?: number;
|
|
33
|
-
sort?:
|
|
35
|
+
sort?: Array<DkitSortField<"key" | "id" | "status">>;
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
export type GetNavMenuByKeyOptions = {
|
|
37
|
-
status?:
|
|
39
|
+
status?: NavMenu["status"] | null;
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
export type GetNavItemsOptions = {
|
|
41
|
-
status?:
|
|
43
|
+
status?: NavItem["status"] | null;
|
|
42
44
|
/** When true, return a nested tree (default). Flat list when false. */
|
|
43
45
|
tree?: boolean;
|
|
44
46
|
};
|
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dkitQueryFailed,
|
|
3
3
|
getDirectus,
|
|
4
|
-
readItem,
|
|
5
4
|
readItems,
|
|
6
5
|
} from "@/lib/dkit/client";
|
|
7
6
|
import { collections } from "@/lib/dkit/config";
|
|
8
7
|
import { queryLimit, statusFilter } from "@/lib/dkit/helpers";
|
|
9
8
|
import {
|
|
10
|
-
isUsableTranslation,
|
|
11
|
-
pickTranslation,
|
|
12
9
|
requireLocaleTranslation,
|
|
13
10
|
resolveLocale,
|
|
14
11
|
translationsDeepFilter,
|
|
12
|
+
withLocale,
|
|
15
13
|
} from "@/lib/dkit/i18n";
|
|
16
14
|
import type {
|
|
17
15
|
GetPageBySlugOptions,
|
|
18
16
|
GetPagesOptions,
|
|
19
17
|
SitePage,
|
|
20
|
-
|
|
18
|
+
SitePageRow,
|
|
21
19
|
} from "./types.multilocale";
|
|
22
20
|
|
|
23
21
|
export type {
|
|
24
22
|
GetPageBySlugOptions,
|
|
25
23
|
GetPagesOptions,
|
|
26
24
|
SitePage,
|
|
25
|
+
SitePageRow,
|
|
27
26
|
SitePageTranslation,
|
|
28
27
|
} from "./types.multilocale";
|
|
29
28
|
|
|
30
|
-
function flattenPage(row:
|
|
31
|
-
|
|
32
|
-
row
|
|
29
|
+
function flattenPage(row: SitePageRow, locale: string): SitePage | null {
|
|
30
|
+
return withLocale(
|
|
31
|
+
row,
|
|
33
32
|
locale,
|
|
33
|
+
(r, t) => ({
|
|
34
|
+
id: r.id,
|
|
35
|
+
status: r.status,
|
|
36
|
+
title: t.title,
|
|
37
|
+
slug: t.slug,
|
|
38
|
+
excerpt: t.excerpt ?? null,
|
|
39
|
+
body: t.body ?? null,
|
|
40
|
+
published_at: r.published_at ?? null,
|
|
41
|
+
}),
|
|
42
|
+
{ required: ["title", "slug"] },
|
|
34
43
|
);
|
|
35
|
-
if (!isUsableTranslation(trans)) return null;
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
id: row.id as string,
|
|
39
|
-
status: row.status as SitePage["status"],
|
|
40
|
-
title: trans!.title!,
|
|
41
|
-
slug: trans!.slug!,
|
|
42
|
-
excerpt: trans?.excerpt ?? null,
|
|
43
|
-
body: trans?.body ?? null,
|
|
44
|
-
published_at: (row.published_at as string | null) ?? null,
|
|
45
|
-
};
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
const PAGE_LIST_FIELDS = [
|
|
@@ -72,20 +70,21 @@ export async function getPages(
|
|
|
72
70
|
}
|
|
73
71
|
const locale = await resolveLocale(options.locale);
|
|
74
72
|
const status = statusFilter(options.status);
|
|
75
|
-
const
|
|
76
|
-
|
|
73
|
+
const filter = status
|
|
74
|
+
? { _and: [status, requireLocaleTranslation(locale)] }
|
|
75
|
+
: requireLocaleTranslation(locale);
|
|
77
76
|
const limit = queryLimit(options.limit);
|
|
78
77
|
try {
|
|
79
78
|
const rows = await client.request(
|
|
80
79
|
readItems(collections.pages, {
|
|
81
|
-
filter
|
|
80
|
+
filter,
|
|
82
81
|
deep: translationsDeepFilter(locale),
|
|
83
82
|
fields: [...PAGE_LIST_FIELDS],
|
|
84
83
|
sort: options.sort ?? ["-published_at"],
|
|
85
84
|
...(limit !== undefined ? { limit } : {}),
|
|
86
85
|
}),
|
|
87
86
|
);
|
|
88
|
-
return (rows as
|
|
87
|
+
return (rows as SitePageRow[])
|
|
89
88
|
.map((r) => flattenPage(r, locale))
|
|
90
89
|
.filter((p): p is SitePage => p != null);
|
|
91
90
|
} catch (err) {
|
|
@@ -106,28 +105,26 @@ export async function getPageBySlug(
|
|
|
106
105
|
}
|
|
107
106
|
const locale = await resolveLocale(options.locale);
|
|
108
107
|
const status = statusFilter(options.status);
|
|
109
|
-
const
|
|
110
|
-
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
],
|
|
117
|
-
},
|
|
108
|
+
const bySlug = {
|
|
109
|
+
translations: {
|
|
110
|
+
_and: [
|
|
111
|
+
{ languages_code: { _eq: locale } },
|
|
112
|
+
{ slug: { _eq: slug } },
|
|
113
|
+
{ title: { _nempty: true } },
|
|
114
|
+
],
|
|
118
115
|
},
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
};
|
|
117
|
+
const filter = status ? { _and: [status, bySlug] } : bySlug;
|
|
121
118
|
try {
|
|
122
119
|
const rows = await client.request(
|
|
123
120
|
readItems(collections.pages, {
|
|
124
|
-
filter
|
|
121
|
+
filter,
|
|
125
122
|
deep: translationsDeepFilter(locale),
|
|
126
123
|
fields: [...PAGE_DETAIL_FIELDS],
|
|
127
124
|
limit: 1,
|
|
128
125
|
}),
|
|
129
126
|
);
|
|
130
|
-
const row = (rows as
|
|
127
|
+
const row = (rows as SitePageRow[])[0];
|
|
131
128
|
return row ? flattenPage(row, locale) : null;
|
|
132
129
|
} catch (err) {
|
|
133
130
|
dkitQueryFailed(`getPageBySlug(${slug}) failed (collection=${collections.pages})`, err);
|
|
@@ -146,15 +143,13 @@ export async function getPageById(
|
|
|
146
143
|
try {
|
|
147
144
|
const rows = await client.request(
|
|
148
145
|
readItems(collections.pages, {
|
|
149
|
-
filter: {
|
|
150
|
-
_and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)],
|
|
151
|
-
},
|
|
146
|
+
filter: { _and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)] },
|
|
152
147
|
deep: translationsDeepFilter(locale),
|
|
153
148
|
fields: [...PAGE_DETAIL_FIELDS],
|
|
154
149
|
limit: 1,
|
|
155
150
|
}),
|
|
156
151
|
);
|
|
157
|
-
const row = (rows as
|
|
152
|
+
const row = (rows as SitePageRow[])[0];
|
|
158
153
|
return row ? flattenPage(row, locale) : null;
|
|
159
154
|
} catch (err) {
|
|
160
155
|
dkitQueryFailed(`getPageById(${id}) failed`, err);
|
|
@@ -83,12 +83,13 @@ export async function getPageBySlug(
|
|
|
83
83
|
return null;
|
|
84
84
|
}
|
|
85
85
|
const status = statusFilter(options.status);
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const filter = status
|
|
87
|
+
? { _and: [status, { slug: { _eq: slug } }] }
|
|
88
|
+
: { slug: { _eq: slug } };
|
|
88
89
|
try {
|
|
89
90
|
const rows = await client.request(
|
|
90
91
|
readItems(collections.pages, {
|
|
91
|
-
filter
|
|
92
|
+
filter,
|
|
92
93
|
fields: [...PAGE_DETAIL_FIELDS],
|
|
93
94
|
limit: 1,
|
|
94
95
|
}),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
/* ── Translation row type ── */
|
|
2
4
|
|
|
3
5
|
export type SitePageTranslation = {
|
|
@@ -10,6 +12,15 @@ export type SitePageTranslation = {
|
|
|
10
12
|
body?: string | null;
|
|
11
13
|
};
|
|
12
14
|
|
|
15
|
+
/* ── Wire type (Directus / DkitSchema when multilocales) ── */
|
|
16
|
+
|
|
17
|
+
export type SitePageRow = {
|
|
18
|
+
id: string;
|
|
19
|
+
status: "published" | "draft" | "archived";
|
|
20
|
+
published_at?: string | null;
|
|
21
|
+
translations?: SitePageTranslation[] | null;
|
|
22
|
+
};
|
|
23
|
+
|
|
13
24
|
/* ── Public API type (flat) ── */
|
|
14
25
|
|
|
15
26
|
export type SitePage = {
|
|
@@ -25,13 +36,13 @@ export type SitePage = {
|
|
|
25
36
|
/** Shared list/query options for pages fetches. */
|
|
26
37
|
export type GetPagesOptions = {
|
|
27
38
|
/** Directus status filter. Default `"published"`. Pass `null` to skip. */
|
|
28
|
-
status?:
|
|
39
|
+
status?: SitePage["status"] | null;
|
|
29
40
|
limit?: number;
|
|
30
|
-
sort?:
|
|
41
|
+
sort?: Array<DkitSortField<"published_at" | "id" | "status">>;
|
|
31
42
|
locale?: string;
|
|
32
43
|
};
|
|
33
44
|
|
|
34
45
|
export type GetPageBySlugOptions = {
|
|
35
|
-
status?:
|
|
46
|
+
status?: SitePage["status"] | null;
|
|
36
47
|
locale?: string;
|
|
37
48
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
export type SitePage = {
|
|
2
4
|
id: string;
|
|
3
5
|
status: "published" | "draft" | "archived";
|
|
@@ -11,11 +13,11 @@ export type SitePage = {
|
|
|
11
13
|
/** Shared list/query options for pages fetches. */
|
|
12
14
|
export type GetPagesOptions = {
|
|
13
15
|
/** Directus status filter. Default `"published"`. Pass `null` to skip. */
|
|
14
|
-
status?:
|
|
16
|
+
status?: SitePage["status"] | null;
|
|
15
17
|
limit?: number;
|
|
16
|
-
sort?:
|
|
18
|
+
sort?: Array<DkitSortField<"published_at" | "id" | "status">>;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export type GetPageBySlugOptions = {
|
|
20
|
-
status?:
|
|
22
|
+
status?: SitePage["status"] | null;
|
|
21
23
|
};
|
|
@@ -3,76 +3,146 @@ import {
|
|
|
3
3
|
directusFileId,
|
|
4
4
|
dkitQueryFailed,
|
|
5
5
|
getDirectus,
|
|
6
|
-
readItem,
|
|
7
6
|
readItems,
|
|
8
7
|
} from "@/lib/dkit/client";
|
|
9
8
|
import { collections } from "@/lib/dkit/config";
|
|
10
9
|
import { queryLimit, statusFilter } from "@/lib/dkit/helpers";
|
|
11
10
|
import {
|
|
12
|
-
isUsableTranslation,
|
|
13
|
-
pickTranslation,
|
|
14
11
|
requireLocaleTranslation,
|
|
15
12
|
resolveLocale,
|
|
16
13
|
translationsDeepFilter,
|
|
14
|
+
withLocale,
|
|
17
15
|
} from "@/lib/dkit/i18n";
|
|
18
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
DirectusFileRef,
|
|
18
|
+
GetProjectBySlugOptions,
|
|
19
|
+
GetProjectsOptions,
|
|
20
|
+
Project,
|
|
21
|
+
ProjectRow,
|
|
22
|
+
} from "./types.multilocale";
|
|
19
23
|
|
|
20
|
-
export type {
|
|
24
|
+
export type {
|
|
25
|
+
DirectusFileRef,
|
|
26
|
+
GetProjectBySlugOptions,
|
|
27
|
+
GetProjectsOptions,
|
|
28
|
+
Project,
|
|
29
|
+
ProjectRow,
|
|
30
|
+
ProjectTranslation,
|
|
31
|
+
} from "./types.multilocale";
|
|
21
32
|
|
|
22
|
-
function flattenProject(row:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
function flattenProject(row: ProjectRow, locale: string): Project | null {
|
|
34
|
+
return withLocale(
|
|
35
|
+
row,
|
|
36
|
+
locale,
|
|
37
|
+
(r, t) => ({
|
|
38
|
+
id: r.id,
|
|
39
|
+
status: r.status,
|
|
40
|
+
title: t.title,
|
|
41
|
+
slug: t.slug,
|
|
42
|
+
summary: t.summary ?? null,
|
|
43
|
+
body: t.body ?? null,
|
|
44
|
+
featured_image: r.featured_image,
|
|
45
|
+
client: r.client ?? null,
|
|
46
|
+
location: t.location ?? null,
|
|
47
|
+
completed_on: r.completed_on ?? null,
|
|
48
|
+
sort: r.sort ?? null,
|
|
49
|
+
}),
|
|
50
|
+
{ required: ["title", "slug"] },
|
|
51
|
+
);
|
|
39
52
|
}
|
|
40
53
|
|
|
41
|
-
const PROJECT_LIST_FIELDS = [
|
|
42
|
-
|
|
54
|
+
const PROJECT_LIST_FIELDS = [
|
|
55
|
+
"id",
|
|
56
|
+
"status",
|
|
57
|
+
"featured_image",
|
|
58
|
+
"client",
|
|
59
|
+
"completed_on",
|
|
60
|
+
"sort",
|
|
61
|
+
{
|
|
62
|
+
translations: [
|
|
63
|
+
"id",
|
|
64
|
+
"languages_code",
|
|
65
|
+
"title",
|
|
66
|
+
"slug",
|
|
67
|
+
"summary",
|
|
68
|
+
"location",
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
] as const;
|
|
72
|
+
const PROJECT_DETAIL_FIELDS = [
|
|
73
|
+
"id",
|
|
74
|
+
"status",
|
|
75
|
+
"featured_image",
|
|
76
|
+
"client",
|
|
77
|
+
"completed_on",
|
|
78
|
+
"sort",
|
|
79
|
+
{
|
|
80
|
+
translations: [
|
|
81
|
+
"id",
|
|
82
|
+
"languages_code",
|
|
83
|
+
"title",
|
|
84
|
+
"slug",
|
|
85
|
+
"summary",
|
|
86
|
+
"location",
|
|
87
|
+
"body",
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
] as const;
|
|
43
91
|
|
|
44
92
|
export function projectImageUrl(project: Project): string | null {
|
|
45
|
-
const id = directusFileId(
|
|
93
|
+
const id = directusFileId(
|
|
94
|
+
project.featured_image as string | DirectusFileRef | null | undefined,
|
|
95
|
+
);
|
|
46
96
|
return id ? directusAssetUrl(id) : null;
|
|
47
97
|
}
|
|
48
98
|
|
|
49
|
-
export async function getProjects(
|
|
50
|
-
|
|
51
|
-
|
|
99
|
+
export async function getProjects(
|
|
100
|
+
options: GetProjectsOptions = {},
|
|
101
|
+
): Promise<Project[]> {
|
|
102
|
+
const client = getDirectus();
|
|
103
|
+
if (!client) return [];
|
|
104
|
+
if (!collections.projects) {
|
|
105
|
+
dkitQueryFailed("collections.projects missing — re-run `dkit add projects`");
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
52
108
|
const locale = await resolveLocale(options.locale);
|
|
53
109
|
const status = statusFilter(options.status);
|
|
54
|
-
const
|
|
55
|
-
|
|
110
|
+
const filter = status
|
|
111
|
+
? { _and: [status, requireLocaleTranslation(locale)] }
|
|
112
|
+
: requireLocaleTranslation(locale);
|
|
56
113
|
const limit = queryLimit(options.limit);
|
|
57
114
|
try {
|
|
58
|
-
const rows = await client.request(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
115
|
+
const rows = await client.request(
|
|
116
|
+
readItems(collections.projects, {
|
|
117
|
+
filter,
|
|
118
|
+
deep: translationsDeepFilter(locale),
|
|
119
|
+
fields: [...PROJECT_LIST_FIELDS],
|
|
120
|
+
sort: options.sort ?? ["sort", "-completed_on"],
|
|
121
|
+
...(limit !== undefined ? { limit } : {}),
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
return (rows as ProjectRow[])
|
|
65
125
|
.map((r) => flattenProject(r, locale))
|
|
66
126
|
.filter((p): p is Project => p != null);
|
|
67
|
-
} catch (err) {
|
|
127
|
+
} catch (err) {
|
|
128
|
+
dkitQueryFailed(`getProjects failed`, err);
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
68
131
|
}
|
|
69
132
|
|
|
70
|
-
export async function getProjectBySlug(
|
|
71
|
-
|
|
72
|
-
|
|
133
|
+
export async function getProjectBySlug(
|
|
134
|
+
slug: string,
|
|
135
|
+
options: GetProjectBySlugOptions = {},
|
|
136
|
+
): Promise<Project | null> {
|
|
137
|
+
const client = getDirectus();
|
|
138
|
+
if (!client) return null;
|
|
139
|
+
if (!collections.projects) {
|
|
140
|
+
dkitQueryFailed("collections.projects missing");
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
73
143
|
const locale = await resolveLocale(options.locale);
|
|
74
144
|
const status = statusFilter(options.status);
|
|
75
|
-
const
|
|
145
|
+
const bySlug = {
|
|
76
146
|
translations: {
|
|
77
147
|
_and: [
|
|
78
148
|
{ languages_code: { _eq: locale } },
|
|
@@ -80,32 +150,46 @@ export async function getProjectBySlug(slug: string, options: GetProjectBySlugOp
|
|
|
80
150
|
{ title: { _nempty: true } },
|
|
81
151
|
],
|
|
82
152
|
},
|
|
83
|
-
}
|
|
84
|
-
|
|
153
|
+
};
|
|
154
|
+
const filter = status ? { _and: [status, bySlug] } : bySlug;
|
|
85
155
|
try {
|
|
86
|
-
const rows = await client.request(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
156
|
+
const rows = await client.request(
|
|
157
|
+
readItems(collections.projects, {
|
|
158
|
+
filter,
|
|
159
|
+
deep: translationsDeepFilter(locale),
|
|
160
|
+
fields: [...PROJECT_DETAIL_FIELDS],
|
|
161
|
+
limit: 1,
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
const row = (rows as ProjectRow[])[0];
|
|
165
|
+
return row ? flattenProject(row, locale) : null;
|
|
166
|
+
} catch (err) {
|
|
167
|
+
dkitQueryFailed(`getProjectBySlug(${slug}) failed`, err);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
94
170
|
}
|
|
95
171
|
|
|
96
|
-
export async function getProjectById(
|
|
97
|
-
|
|
172
|
+
export async function getProjectById(
|
|
173
|
+
id: string,
|
|
174
|
+
options: GetProjectBySlugOptions = {},
|
|
175
|
+
): Promise<Project | null> {
|
|
176
|
+
const client = getDirectus();
|
|
177
|
+
if (!client) return null;
|
|
178
|
+
if (!collections.projects) return null;
|
|
98
179
|
const locale = await resolveLocale(options.locale);
|
|
99
180
|
try {
|
|
100
|
-
const rows = await client.request(
|
|
101
|
-
|
|
102
|
-
_and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)],
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const row = (rows as
|
|
109
|
-
return row ? flattenProject(row
|
|
110
|
-
} catch (err) {
|
|
181
|
+
const rows = await client.request(
|
|
182
|
+
readItems(collections.projects, {
|
|
183
|
+
filter: { _and: [{ id: { _eq: id } }, requireLocaleTranslation(locale)] },
|
|
184
|
+
deep: translationsDeepFilter(locale),
|
|
185
|
+
fields: [...PROJECT_DETAIL_FIELDS],
|
|
186
|
+
limit: 1,
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
const row = (rows as ProjectRow[])[0];
|
|
190
|
+
return row ? flattenProject(row, locale) : null;
|
|
191
|
+
} catch (err) {
|
|
192
|
+
dkitQueryFailed(`getProjectById(${id}) failed`, err);
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
111
195
|
}
|
|
@@ -69,13 +69,12 @@ export async function getProjects(
|
|
|
69
69
|
return [];
|
|
70
70
|
}
|
|
71
71
|
const status = statusFilter(options.status);
|
|
72
|
-
const
|
|
73
|
-
if (status) and.push(status);
|
|
72
|
+
const filter = status;
|
|
74
73
|
const limit = queryLimit(options.limit);
|
|
75
74
|
try {
|
|
76
75
|
return await client.request(
|
|
77
76
|
readItems(collections.projects, {
|
|
78
|
-
filter
|
|
77
|
+
filter,
|
|
79
78
|
fields: [...PROJECT_LIST_FIELDS],
|
|
80
79
|
sort: options.sort ?? ["sort", "-completed_on", "title"],
|
|
81
80
|
...(limit !== undefined ? { limit } : {}),
|
|
@@ -101,12 +100,13 @@ export async function getProjectBySlug(
|
|
|
101
100
|
return null;
|
|
102
101
|
}
|
|
103
102
|
const status = statusFilter(options.status);
|
|
104
|
-
const
|
|
105
|
-
|
|
103
|
+
const filter = status
|
|
104
|
+
? { _and: [status, { slug: { _eq: slug } }] }
|
|
105
|
+
: { slug: { _eq: slug } };
|
|
106
106
|
try {
|
|
107
107
|
const rows = await client.request(
|
|
108
108
|
readItems(collections.projects, {
|
|
109
|
-
filter
|
|
109
|
+
filter,
|
|
110
110
|
fields: [...PROJECT_DETAIL_FIELDS],
|
|
111
111
|
limit: 1,
|
|
112
112
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": [
|
|
3
3
|
{
|
|
4
|
-
"id": "
|
|
4
|
+
"id": "c1000000-0000-4000-8000-000000000001",
|
|
5
5
|
"filename_download": "brand-identity-cover.jpg",
|
|
6
6
|
"title": "Sample cover — brand identity (Unsplash)",
|
|
7
7
|
"type": "image/jpeg",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"client": "Acme Corp",
|
|
20
20
|
"location": "Amsterdam, NL",
|
|
21
21
|
"completed_on": "2025-09-15",
|
|
22
|
-
"featured_image": "
|
|
22
|
+
"featured_image": "c1000000-0000-4000-8000-000000000001",
|
|
23
23
|
"sort": 1,
|
|
24
24
|
"body": "<p>This is <strong>sample seed data</strong> from the projects module. Replace or delete it once your own case studies are ready.</p><h2>What to verify</h2><p>Use this project to confirm the public API, featured image, client/location metadata, 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>Scope</h3><ul><li>Logo concept and refinement</li><li>Typography and colour palette</li><li>Brand guidelines document</li></ul><h3>Outcome</h3><ol><li>Open this item in Directus to edit fields</li><li>Confirm list and detail views render correctly</li><li>Replace every sample field before going to production</li></ol><p>Safe to delete after verifying the install.</p>"
|
|
25
25
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": [
|
|
3
3
|
{
|
|
4
|
-
"id": "
|
|
4
|
+
"id": "c1000000-0000-4000-8000-000000000001",
|
|
5
5
|
"filename_download": "brand-identity-cover.jpg",
|
|
6
6
|
"title": "Sample cover — brand identity (Unsplash)",
|
|
7
7
|
"type": "image/jpeg",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"status": "published",
|
|
16
16
|
"sort": 1,
|
|
17
17
|
"client": "Example Corp",
|
|
18
|
-
"featured_image": "
|
|
18
|
+
"featured_image": "c1000000-0000-4000-8000-000000000001",
|
|
19
19
|
"translations": [
|
|
20
20
|
{
|
|
21
21
|
"languages_code": "en-US",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
export type DirectusFileRef = { id: string };
|
|
2
4
|
|
|
3
5
|
export type ProjectTranslation = {
|
|
@@ -11,6 +13,16 @@ export type ProjectTranslation = {
|
|
|
11
13
|
body?: string | null;
|
|
12
14
|
};
|
|
13
15
|
|
|
16
|
+
export type ProjectRow = {
|
|
17
|
+
id: string;
|
|
18
|
+
status: "published" | "draft" | "archived";
|
|
19
|
+
featured_image?: string | DirectusFileRef | null;
|
|
20
|
+
client?: string | null;
|
|
21
|
+
completed_on?: string | null;
|
|
22
|
+
sort?: number | null;
|
|
23
|
+
translations?: ProjectTranslation[] | null;
|
|
24
|
+
};
|
|
25
|
+
|
|
14
26
|
export type Project = {
|
|
15
27
|
id: string;
|
|
16
28
|
status: "published" | "draft" | "archived";
|
|
@@ -26,13 +38,13 @@ export type Project = {
|
|
|
26
38
|
};
|
|
27
39
|
|
|
28
40
|
export type GetProjectsOptions = {
|
|
29
|
-
status?:
|
|
41
|
+
status?: Project["status"] | null;
|
|
30
42
|
limit?: number;
|
|
31
|
-
sort?:
|
|
43
|
+
sort?: Array<DkitSortField<"sort" | "completed_on" | "id" | "status">>;
|
|
32
44
|
locale?: string;
|
|
33
45
|
};
|
|
34
46
|
|
|
35
47
|
export type GetProjectBySlugOptions = {
|
|
36
|
-
status?:
|
|
48
|
+
status?: Project["status"] | null;
|
|
37
49
|
locale?: string;
|
|
38
50
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
type DkitSortField<T extends string> = T | `-${T}`;
|
|
2
|
+
|
|
1
3
|
export type DirectusFileRef = {
|
|
2
4
|
id: string;
|
|
3
5
|
};
|
|
@@ -18,11 +20,11 @@ export type Project = {
|
|
|
18
20
|
|
|
19
21
|
export type GetProjectsOptions = {
|
|
20
22
|
/** Directus status filter. Default `"published"`. Pass `null` to skip. */
|
|
21
|
-
status?:
|
|
23
|
+
status?: Project["status"] | null;
|
|
22
24
|
limit?: number;
|
|
23
|
-
sort?:
|
|
25
|
+
sort?: Array<DkitSortField<"sort" | "completed_on" | "id" | "status">>;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export type GetProjectBySlugOptions = {
|
|
27
|
-
status?:
|
|
29
|
+
status?: Project["status"] | null;
|
|
28
30
|
};
|