includio-cms 0.0.21 → 0.0.22
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/admin/remote/entry.remote.d.ts +1 -1
- package/dist/core/server/entries/operations/get.js +4 -4
- package/dist/core/server/entries/utils/getEntryTranslation.js +20 -17
- package/dist/core/server/fields/populateEntry.d.ts +3 -0
- package/dist/core/server/fields/populateEntry.js +7 -0
- package/dist/core/server/fields/resolveUrlFields.d.ts +3 -0
- package/dist/core/server/fields/resolveUrlFields.js +95 -0
- package/dist/core/server/generator/fields.js +3 -3
- package/dist/sveltekit/components/seo.svelte +18 -0
- package/dist/sveltekit/components/seo.svelte.d.ts +7 -0
- package/package.json +1 -1
|
@@ -4,9 +4,9 @@ export declare const getEntries: import("@sveltejs/kit").RemoteQueryFunction<{
|
|
|
4
4
|
slug?: string | undefined;
|
|
5
5
|
status?: "draft" | "published" | "archived" | undefined;
|
|
6
6
|
type?: "collection" | "singleton" | undefined;
|
|
7
|
+
ids?: string[] | undefined;
|
|
7
8
|
dataValues?: Record<string, unknown> | undefined;
|
|
8
9
|
dataLike?: Record<string, unknown> | undefined;
|
|
9
|
-
ids?: string[] | undefined;
|
|
10
10
|
} | undefined;
|
|
11
11
|
}, import("../../types/entries.js").Entry[]>;
|
|
12
12
|
export declare const createNewEntry: import("@sveltejs/kit").RemoteQueryFunction<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { resolveMediaFields } from '../../fields/resolveImageFields.js';
|
|
2
1
|
import z from 'zod';
|
|
3
2
|
import { getCMS } from '../../../cms.js';
|
|
4
3
|
import { getEntryTranslation } from '../utils/getEntryTranslation.js';
|
|
4
|
+
import { populateEntry } from '../../fields/populateEntry.js';
|
|
5
5
|
// Helper function to transform string values to localized objects
|
|
6
6
|
function transformDataValuesToLocalized(dataValues, defaultLanguage) {
|
|
7
7
|
const result = {};
|
|
@@ -86,7 +86,7 @@ export const getEntry = async (data, options = {}) => {
|
|
|
86
86
|
const translatedEntry = getEntryTranslation(entry, language);
|
|
87
87
|
return {
|
|
88
88
|
...entry,
|
|
89
|
-
data: await
|
|
89
|
+
data: await populateEntry(translatedEntry.data, config.fields),
|
|
90
90
|
populated: true
|
|
91
91
|
};
|
|
92
92
|
};
|
|
@@ -121,7 +121,7 @@ export const getEntries = async (data, options = {}) => {
|
|
|
121
121
|
const translatedEntry = getEntryTranslation(entry, language);
|
|
122
122
|
return {
|
|
123
123
|
...entry,
|
|
124
|
-
data: await
|
|
124
|
+
data: await populateEntry(translatedEntry.data, config.fields),
|
|
125
125
|
populated: true
|
|
126
126
|
};
|
|
127
127
|
}));
|
|
@@ -144,7 +144,7 @@ export const getCollectionEntries = async (slug, options = {}) => {
|
|
|
144
144
|
const translatedEntries = entries.map((entry) => getEntryTranslation(entry, language));
|
|
145
145
|
return Promise.all(translatedEntries.map(async (row) => ({
|
|
146
146
|
...row,
|
|
147
|
-
data: await
|
|
147
|
+
data: await populateEntry(row.data, config.fields),
|
|
148
148
|
populated: true
|
|
149
149
|
})));
|
|
150
150
|
};
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function translateObject(obj, language) {
|
|
2
|
+
if (Array.isArray(obj)) {
|
|
3
|
+
return obj.map((item) => translateObject(item, language));
|
|
4
|
+
}
|
|
5
|
+
if (obj && typeof obj === 'object') {
|
|
6
|
+
// Jeśli obiekt zawiera klucz języka, zwracamy tłumaczenie
|
|
7
|
+
if (language in obj) {
|
|
8
|
+
return obj[language];
|
|
9
|
+
}
|
|
10
|
+
if ('url' in obj) {
|
|
11
|
+
return obj.url[language] ?? obj.url;
|
|
5
12
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
// W przeciwnym razie rekurencyjnie przechodzimy przez wszystkie pola
|
|
12
|
-
const result = {};
|
|
13
|
-
for (const key in obj) {
|
|
14
|
-
result[key] = translate(obj[key]);
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
13
|
+
// W przeciwnym razie rekurencyjnie przechodzimy przez wszystkie pola
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const key in obj) {
|
|
16
|
+
result[key] = translateObject(obj[key], language);
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return result;
|
|
19
19
|
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
export function getEntryTranslation(entry, language) {
|
|
20
23
|
return {
|
|
21
24
|
...entry,
|
|
22
|
-
data:
|
|
25
|
+
data: translateObject(entry.data, language)
|
|
23
26
|
};
|
|
24
27
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { resolveMediaFields } from './resolveImageFields.js';
|
|
2
|
+
import { resolveUrlFields } from './resolveUrlFields.js';
|
|
3
|
+
export async function populateEntry(data, fields) {
|
|
4
|
+
let populatedData = await resolveMediaFields(data, fields);
|
|
5
|
+
populatedData = await resolveUrlFields(populatedData, fields);
|
|
6
|
+
return populatedData;
|
|
7
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getCMS } from '../../cms.js';
|
|
2
|
+
export async function resolveUrlFields(data, fields) {
|
|
3
|
+
const entriesIds = [];
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
const collectIds = (value, fields) => {
|
|
6
|
+
for (const field of fields) {
|
|
7
|
+
const val = value?.[field.slug];
|
|
8
|
+
if (val == null)
|
|
9
|
+
continue;
|
|
10
|
+
switch (field.type) {
|
|
11
|
+
case 'url': {
|
|
12
|
+
if (typeof val === 'object' &&
|
|
13
|
+
val !== null &&
|
|
14
|
+
'id' in val &&
|
|
15
|
+
typeof val.id === 'string') {
|
|
16
|
+
entriesIds.push(val.id);
|
|
17
|
+
}
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case 'object':
|
|
21
|
+
collectIds(val.data, field.fields);
|
|
22
|
+
break;
|
|
23
|
+
case 'array':
|
|
24
|
+
if (Array.isArray(val)) {
|
|
25
|
+
val.forEach((item) => {
|
|
26
|
+
// Find the object definition for this item based on its slug
|
|
27
|
+
const objectDef = field.of.find((objDef) => objDef.slug === item.slug);
|
|
28
|
+
if (objectDef) {
|
|
29
|
+
collectIds(item.data, objectDef.fields);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
collectIds(data, fields);
|
|
38
|
+
if (entriesIds.length === 0)
|
|
39
|
+
return data;
|
|
40
|
+
const entries = (await getCMS().databaseAdapter.getEntries({
|
|
41
|
+
data: {
|
|
42
|
+
ids: entriesIds
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
const entriesMap = Object.fromEntries(entries.map((m) => [m.id, m]));
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const resolveValues = (value, fields) => {
|
|
48
|
+
// Start with a copy of all original data to preserve non-field properties
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
const result = { ...value };
|
|
51
|
+
for (const field of fields) {
|
|
52
|
+
const val = value?.[field.slug];
|
|
53
|
+
if (val == null) {
|
|
54
|
+
result[field.slug] = val;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
switch (field.type) {
|
|
58
|
+
case 'url': {
|
|
59
|
+
if (typeof val === 'object' &&
|
|
60
|
+
val !== null &&
|
|
61
|
+
'id' in val &&
|
|
62
|
+
typeof val.id === 'string') {
|
|
63
|
+
result[field.slug] = entriesMap[val.id].data.seo?.slug ?? val;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'object':
|
|
68
|
+
result[field.slug] = {
|
|
69
|
+
...val,
|
|
70
|
+
data: resolveValues(val.data, field.fields)
|
|
71
|
+
};
|
|
72
|
+
break;
|
|
73
|
+
case 'array':
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
result[field.slug] = val.map((item) => {
|
|
76
|
+
// Find the object definition for this item based on its slug
|
|
77
|
+
const objectDef = field.of.find((objDef) => objDef.slug === item.slug);
|
|
78
|
+
if (objectDef) {
|
|
79
|
+
return {
|
|
80
|
+
...item,
|
|
81
|
+
data: resolveValues(item.data, objectDef.fields)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// If no matching object definition found, return item unchanged
|
|
85
|
+
return item;
|
|
86
|
+
});
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
result[field.slug] = val;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
return resolveValues(data, fields);
|
|
95
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
type Props = {
|
|
3
|
+
title?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
let { title, description }: Props = $props();
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<svelte:head>
|
|
11
|
+
{#if title}
|
|
12
|
+
<title>{title}</title>
|
|
13
|
+
<meta name="title" content={title} />
|
|
14
|
+
{/if}
|
|
15
|
+
{#if description}
|
|
16
|
+
<meta name="description" content={description} />
|
|
17
|
+
{/if}
|
|
18
|
+
</svelte:head>
|