@natilon/cms-server 0.6.0 → 0.8.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/routes.mjs +29 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@natilon/cms-server",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Express-based CMS server with pluggable adapters for content, media, auth, and build.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/routes.mjs CHANGED
@@ -170,6 +170,35 @@ export const apiRoutes = [
170
170
  },
171
171
  },
172
172
 
173
+ // ── Preview URL ────────────────────────────────────────────────────────
174
+ // Resolves the preview URL for an entry. Supports both `config.previewUrl`
175
+ // (a function, called server-side with the page data) and the simpler
176
+ // `config.previewUrlPattern` (template string with {collection}/{slug}/{lang}).
177
+ {
178
+ method: "GET",
179
+ path: "/api/preview-url/:collection/:file",
180
+ auth: "any",
181
+ handler: async ({ adapters, params, config }) => {
182
+ const data = await adapters.content.readPage(params.collection, params.file);
183
+ if (!data) return notFound();
184
+
185
+ let url = null;
186
+ if (typeof config.previewUrl === "function") {
187
+ try {
188
+ url = config.previewUrl({ collection: params.collection, data });
189
+ } catch (err) {
190
+ return { status: 500, json: { error: `previewUrl(): ${err.message}` } };
191
+ }
192
+ } else if (config.previewUrlPattern) {
193
+ url = config.previewUrlPattern
194
+ .replace("{collection}", data.collection || params.collection)
195
+ .replace("{slug}", data.slug || "")
196
+ .replace("{lang}", data.lang || "");
197
+ }
198
+ return ok({ url });
199
+ },
200
+ },
201
+
173
202
  // ── History ────────────────────────────────────────────────────────────
174
203
  {
175
204
  method: "GET",