@sleekcms/client 3.1.0 → 3.2.0
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 +54 -1
- package/index.cjs +9 -8
- package/index.d.cts +6 -3
- package/index.d.ts +6 -3
- package/index.global.js +1824 -0
- package/index.global.js.map +1 -0
- package/index.global.min.js +2 -0
- package/index.global.min.js.map +1 -0
- package/index.mjs +9 -8
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -6,10 +6,52 @@ Sign in at [sleekcms.com](https://sleekcms.com), create your content models, add
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
+
### From NPM
|
|
10
|
+
|
|
9
11
|
```bash
|
|
10
12
|
npm install @sleekcms/client
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
### From CDN (Browser)
|
|
16
|
+
|
|
17
|
+
Include the library directly in your HTML from a CDN:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<!-- From unpkg -->
|
|
21
|
+
<script src="https://unpkg.com/@sleekcms/client"></script>
|
|
22
|
+
|
|
23
|
+
<!-- From jsdelivr -->
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@sleekcms/client"></script>
|
|
25
|
+
|
|
26
|
+
<!-- Specific version -->
|
|
27
|
+
<script src="https://unpkg.com/@sleekcms/client@3.1.0"></script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The library is available globally as `SleekCMS`:
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<script src="https://unpkg.com/@sleekcms/client"></script>
|
|
34
|
+
<script>
|
|
35
|
+
// Use the sync client
|
|
36
|
+
SleekCMS.createSyncClient({
|
|
37
|
+
siteToken: 'your-site-token',
|
|
38
|
+
env: 'latest'
|
|
39
|
+
}).then(client => {
|
|
40
|
+
const page = client.getPage('/about');
|
|
41
|
+
console.log(page);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Or use the async client
|
|
45
|
+
const client = SleekCMS.createAsyncClient({
|
|
46
|
+
siteToken: 'your-site-token'
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
client.getPage('/pricing').then(page => {
|
|
50
|
+
console.log(page);
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
```
|
|
54
|
+
|
|
13
55
|
## Quick Start
|
|
14
56
|
|
|
15
57
|
```typescript
|
|
@@ -168,7 +210,7 @@ const pages = client.getContent('pages');
|
|
|
168
210
|
const title = client.getContent('config.title');
|
|
169
211
|
```
|
|
170
212
|
|
|
171
|
-
### `getPages(path)`
|
|
213
|
+
### `getPages(path, options?)`
|
|
172
214
|
|
|
173
215
|
Get all pages that start with a specific path.
|
|
174
216
|
|
|
@@ -177,6 +219,17 @@ const posts = client.getPages('/blog');
|
|
|
177
219
|
const products = client.getPages('/shop/products');
|
|
178
220
|
```
|
|
179
221
|
|
|
222
|
+
**Options:**
|
|
223
|
+
|
|
224
|
+
| Option | Type | Description |
|
|
225
|
+
|--------|------|-------------|
|
|
226
|
+
| `collection` | `boolean` | If `true`, only returns pages that are part of a collection / multiple records |
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
// Get only collection pages / multiple records
|
|
230
|
+
const posts = client.getPages('/blog', { collection: true });
|
|
231
|
+
```
|
|
232
|
+
|
|
180
233
|
### `getPage(path)`
|
|
181
234
|
|
|
182
235
|
Get a single page by exact path. Returns `null` if not found.
|
package/index.cjs
CHANGED
|
@@ -164,11 +164,13 @@ function extractSlugs(pages, path) {
|
|
|
164
164
|
}
|
|
165
165
|
return slugs;
|
|
166
166
|
}
|
|
167
|
-
function filterPagesByPath(pages, path) {
|
|
167
|
+
function filterPagesByPath(pages, path, options) {
|
|
168
168
|
const pagesList = pages ?? [];
|
|
169
169
|
return pagesList.filter((p) => {
|
|
170
170
|
const pth = typeof p._path === "string" ? p._path : "";
|
|
171
|
-
|
|
171
|
+
if (path && !pth.startsWith(path)) return false;
|
|
172
|
+
if ((options == null ? void 0 : options.collection) && !("_slug" in p)) return false;
|
|
173
|
+
return true;
|
|
172
174
|
});
|
|
173
175
|
}
|
|
174
176
|
|
|
@@ -188,11 +190,11 @@ async function createSyncClient(options) {
|
|
|
188
190
|
function getContent(query) {
|
|
189
191
|
return applyJmes(data, query);
|
|
190
192
|
}
|
|
191
|
-
function getPages(path) {
|
|
193
|
+
function getPages(path, options2) {
|
|
192
194
|
if (!path) {
|
|
193
195
|
throw new Error("[SleekCMS] path is required for getPages");
|
|
194
196
|
}
|
|
195
|
-
return filterPagesByPath(data.pages, path);
|
|
197
|
+
return filterPagesByPath(data.pages, path, options2);
|
|
196
198
|
}
|
|
197
199
|
function getPage(path) {
|
|
198
200
|
if (!path) {
|
|
@@ -251,11 +253,10 @@ function createAsyncClient(options) {
|
|
|
251
253
|
if (!search2) return null;
|
|
252
254
|
return await fetchSiteContent({ siteToken, env, search: search2, lang, cache, resolveEnv });
|
|
253
255
|
}
|
|
254
|
-
async function getPages(path) {
|
|
255
|
-
if (syncClient) return syncClient.getPages(path);
|
|
256
|
+
async function getPages(path, options2) {
|
|
257
|
+
if (syncClient) return syncClient.getPages(path, options2);
|
|
256
258
|
const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
|
|
257
|
-
|
|
258
|
-
else return filterPagesByPath(pages, path);
|
|
259
|
+
return filterPagesByPath(pages, path, options2);
|
|
259
260
|
}
|
|
260
261
|
async function getPage(path) {
|
|
261
262
|
if (syncClient) return syncClient.getPage(path);
|
package/index.d.cts
CHANGED
|
@@ -11,6 +11,9 @@ type Options = Array<{
|
|
|
11
11
|
label: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}>;
|
|
14
|
+
type GetPagesOptions = {
|
|
15
|
+
collection?: boolean;
|
|
16
|
+
};
|
|
14
17
|
interface SleekSiteContent {
|
|
15
18
|
entries?: {
|
|
16
19
|
[handle: string]: Entry | Entry[];
|
|
@@ -40,7 +43,7 @@ interface ClientOptions {
|
|
|
40
43
|
}
|
|
41
44
|
interface SleekClient {
|
|
42
45
|
getContent(query?: string): SleekSiteContent;
|
|
43
|
-
getPages(path: string): SleekSiteContent["pages"];
|
|
46
|
+
getPages(path: string, options?: GetPagesOptions): SleekSiteContent["pages"];
|
|
44
47
|
getPage(path: string): Page | null;
|
|
45
48
|
getEntry(handle: string): Entry | Entry[] | null;
|
|
46
49
|
getSlugs(path: string): string[];
|
|
@@ -49,7 +52,7 @@ interface SleekClient {
|
|
|
49
52
|
}
|
|
50
53
|
interface SleekAsyncClient {
|
|
51
54
|
getContent(query?: string): Promise<SleekSiteContent>;
|
|
52
|
-
getPages(path: string): Promise<SleekSiteContent["pages"]>;
|
|
55
|
+
getPages(path: string, options?: GetPagesOptions): Promise<SleekSiteContent["pages"]>;
|
|
53
56
|
getPage(path: string): Promise<Page | null>;
|
|
54
57
|
getEntry(handle: string): Promise<Entry | Entry[] | null>;
|
|
55
58
|
getSlugs(path: string): Promise<string[]>;
|
|
@@ -62,4 +65,4 @@ interface SleekAsyncClient {
|
|
|
62
65
|
declare function createSyncClient(options: ClientOptions): Promise<SleekClient>;
|
|
63
66
|
declare function createAsyncClient(options: ClientOptions): SleekAsyncClient | any;
|
|
64
67
|
|
|
65
|
-
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type Image, type Options, type Page, type SleekAsyncClient, type SleekClient, type SleekSiteContent, type SyncCacheAdapter, createAsyncClient, createSyncClient };
|
|
68
|
+
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type GetPagesOptions, type Image, type Options, type Page, type SleekAsyncClient, type SleekClient, type SleekSiteContent, type SyncCacheAdapter, createAsyncClient, createSyncClient };
|
package/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ type Options = Array<{
|
|
|
11
11
|
label: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}>;
|
|
14
|
+
type GetPagesOptions = {
|
|
15
|
+
collection?: boolean;
|
|
16
|
+
};
|
|
14
17
|
interface SleekSiteContent {
|
|
15
18
|
entries?: {
|
|
16
19
|
[handle: string]: Entry | Entry[];
|
|
@@ -40,7 +43,7 @@ interface ClientOptions {
|
|
|
40
43
|
}
|
|
41
44
|
interface SleekClient {
|
|
42
45
|
getContent(query?: string): SleekSiteContent;
|
|
43
|
-
getPages(path: string): SleekSiteContent["pages"];
|
|
46
|
+
getPages(path: string, options?: GetPagesOptions): SleekSiteContent["pages"];
|
|
44
47
|
getPage(path: string): Page | null;
|
|
45
48
|
getEntry(handle: string): Entry | Entry[] | null;
|
|
46
49
|
getSlugs(path: string): string[];
|
|
@@ -49,7 +52,7 @@ interface SleekClient {
|
|
|
49
52
|
}
|
|
50
53
|
interface SleekAsyncClient {
|
|
51
54
|
getContent(query?: string): Promise<SleekSiteContent>;
|
|
52
|
-
getPages(path: string): Promise<SleekSiteContent["pages"]>;
|
|
55
|
+
getPages(path: string, options?: GetPagesOptions): Promise<SleekSiteContent["pages"]>;
|
|
53
56
|
getPage(path: string): Promise<Page | null>;
|
|
54
57
|
getEntry(handle: string): Promise<Entry | Entry[] | null>;
|
|
55
58
|
getSlugs(path: string): Promise<string[]>;
|
|
@@ -62,4 +65,4 @@ interface SleekAsyncClient {
|
|
|
62
65
|
declare function createSyncClient(options: ClientOptions): Promise<SleekClient>;
|
|
63
66
|
declare function createAsyncClient(options: ClientOptions): SleekAsyncClient | any;
|
|
64
67
|
|
|
65
|
-
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type Image, type Options, type Page, type SleekAsyncClient, type SleekClient, type SleekSiteContent, type SyncCacheAdapter, createAsyncClient, createSyncClient };
|
|
68
|
+
export { type AsyncCacheAdapter, type ClientOptions, type Entry, type GetPagesOptions, type Image, type Options, type Page, type SleekAsyncClient, type SleekClient, type SleekSiteContent, type SyncCacheAdapter, createAsyncClient, createSyncClient };
|