@sleekcms/client 3.1.1 → 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 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
@@ -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
- return pth.startsWith(path);
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
- if (!path) return pages;
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 };
package/index.global.js CHANGED
@@ -1676,11 +1676,13 @@ var SleekCMS = (() => {
1676
1676
  }
1677
1677
  return slugs;
1678
1678
  }
1679
- function filterPagesByPath(pages, path) {
1679
+ function filterPagesByPath(pages, path, options) {
1680
1680
  const pagesList = pages ?? [];
1681
1681
  return pagesList.filter((p) => {
1682
1682
  const pth = typeof p._path === "string" ? p._path : "";
1683
- return pth.startsWith(path);
1683
+ if (path && !pth.startsWith(path)) return false;
1684
+ if (options?.collection && !("_slug" in p)) return false;
1685
+ return true;
1684
1686
  });
1685
1687
  }
1686
1688
 
@@ -1700,11 +1702,11 @@ var SleekCMS = (() => {
1700
1702
  function getContent(query) {
1701
1703
  return applyJmes(data, query);
1702
1704
  }
1703
- function getPages(path) {
1705
+ function getPages(path, options2) {
1704
1706
  if (!path) {
1705
1707
  throw new Error("[SleekCMS] path is required for getPages");
1706
1708
  }
1707
- return filterPagesByPath(data.pages, path);
1709
+ return filterPagesByPath(data.pages, path, options2);
1708
1710
  }
1709
1711
  function getPage(path) {
1710
1712
  if (!path) {
@@ -1763,11 +1765,10 @@ var SleekCMS = (() => {
1763
1765
  if (!search2) return null;
1764
1766
  return await fetchSiteContent({ siteToken, env, search: search2, lang, cache, resolveEnv });
1765
1767
  }
1766
- async function getPages(path) {
1767
- if (syncClient) return syncClient.getPages(path);
1768
+ async function getPages(path, options2) {
1769
+ if (syncClient) return syncClient.getPages(path, options2);
1768
1770
  const pages = await fetchSiteContent({ siteToken, env, search: "pages", lang, cache, resolveEnv });
1769
- if (!path) return pages;
1770
- else return filterPagesByPath(pages, path);
1771
+ return filterPagesByPath(pages, path, options2);
1771
1772
  }
1772
1773
  async function getPage(path) {
1773
1774
  if (syncClient) return syncClient.getPage(path);