@evenicanpm/cms 2.0.0 → 2.2.2
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/content/blogs/index.d.ts +2 -0
- package/dist/content/blogs/types.d.ts +2 -0
- package/dist/index.d.ts +13 -0
- package/package.json +2 -2
- package/src/content/blogs/index.ts +15 -2
- package/src/content/blogs/types.ts +4 -2
- package/src/content/pages/types.ts +1 -1
- package/src/index.ts +2 -0
- package/src/locales/index.ts +15 -0
- package/src/locales/types.ts +10 -0
- package/src/media/get-image-url.ts +17 -2
|
@@ -4,8 +4,10 @@ declare const getBlogs: (options: {
|
|
|
4
4
|
pageSize: number;
|
|
5
5
|
page: number;
|
|
6
6
|
};
|
|
7
|
+
locale?: string;
|
|
7
8
|
}) => Promise<import("strapi-sdk-js").StrapiResponse<Blog[]>>;
|
|
8
9
|
declare const getBlog: (options: {
|
|
9
10
|
id: string;
|
|
11
|
+
locale?: string;
|
|
10
12
|
}) => Promise<import("strapi-sdk-js").StrapiResponse<Blog>>;
|
|
11
13
|
export { getBlogs, getBlog };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,23 @@ import * as navigation from "./content/navigation";
|
|
|
3
3
|
import * as pages from "./content/pages";
|
|
4
4
|
import * as media from "./media";
|
|
5
5
|
import * as session from "./session";
|
|
6
|
+
declare const locales: {
|
|
7
|
+
getLocales: () => Promise<{
|
|
8
|
+
id: number;
|
|
9
|
+
documentId?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
code: string;
|
|
12
|
+
isDefault?: boolean;
|
|
13
|
+
createdAt?: string;
|
|
14
|
+
updatedAt?: string;
|
|
15
|
+
publishedAt?: string;
|
|
16
|
+
}[]>;
|
|
17
|
+
};
|
|
6
18
|
export declare const cms: {
|
|
7
19
|
blogs: typeof blogs;
|
|
8
20
|
pages: typeof pages;
|
|
9
21
|
navigation: typeof navigation;
|
|
22
|
+
locales: typeof locales;
|
|
10
23
|
media: typeof media;
|
|
11
24
|
session: typeof session;
|
|
12
25
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evenicanpm/cms",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Strapi 5 client and queries for e4 Headless.",
|
|
5
5
|
"author": "Evenica",
|
|
6
6
|
"type": "module",
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/node": "^24.0.13"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "eb81763cdb511681ffaf1da5140e957afa149816"
|
|
20
20
|
}
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { strapi } from "../../client";
|
|
2
2
|
import type { Blog } from "./types";
|
|
3
3
|
|
|
4
|
+
type BlogOptions = {
|
|
5
|
+
locale?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
4
8
|
// Queries
|
|
5
9
|
const getBlogs = async (options: {
|
|
6
10
|
pagination: { pageSize: number; page: number };
|
|
11
|
+
locale?: string;
|
|
7
12
|
}) => {
|
|
8
13
|
return await strapi.find<Blog>("blogs", {
|
|
9
14
|
pagination: { ...options.pagination, withCount: true },
|
|
10
15
|
populate: "*",
|
|
16
|
+
...getLocaleOption(options),
|
|
11
17
|
});
|
|
12
18
|
};
|
|
13
19
|
|
|
14
|
-
const getBlog = async (options: { id: string }) => {
|
|
15
|
-
return await strapi.findOne<Blog>("blogs", options.id, {
|
|
20
|
+
const getBlog = async (options: { id: string; locale?: string }) => {
|
|
21
|
+
return await strapi.findOne<Blog>("blogs", options.id, {
|
|
22
|
+
populate: "*",
|
|
23
|
+
...getLocaleOption(options),
|
|
24
|
+
});
|
|
16
25
|
};
|
|
17
26
|
|
|
18
27
|
export { getBlog, getBlogs };
|
|
28
|
+
|
|
29
|
+
const getLocaleOption = (options: BlogOptions) => {
|
|
30
|
+
return options.locale ? { locale: options.locale } : {};
|
|
31
|
+
};
|
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
export interface Blog {
|
|
9
9
|
title: string;
|
|
10
|
-
content:
|
|
11
|
-
image:
|
|
10
|
+
content: unknown;
|
|
11
|
+
image: unknown;
|
|
12
|
+
author?: string;
|
|
12
13
|
documentId: string;
|
|
13
14
|
id: number;
|
|
15
|
+
locale?: string;
|
|
14
16
|
shortDescription: string;
|
|
15
17
|
createdAt: Date;
|
|
16
18
|
publishedAt: Date;
|
|
@@ -17,7 +17,7 @@ export interface Page {
|
|
|
17
17
|
// blocks.seo component
|
|
18
18
|
metaTitle?: string;
|
|
19
19
|
metaDescription?: string;
|
|
20
|
-
shareImage?:
|
|
20
|
+
shareImage?: { media: { url: string } };
|
|
21
21
|
metaImage?: { media: { url: string } };
|
|
22
22
|
metaKeywords: Array<string>;
|
|
23
23
|
meta: Array<MetaElement>;
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as blogs from "./content/blogs";
|
|
2
2
|
import * as navigation from "./content/navigation";
|
|
3
3
|
import * as pages from "./content/pages";
|
|
4
|
+
import * as locales from "./locales";
|
|
4
5
|
import * as media from "./media";
|
|
5
6
|
import * as session from "./session";
|
|
6
7
|
|
|
@@ -8,6 +9,7 @@ export const cms = {
|
|
|
8
9
|
blogs,
|
|
9
10
|
pages,
|
|
10
11
|
navigation,
|
|
12
|
+
locales,
|
|
11
13
|
media,
|
|
12
14
|
session,
|
|
13
15
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { strapi } from "../client";
|
|
2
|
+
import type { CmsLocale } from "./types";
|
|
3
|
+
|
|
4
|
+
const getLocales = async () => {
|
|
5
|
+
try {
|
|
6
|
+
return await strapi.request<CmsLocale[]>("get", "/i18n/locales", {
|
|
7
|
+
headers: {},
|
|
8
|
+
});
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.log("error fetching strapi locale data", error);
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { getLocales };
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface ImageFormat {
|
|
2
|
+
ext: string;
|
|
3
|
+
url: string;
|
|
4
|
+
hash: string;
|
|
5
|
+
mime: string;
|
|
6
|
+
name: string;
|
|
7
|
+
path: string | null;
|
|
8
|
+
size: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Formats {
|
|
14
|
+
[size: string]: ImageFormat;
|
|
15
|
+
}
|
|
16
|
+
|
|
2
17
|
// Media
|
|
3
18
|
/**
|
|
4
19
|
* @param formats formats array from CMS data
|
|
5
20
|
* @param size size of the image
|
|
6
21
|
* @returns largest available image url
|
|
7
22
|
*/
|
|
8
|
-
export const getImageUrl = (formats:
|
|
23
|
+
export const getImageUrl = (formats: Formats, size?: string) => {
|
|
9
24
|
if (size) {
|
|
10
25
|
return formats[size]?.url;
|
|
11
26
|
}
|