rankrunners-cms 0.0.15 → 0.0.17
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
|
@@ -130,7 +130,45 @@ export const Heading: ComponentConfig<HeadingProps> = {
|
|
|
130
130
|
|
|
131
131
|
---
|
|
132
132
|
|
|
133
|
-
## 6.
|
|
133
|
+
## 6. Sitemap & Robots.txt Support
|
|
134
|
+
|
|
135
|
+
To add support for these, you need to create the following server-side routes in your TanStack Router setup.
|
|
136
|
+
|
|
137
|
+
### Sitemap Support
|
|
138
|
+
Create a file called `src/routes/$sitemap.xml.tsx`:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
142
|
+
import { downloadSitemapAsResponse } from 'rankrunners-cms/src/api/client/sitemap'
|
|
143
|
+
|
|
144
|
+
export const Route = createFileRoute('/$sitemap.xml')({
|
|
145
|
+
server: {
|
|
146
|
+
handlers: {
|
|
147
|
+
GET: ({ params }) => downloadSitemapAsResponse(params['sitemap.xml']),
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Robots.txt Support
|
|
154
|
+
Create a file called `src/routes/robots[.]txt.tsx`:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
158
|
+
import { downloadSitemapAsResponse } from 'rankrunners-cms/src/api/client/sitemap'
|
|
159
|
+
|
|
160
|
+
export const Route = createFileRoute('/robots.txt')({
|
|
161
|
+
server: {
|
|
162
|
+
handlers: {
|
|
163
|
+
GET: () => downloadSitemapAsResponse('robots.txt'),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 7. Developer Checklist
|
|
134
172
|
|
|
135
173
|
Use this checklist to ensure a complete and correct integration:
|
|
136
174
|
|
|
@@ -155,9 +193,8 @@ Use this checklist to ensure a complete and correct integration:
|
|
|
155
193
|
- [ ] Register all blocks in `src/editor/index.tsx`.
|
|
156
194
|
- [ ] Organize blocks into `categories` within the config.
|
|
157
195
|
|
|
158
|
-
###
|
|
159
|
-
- [ ]
|
|
160
|
-
- [ ]
|
|
161
|
-
- [ ] Verify that `@puckeditor/core/no-external.css` is imported in the editor route.
|
|
196
|
+
### Sitemap & Robots.txt
|
|
197
|
+
- [ ] Add `src/routes/$sitemap.xml.tsx` for dynamic sitemap support.
|
|
198
|
+
- [ ] Add `src/routes/robots.txt.tsx` for `robots.txt` support.
|
|
162
199
|
|
|
163
200
|
---
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rankrunners-cms",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.17",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@puckeditor/core": "^0.21.0",
|
|
7
7
|
"next": "^16.1.2",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "^5.9.3",
|
|
35
35
|
"@tanstack/router-core": "^1.150.0",
|
|
36
36
|
"@tanstack/react-router": "^1.150.0",
|
|
37
|
-
"next": "^16.1.
|
|
37
|
+
"next": "^16.1.3",
|
|
38
38
|
"valibot": "^1.2.0",
|
|
39
39
|
"lucide-react": "^0.562.0",
|
|
40
40
|
"react": "^19.2.3"
|
|
@@ -3,7 +3,7 @@ import { CMS_BASE_URL, SITE_ID } from "../constants";
|
|
|
3
3
|
|
|
4
4
|
export const downloadSitemap = async (sitemap: string): Promise<string> => {
|
|
5
5
|
const response = await fetchWithCache(
|
|
6
|
-
`${CMS_BASE_URL}/sites/${SITE_ID}/sitemaps/${sitemap}
|
|
6
|
+
`${CMS_BASE_URL}/sites/${SITE_ID}/sitemaps/${sitemap}`,
|
|
7
7
|
);
|
|
8
8
|
|
|
9
9
|
if (!response.ok) {
|
|
@@ -13,3 +13,20 @@ export const downloadSitemap = async (sitemap: string): Promise<string> => {
|
|
|
13
13
|
const content = await response.text();
|
|
14
14
|
return content;
|
|
15
15
|
};
|
|
16
|
+
|
|
17
|
+
export const downloadSitemapAsResponse = async (
|
|
18
|
+
sitemap: string,
|
|
19
|
+
): Promise<Response> => {
|
|
20
|
+
const sitemapData = await downloadSitemap(sitemap);
|
|
21
|
+
|
|
22
|
+
const contentType = sitemap.endsWith(".xml")
|
|
23
|
+
? "application/xml"
|
|
24
|
+
: "text/plain";
|
|
25
|
+
|
|
26
|
+
return new Response(sitemapData, {
|
|
27
|
+
status: 200,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": contentType,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
2
|
import type { CMSUserData } from "../types";
|
|
3
3
|
import { Render, type Config } from "@puckeditor/core";
|
|
4
4
|
import { CMS_BASE_URL, SITE_ID } from "../../api";
|
|
@@ -6,7 +6,7 @@ import { fetchWithCache } from "../../libs";
|
|
|
6
6
|
|
|
7
7
|
const getPageContents = async (
|
|
8
8
|
pathname: string,
|
|
9
|
-
allPageData: Record<string, CMSUserData<any
|
|
9
|
+
allPageData: Record<string, CMSUserData<any>>,
|
|
10
10
|
) => {
|
|
11
11
|
// remove trailing (left and right) slashes
|
|
12
12
|
pathname = pathname.replace(/^\/+|\/+$/g, "");
|
|
@@ -18,13 +18,10 @@ const getPageContents = async (
|
|
|
18
18
|
headers: {
|
|
19
19
|
"Content-Type": "application/json",
|
|
20
20
|
},
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
if (res.ok) {
|
|
25
|
-
// console.error("Failed to fetch page data from CMS");
|
|
26
|
-
// throw new Error("Failed to fetch page data from CMS");
|
|
27
|
-
//}
|
|
28
25
|
const json = (await res.json()) as { content?: string };
|
|
29
26
|
|
|
30
27
|
if (json.content) {
|
|
@@ -68,13 +65,13 @@ export const PageRendererContent = ({
|
|
|
68
65
|
}: PageRendererContentProps) => {
|
|
69
66
|
const [data, setData] = useState<CMSUserData<any> | null>(null);
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
useEffect(() => {
|
|
72
69
|
const fetchData = async () => {
|
|
73
70
|
const pageData = await getPageContents(pathname, allPageData);
|
|
74
71
|
setData(pageData);
|
|
75
72
|
};
|
|
76
73
|
fetchData();
|
|
77
|
-
});
|
|
74
|
+
}, [pathname]);
|
|
78
75
|
|
|
79
76
|
if (!data) {
|
|
80
77
|
return (
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Config } from "@puckeditor/core";
|
|
2
|
+
import { PageRendererContent } from "../../editor";
|
|
3
|
+
import { EditorTanstack } from ".";
|
|
4
|
+
import { usePathnameTanstack, useSearchParamsTanstack } from "../hooks";
|
|
5
|
+
import type { CMSUserData } from "../../editor";
|
|
6
|
+
|
|
7
|
+
export type PageRendererTanstackInitializerProps = {
|
|
8
|
+
config: Config;
|
|
9
|
+
allPageData: Record<string, CMSUserData<any>>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const PageRendererTanstack =
|
|
13
|
+
({ config, allPageData }: PageRendererTanstackInitializerProps) =>
|
|
14
|
+
() => {
|
|
15
|
+
const pathname = usePathnameTanstack();
|
|
16
|
+
const searchParams = useSearchParamsTanstack();
|
|
17
|
+
const previewToken = searchParams.get("preview");
|
|
18
|
+
|
|
19
|
+
if (previewToken) {
|
|
20
|
+
return <EditorTanstack config={config} allPageData={allPageData} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<PageRendererContent
|
|
25
|
+
config={config}
|
|
26
|
+
allPageData={allPageData}
|
|
27
|
+
pathname={pathname}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|