includio-cms 0.0.21 → 0.0.23
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 +5 -9
- package/dist/core/server/entries/utils/getEntryTranslation.d.ts +1 -2
- package/dist/core/server/entries/utils/getEntryTranslation.js +14 -20
- package/dist/core/server/fields/populateEntry.d.ts +3 -0
- package/dist/core/server/fields/populateEntry.js +9 -0
- package/dist/core/server/fields/resolveUrlFields.d.ts +3 -0
- package/dist/core/server/fields/resolveUrlFields.js +103 -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,6 @@
|
|
|
1
|
-
import { resolveMediaFields } from '../../fields/resolveImageFields.js';
|
|
2
1
|
import z from 'zod';
|
|
3
2
|
import { getCMS } from '../../../cms.js';
|
|
4
|
-
import {
|
|
3
|
+
import { populateEntryData } from '../../fields/populateEntry.js';
|
|
5
4
|
// Helper function to transform string values to localized objects
|
|
6
5
|
function transformDataValuesToLocalized(dataValues, defaultLanguage) {
|
|
7
6
|
const result = {};
|
|
@@ -83,10 +82,9 @@ export const getEntry = async (data, options = {}) => {
|
|
|
83
82
|
return null;
|
|
84
83
|
}
|
|
85
84
|
const config = getCMS().getBySlug(entry.slug);
|
|
86
|
-
const translatedEntry = getEntryTranslation(entry, language);
|
|
87
85
|
return {
|
|
88
86
|
...entry,
|
|
89
|
-
data: await
|
|
87
|
+
data: await populateEntryData(entry.data, config.fields, language),
|
|
90
88
|
populated: true
|
|
91
89
|
};
|
|
92
90
|
};
|
|
@@ -118,10 +116,9 @@ export const getEntries = async (data, options = {}) => {
|
|
|
118
116
|
const entries = await getRawEntries(transformedData);
|
|
119
117
|
return Promise.all(entries.map(async (entry) => {
|
|
120
118
|
const config = getCMS().getBySlug(entry.slug);
|
|
121
|
-
const translatedEntry = getEntryTranslation(entry, language);
|
|
122
119
|
return {
|
|
123
120
|
...entry,
|
|
124
|
-
data: await
|
|
121
|
+
data: await populateEntryData(entry.data, config.fields, language),
|
|
125
122
|
populated: true
|
|
126
123
|
};
|
|
127
124
|
}));
|
|
@@ -141,10 +138,9 @@ export const getCollectionEntries = async (slug, options = {}) => {
|
|
|
141
138
|
}
|
|
142
139
|
const entries = await getRawCollectionEntries(slug);
|
|
143
140
|
const language = options.language || getCMS().languages[0];
|
|
144
|
-
|
|
145
|
-
return Promise.all(translatedEntries.map(async (row) => ({
|
|
141
|
+
return Promise.all(entries.map(async (row) => ({
|
|
146
142
|
...row,
|
|
147
|
-
data: await
|
|
143
|
+
data: await populateEntryData(row.data, config.fields, language),
|
|
148
144
|
populated: true
|
|
149
145
|
})));
|
|
150
146
|
};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function getEntryTranslation(entry: RawEntry, language: string): RawEntry;
|
|
1
|
+
export declare function translateObject(obj: unknown, language: string): unknown;
|
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
export function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export 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];
|
|
5
9
|
}
|
|
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;
|
|
10
|
+
// W przeciwnym razie rekurencyjnie przechodzimy przez wszystkie pola
|
|
11
|
+
const result = {};
|
|
12
|
+
for (const key in obj) {
|
|
13
|
+
result[key] = translateObject(obj[key], language);
|
|
17
14
|
}
|
|
18
|
-
return
|
|
15
|
+
return result;
|
|
19
16
|
}
|
|
20
|
-
return
|
|
21
|
-
...entry,
|
|
22
|
-
data: translate(entry.data)
|
|
23
|
-
};
|
|
17
|
+
return obj;
|
|
24
18
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { translateObject } from '../entries/utils/getEntryTranslation.js';
|
|
2
|
+
import { resolveMediaFields } from './resolveImageFields.js';
|
|
3
|
+
import { resolveUrlFields } from './resolveUrlFields.js';
|
|
4
|
+
export async function populateEntryData(data, fields, language) {
|
|
5
|
+
let populatedData = translateObject(data, language);
|
|
6
|
+
populatedData = await resolveMediaFields(populatedData, fields);
|
|
7
|
+
populatedData = await resolveUrlFields(populatedData, fields, language);
|
|
8
|
+
return populatedData;
|
|
9
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { getCMS } from '../../cms.js';
|
|
2
|
+
import { translateObject } from '../entries/utils/getEntryTranslation.js';
|
|
3
|
+
export async function resolveUrlFields(data, fields, language) {
|
|
4
|
+
const entriesIds = [];
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
const collectIds = (value, fields) => {
|
|
7
|
+
for (const field of fields) {
|
|
8
|
+
const val = value?.[field.slug];
|
|
9
|
+
if (val == null)
|
|
10
|
+
continue;
|
|
11
|
+
switch (field.type) {
|
|
12
|
+
case 'url': {
|
|
13
|
+
if (typeof val === 'object' &&
|
|
14
|
+
val !== null &&
|
|
15
|
+
'id' in val &&
|
|
16
|
+
typeof val.id === 'string') {
|
|
17
|
+
entriesIds.push(val.id);
|
|
18
|
+
}
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case 'object':
|
|
22
|
+
collectIds(val.data, field.fields);
|
|
23
|
+
break;
|
|
24
|
+
case 'array':
|
|
25
|
+
if (Array.isArray(val)) {
|
|
26
|
+
val.forEach((item) => {
|
|
27
|
+
// Find the object definition for this item based on its slug
|
|
28
|
+
const objectDef = field.of.find((objDef) => objDef.slug === item.slug);
|
|
29
|
+
if (objectDef) {
|
|
30
|
+
collectIds(item.data, objectDef.fields);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
collectIds(data, fields);
|
|
39
|
+
if (entriesIds.length === 0)
|
|
40
|
+
return data;
|
|
41
|
+
const entries = (await getCMS().databaseAdapter.getEntries({
|
|
42
|
+
data: {
|
|
43
|
+
ids: entriesIds
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
const entriesMap = Object.fromEntries(entries.map((m) => [m.id, m]));
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
const resolveValues = (value, fields) => {
|
|
49
|
+
// Start with a copy of all original data to preserve non-field properties
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
const result = { ...value };
|
|
52
|
+
for (const field of fields) {
|
|
53
|
+
const val = value?.[field.slug];
|
|
54
|
+
if (val == null) {
|
|
55
|
+
result[field.slug] = val;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
switch (field.type) {
|
|
59
|
+
case 'url': {
|
|
60
|
+
if (typeof val === 'object' &&
|
|
61
|
+
val !== null &&
|
|
62
|
+
'id' in val &&
|
|
63
|
+
typeof val.id === 'string') {
|
|
64
|
+
result[field.slug] = entriesMap[val.id].data.seo?.slug ?? val;
|
|
65
|
+
}
|
|
66
|
+
if (typeof val === 'object' &&
|
|
67
|
+
val !== null &&
|
|
68
|
+
'url' in val &&
|
|
69
|
+
typeof val.url === 'object' &&
|
|
70
|
+
val.url !== null) {
|
|
71
|
+
result[field.slug] = translateObject(val.url, language);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'object':
|
|
76
|
+
result[field.slug] = {
|
|
77
|
+
...val,
|
|
78
|
+
data: resolveValues(val.data, field.fields)
|
|
79
|
+
};
|
|
80
|
+
break;
|
|
81
|
+
case 'array':
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
result[field.slug] = val.map((item) => {
|
|
84
|
+
// Find the object definition for this item based on its slug
|
|
85
|
+
const objectDef = field.of.find((objDef) => objDef.slug === item.slug);
|
|
86
|
+
if (objectDef) {
|
|
87
|
+
return {
|
|
88
|
+
...item,
|
|
89
|
+
data: resolveValues(item.data, objectDef.fields)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// If no matching object definition found, return item unchanged
|
|
93
|
+
return item;
|
|
94
|
+
});
|
|
95
|
+
break;
|
|
96
|
+
default:
|
|
97
|
+
result[field.slug] = val;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
return resolveValues(data, fields);
|
|
103
|
+
}
|
|
@@ -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>
|