rankrunners-cms 0.0.21 → 0.0.22

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rankrunners-cms",
3
3
  "type": "module",
4
- "version": "0.0.21",
4
+ "version": "0.0.22",
5
5
  "peerDependencies": {
6
6
  "@puckeditor/core": "^0.21.1",
7
7
  "next": "^16.1.6",
@@ -22,10 +22,7 @@ import React from "react";
22
22
  import type { Config } from "@puckeditor/core";
23
23
  import type { CMSUserData } from "../editor/types";
24
24
  import { NotFound } from "./components/NotFound";
25
- import type {
26
- CMSBlogConfig,
27
- CMSConfig,
28
- } from "./seo/types";
25
+ import type { CMSBlogConfig, CMSConfig } from "./seo/types";
29
26
  import type {
30
27
  PublicPostDTO,
31
28
  PublicPostSeoDetailsDTO,
@@ -42,7 +39,7 @@ const cmsSearchEntries = {
42
39
 
43
40
  interface BlogMatch {
44
41
  kind: "list" | "detail";
45
- blog: CMSBlogConfig;
42
+ blogIndex: number;
46
43
  /** Slug of the post (only set when kind === "detail") */
47
44
  slug?: string;
48
45
  }
@@ -53,20 +50,20 @@ function matchBlogRoute(
53
50
  ): BlogMatch | null {
54
51
  if (!blogs) return null;
55
52
 
56
- for (const blog of blogs) {
53
+ for (const [index, blog] of blogs.entries()) {
57
54
  const prefix = blog.prefix.replace(/^\/+|\/+$/g, "");
58
55
 
59
56
  // Detail: {prefix}/{slug}
60
57
  if (pathname.startsWith(`${prefix}/`)) {
61
58
  const slug = pathname.slice(prefix.length + 1);
62
59
  if (slug.length > 0) {
63
- return { kind: "detail", blog, slug };
60
+ return { kind: "detail", blogIndex: index, slug };
64
61
  }
65
62
  }
66
63
 
67
64
  // List: exact match on prefix
68
65
  if (pathname === prefix) {
69
- return { kind: "list", blog };
66
+ return { kind: "list", blogIndex: index };
70
67
  }
71
68
  }
72
69
 
@@ -159,6 +156,10 @@ export function withCMS<
159
156
  const blogMatch = matchBlogRoute(pathname, blogs);
160
157
 
161
158
  if (blogMatch) {
159
+ const blog = blogs?.[blogMatch.blogIndex];
160
+ if (!blog) {
161
+ throw notFound();
162
+ }
162
163
  if (blogMatch.kind === "detail" && blogMatch.slug) {
163
164
  // Fetch full post data by slug
164
165
  try {
@@ -168,7 +169,7 @@ export function withCMS<
168
169
  preview: deps.preview,
169
170
  blogMatch: {
170
171
  kind: "detail" as const,
171
- blog: blogMatch.blog,
172
+ blogIndex: blogMatch.blogIndex,
172
173
  postData,
173
174
  },
174
175
  };
@@ -179,24 +180,14 @@ export function withCMS<
179
180
 
180
181
  if (blogMatch.kind === "list") {
181
182
  // Fetch post list (optionally filtered by category)
182
- const posts = await getPublicPosts(
183
- blogMatch.blog.category ?? undefined,
184
- );
185
-
186
- // Also try to load CMS page data for the list page itself
187
- // (the user may have created a CMS page at the prefix path)
188
- const pageData = await getPageContents(
189
- pathname,
190
- allPageData,
191
- deps.preview,
192
- );
183
+ const posts = await getPublicPosts(blog.category ?? undefined);
193
184
 
194
185
  return {
195
- pageData,
186
+ pageData: null,
196
187
  preview: deps.preview,
197
188
  blogMatch: {
198
189
  kind: "list" as const,
199
- blog: blogMatch.blog,
190
+ blogIndex: blogMatch.blogIndex,
200
191
  posts,
201
192
  },
202
193
  };
@@ -234,9 +225,9 @@ export function withCMS<
234
225
  }) as unknown as {
235
226
  pageData: CMSUserData<TComponents> | null;
236
227
  preview?: string;
237
- blogMatch?: {
228
+ blogMatch: {
238
229
  kind: "list" | "detail";
239
- blog: CMSBlogConfig;
230
+ blogIndex: number;
240
231
  posts?: PublicPostDTO[];
241
232
  postData?: PublicPostSeoDetailsDTO;
242
233
  } | null;
@@ -246,22 +237,18 @@ export function withCMS<
246
237
 
247
238
  // ---- Blog rendering ----
248
239
  if (blogMatch) {
240
+ const blog = blogs?.[blogMatch.blogIndex];
241
+
242
+ if (!blog) {
243
+ return <NotFound />;
244
+ }
245
+
249
246
  if (blogMatch.kind === "detail" && blogMatch.postData) {
250
- return <>{blogMatch.blog.detailComponent(blogMatch.postData)}</>;
247
+ return blog.detailComponent(blogMatch.postData);
251
248
  }
252
249
 
253
250
  if (blogMatch.kind === "list" && blogMatch.posts) {
254
- // If there's also a CMS page for the list prefix, render it
255
- // above/around the blog list -- or just render the list component.
256
- if (pageData && !preview) {
257
- return (
258
- <>
259
- <PageRendererSSR config={config} data={pageData} />
260
- {blogMatch.blog.listComponent(blogMatch.posts)}
261
- </>
262
- );
263
- }
264
- return <>{blogMatch.blog.listComponent(blogMatch.posts)}</>;
251
+ return blog.listComponent(blogMatch.posts);
265
252
  }
266
253
  }
267
254