@sleekcms/client 3.1.1 → 3.3.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 +12 -1
- package/index.cjs +9 -10
- package/index.d.cts +6 -3
- package/index.d.ts +6 -3
- package/index.global.js +9 -10
- package/index.global.js.map +1 -1
- package/index.global.min.js +1 -1
- package/index.global.min.js.map +1 -1
- package/index.mjs +9 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -210,7 +210,7 @@ const pages = client.getContent('pages');
|
|
|
210
210
|
const title = client.getContent('config.title');
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
### `getPages(path)`
|
|
213
|
+
### `getPages(path, options?)`
|
|
214
214
|
|
|
215
215
|
Get all pages that start with a specific path.
|
|
216
216
|
|
|
@@ -219,6 +219,17 @@ const posts = client.getPages('/blog');
|
|
|
219
219
|
const products = client.getPages('/shop/products');
|
|
220
220
|
```
|
|
221
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
|
+
|
|
222
233
|
### `getPage(path)`
|
|
223
234
|
|
|
224
235
|
Get a single page by exact path. Returns `null` if not found.
|
package/index.cjs
CHANGED
|
@@ -141,8 +141,6 @@ async function fetchSiteContent(options) {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
return cachedData.data;
|
|
144
|
-
} else {
|
|
145
|
-
return cachedData;
|
|
146
144
|
}
|
|
147
145
|
} catch (e) {
|
|
148
146
|
}
|
|
@@ -164,11 +162,13 @@ function extractSlugs(pages, path) {
|
|
|
164
162
|
}
|
|
165
163
|
return slugs;
|
|
166
164
|
}
|
|
167
|
-
function filterPagesByPath(pages, path) {
|
|
165
|
+
function filterPagesByPath(pages, path, options) {
|
|
168
166
|
const pagesList = pages ?? [];
|
|
169
167
|
return pagesList.filter((p) => {
|
|
170
168
|
const pth = typeof p._path === "string" ? p._path : "";
|
|
171
|
-
|
|
169
|
+
if (path && !pth.startsWith(path)) return false;
|
|
170
|
+
if ((options == null ? void 0 : options.collection) && !("_slug" in p)) return false;
|
|
171
|
+
return true;
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -188,11 +188,11 @@ async function createSyncClient(options) {
|
|
|
188
188
|
function getContent(query) {
|
|
189
189
|
return applyJmes(data, query);
|
|
190
190
|
}
|
|
191
|
-
function getPages(path) {
|
|
191
|
+
function getPages(path, options2) {
|
|
192
192
|
if (!path) {
|
|
193
193
|
throw new Error("[SleekCMS] path is required for getPages");
|
|
194
194
|
}
|
|
195
|
-
return filterPagesByPath(data.pages, path);
|
|
195
|
+
return filterPagesByPath(data.pages, path, options2);
|
|
196
196
|
}
|
|
197
197
|
function getPage(path) {
|
|
198
198
|
if (!path) {
|
|
@@ -251,11 +251,10 @@ function createAsyncClient(options) {
|
|
|
251
251
|
if (!search2) return null;
|
|
252
252
|
return await fetchSiteContent({ siteToken, env, search: search2, lang, cache, resolveEnv });
|
|
253
253
|
}
|
|
254
|
-
async function getPages(path) {
|
|
255
|
-
if (syncClient) return syncClient.getPages(path);
|
|
254
|
+
async function getPages(path, options2) {
|
|
255
|
+
if (syncClient) return syncClient.getPages(path, options2);
|
|
256
256
|
const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
|
|
257
|
-
|
|
258
|
-
else return filterPagesByPath(pages, path);
|
|
257
|
+
return filterPagesByPath(pages, path, options2);
|
|
259
258
|
}
|
|
260
259
|
async function getPage(path) {
|
|
261
260
|
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 };
|
package/index.global.js
CHANGED
|
@@ -1653,8 +1653,6 @@ var SleekCMS = (() => {
|
|
|
1653
1653
|
}
|
|
1654
1654
|
}
|
|
1655
1655
|
return cachedData.data;
|
|
1656
|
-
} else {
|
|
1657
|
-
return cachedData;
|
|
1658
1656
|
}
|
|
1659
1657
|
} catch (e) {
|
|
1660
1658
|
}
|
|
@@ -1676,11 +1674,13 @@ var SleekCMS = (() => {
|
|
|
1676
1674
|
}
|
|
1677
1675
|
return slugs;
|
|
1678
1676
|
}
|
|
1679
|
-
function filterPagesByPath(pages, path) {
|
|
1677
|
+
function filterPagesByPath(pages, path, options) {
|
|
1680
1678
|
const pagesList = pages ?? [];
|
|
1681
1679
|
return pagesList.filter((p) => {
|
|
1682
1680
|
const pth = typeof p._path === "string" ? p._path : "";
|
|
1683
|
-
|
|
1681
|
+
if (path && !pth.startsWith(path)) return false;
|
|
1682
|
+
if (options?.collection && !("_slug" in p)) return false;
|
|
1683
|
+
return true;
|
|
1684
1684
|
});
|
|
1685
1685
|
}
|
|
1686
1686
|
|
|
@@ -1700,11 +1700,11 @@ var SleekCMS = (() => {
|
|
|
1700
1700
|
function getContent(query) {
|
|
1701
1701
|
return applyJmes(data, query);
|
|
1702
1702
|
}
|
|
1703
|
-
function getPages(path) {
|
|
1703
|
+
function getPages(path, options2) {
|
|
1704
1704
|
if (!path) {
|
|
1705
1705
|
throw new Error("[SleekCMS] path is required for getPages");
|
|
1706
1706
|
}
|
|
1707
|
-
return filterPagesByPath(data.pages, path);
|
|
1707
|
+
return filterPagesByPath(data.pages, path, options2);
|
|
1708
1708
|
}
|
|
1709
1709
|
function getPage(path) {
|
|
1710
1710
|
if (!path) {
|
|
@@ -1763,11 +1763,10 @@ var SleekCMS = (() => {
|
|
|
1763
1763
|
if (!search2) return null;
|
|
1764
1764
|
return await fetchSiteContent({ siteToken, env, search: search2, lang, cache, resolveEnv });
|
|
1765
1765
|
}
|
|
1766
|
-
async function getPages(path) {
|
|
1767
|
-
if (syncClient) return syncClient.getPages(path);
|
|
1766
|
+
async function getPages(path, options2) {
|
|
1767
|
+
if (syncClient) return syncClient.getPages(path, options2);
|
|
1768
1768
|
const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
|
|
1769
|
-
|
|
1770
|
-
else return filterPagesByPath(pages, path);
|
|
1769
|
+
return filterPagesByPath(pages, path, options2);
|
|
1771
1770
|
}
|
|
1772
1771
|
async function getPage(path) {
|
|
1773
1772
|
if (syncClient) return syncClient.getPage(path);
|