@pramen/cms-astro 0.0.22 → 0.0.24

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +9 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pramen/cms-astro",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Astro integration for @pramen/cms — a build-time content-collection loader + a BlockRenderer for rendering CMS blocks in .astro pages.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -37,6 +37,8 @@ export interface AssembledPage {
37
37
  slug: string;
38
38
  status: string;
39
39
  locale: string;
40
+ /** The page's content-type slug (e.g. "article", "page"). `null` if unknown. */
41
+ contentType: string | null;
40
42
  translationGroupId: string | null;
41
43
  translations: { locale: string; slug: string }[];
42
44
  fields: Record<string, unknown> | null;
@@ -50,6 +52,8 @@ export interface AssembledPage {
50
52
  export interface PublishedPageRef {
51
53
  slug: string;
52
54
  locale: string;
55
+ /** Content-type slug — lets a loader filter to one type (see `CmsLoaderOptions.type`). */
56
+ contentType: string | null;
53
57
  updatedAt: string;
54
58
  }
55
59
 
@@ -102,6 +106,9 @@ export interface CmsLoaderOptions {
102
106
  client: CmsClient;
103
107
  /** Restrict to one locale (else every published page of every locale is loaded). */
104
108
  locale?: string;
109
+ /** Restrict to one content-type slug (e.g. "article" or "page"), so separate collections
110
+ * can each load their own type. Omit to load every type. */
111
+ type?: string;
105
112
  /**
106
113
  * Map an AssembledPage to the entry `data` stored in the collection. Default flattens the
107
114
  * page's own `fields` up to the top level and adds `title/slug/locale/seo/regions/blocks`
@@ -117,6 +124,7 @@ const defaultTransform = (p: AssembledPage): Record<string, unknown> => {
117
124
  title: p.page.title,
118
125
  slug: p.page.slug,
119
126
  locale: p.page.locale,
127
+ contentType: p.page.contentType,
120
128
  status: p.page.status,
121
129
  seo: p.page.seo ?? null,
122
130
  translations: p.page.translations,
@@ -136,7 +144,7 @@ export function cmsLoader(opts: CmsLoaderOptions): Loader {
136
144
  name: "@pramen/cms",
137
145
  async load({ store, logger, parseData, generateDigest }: LoaderContext): Promise<void> {
138
146
  const refs = await opts.client.listPublishedPages();
139
- const wanted = opts.locale ? refs.filter((r) => r.locale === opts.locale) : refs;
147
+ const wanted = refs.filter((r) => (opts.locale ? r.locale === opts.locale : true) && (opts.type ? r.contentType === opts.type : true));
140
148
  store.clear();
141
149
  let loaded = 0;
142
150
  for (const ref of wanted) {