@backmatter/next 0.0.14 → 0.0.16

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/dist/config.cjs CHANGED
@@ -85,7 +85,8 @@ var DEFAULT_DIRS = {
85
85
  models: "models",
86
86
  blocks: "blocks",
87
87
  mdx: "mdx",
88
- layouts: "layouts"
88
+ layouts: "layouts",
89
+ objects: "objects"
89
90
  };
90
91
 
91
92
  // ../core/src/node/discover.ts
@@ -146,6 +147,9 @@ function listBlockFallbackFiles(root, blocksDir = "blocks") {
146
147
  function listLayoutFiles(root, layoutsDir = "layouts") {
147
148
  return listModelFiles(root, layoutsDir);
148
149
  }
150
+ function listObjectFiles(root, objectsDir = "objects") {
151
+ return listModelFiles(root, objectsDir);
152
+ }
149
153
  function listBlockFiles(root, blocksDir = "blocks") {
150
154
  const { files, skipped } = listPascalCaseFiles(root, blocksDir);
151
155
  return { blocks: files, skipped };
@@ -182,7 +186,7 @@ function detectSdk(root) {
182
186
  }
183
187
  function renderCachedCmsClient() {
184
188
  return [
185
- "const raw = createBackmatter({ ...config, models });",
189
+ "const raw = createBackmatter({ ...config, models, sync: false });",
186
190
  "",
187
191
  "async function getDoc(locale: string, type: string, slug: string) {",
188
192
  ' "use cache";',
@@ -237,6 +241,7 @@ function renderModelsBarrel(input) {
237
241
  `;
238
242
  }
239
243
  function renderSyncBarrel(input) {
244
+ const objects = input.objects ?? [];
240
245
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
241
246
  if (input.configFile) {
242
247
  lines.push(`import config from "${importSpecifier(input.outDir, input.configFile)}";`);
@@ -249,14 +254,19 @@ function renderSyncBarrel(input) {
249
254
  for (const b of input.blocks) {
250
255
  lines.push(`import ${b.name} from "${importSpecifier(input.outDir, b.file)}";`);
251
256
  }
257
+ for (const object of objects) {
258
+ lines.push(`import ${object.importName} from "${importSpecifier(input.outDir, object.file)}";`);
259
+ }
252
260
  lines.push("");
253
261
  lines.push(`export const models = [${input.models.map((m) => m.importName).join(", ")}] as const;`);
254
262
  lines.push("export type Models = typeof models;");
255
263
  lines.push("");
256
264
  lines.push(`export const blocks = [${input.blocks.map((b) => b.name).join(", ")}] as const;`);
257
265
  lines.push("");
266
+ lines.push(`export const objects = [${objects.map((o) => o.importName).join(", ")}] as const;`);
267
+ lines.push("");
258
268
  lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
259
- lines.push("export const cms = createBackmatter({ ...config, models, blocks });");
269
+ lines.push("export const cms = createBackmatter({ ...config, models, blocks, objects, sync: true });");
260
270
  return `${lines.join(`
261
271
  `)}
262
272
  `;
@@ -327,6 +337,7 @@ function generate(options) {
327
337
  const fallbacks = listBlockFallbackFiles(root, options.blocksDir ?? DEFAULT_DIRS.blocks);
328
338
  const { blocks: mdx, skipped: skippedMdx } = listMdxFiles(root, options.mdxDir ?? DEFAULT_DIRS.mdx);
329
339
  const layouts = listLayoutFiles(root, options.layoutsDir ?? DEFAULT_DIRS.layouts);
340
+ const objects = listObjectFiles(root, options.objectsDir ?? DEFAULT_DIRS.objects);
330
341
  const sdk = options.sdk ?? detectSdk(root);
331
342
  const configFile = findConfigFile(root);
332
343
  const write = options.write ?? true;
@@ -336,7 +347,7 @@ function generate(options) {
336
347
  "block-fallbacks.ts": renderBlockFallbacksBarrel({ outDir, fallbacks }),
337
348
  "mdx.ts": renderMdxBarrel({ outDir, mdx }),
338
349
  "layouts.ts": renderLayoutsBarrel({ outDir, layouts }),
339
- "sync.ts": renderSyncBarrel({ outDir, models, blocks, configFile, sdk })
350
+ "sync.ts": renderSyncBarrel({ outDir, models, blocks, objects, configFile, sdk })
340
351
  };
341
352
  const outputs = REGISTRY_FILES.map((name) => {
342
353
  const file = import_node_path2.default.join(outDir, name);
@@ -356,6 +367,7 @@ function generate(options) {
356
367
  blocks,
357
368
  mdx,
358
369
  layouts,
370
+ objects,
359
371
  skippedBlocks,
360
372
  skippedMdx,
361
373
  configFile
@@ -393,6 +405,7 @@ function resolveLoaderOptions(options = {}) {
393
405
  blocksDir: options.blocksDir ?? DEFAULT_DIRS.blocks,
394
406
  mdxDir: options.mdxDir ?? DEFAULT_DIRS.mdx,
395
407
  layoutsDir: options.layoutsDir ?? DEFAULT_DIRS.layouts,
408
+ objectsDir: options.objectsDir ?? DEFAULT_DIRS.objects,
396
409
  sdk: SDK
397
410
  };
398
411
  }
package/dist/loader.cjs CHANGED
@@ -79,7 +79,8 @@ var DEFAULT_DIRS = {
79
79
  models: "models",
80
80
  blocks: "blocks",
81
81
  mdx: "mdx",
82
- layouts: "layouts"
82
+ layouts: "layouts",
83
+ objects: "objects"
83
84
  };
84
85
 
85
86
  // ../core/src/node/discover.ts
@@ -140,6 +141,9 @@ function listBlockFallbackFiles(root, blocksDir = "blocks") {
140
141
  function listLayoutFiles(root, layoutsDir = "layouts") {
141
142
  return listModelFiles(root, layoutsDir);
142
143
  }
144
+ function listObjectFiles(root, objectsDir = "objects") {
145
+ return listModelFiles(root, objectsDir);
146
+ }
143
147
  function listBlockFiles(root, blocksDir = "blocks") {
144
148
  const { files, skipped } = listPascalCaseFiles(root, blocksDir);
145
149
  return { blocks: files, skipped };
@@ -176,7 +180,7 @@ function detectSdk(root) {
176
180
  }
177
181
  function renderCachedCmsClient() {
178
182
  return [
179
- "const raw = createBackmatter({ ...config, models });",
183
+ "const raw = createBackmatter({ ...config, models, sync: false });",
180
184
  "",
181
185
  "async function getDoc(locale: string, type: string, slug: string) {",
182
186
  ' "use cache";',
@@ -231,6 +235,7 @@ function renderModelsBarrel(input) {
231
235
  `;
232
236
  }
233
237
  function renderSyncBarrel(input) {
238
+ const objects = input.objects ?? [];
234
239
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
235
240
  if (input.configFile) {
236
241
  lines.push(`import config from "${importSpecifier(input.outDir, input.configFile)}";`);
@@ -243,14 +248,19 @@ function renderSyncBarrel(input) {
243
248
  for (const b of input.blocks) {
244
249
  lines.push(`import ${b.name} from "${importSpecifier(input.outDir, b.file)}";`);
245
250
  }
251
+ for (const object of objects) {
252
+ lines.push(`import ${object.importName} from "${importSpecifier(input.outDir, object.file)}";`);
253
+ }
246
254
  lines.push("");
247
255
  lines.push(`export const models = [${input.models.map((m) => m.importName).join(", ")}] as const;`);
248
256
  lines.push("export type Models = typeof models;");
249
257
  lines.push("");
250
258
  lines.push(`export const blocks = [${input.blocks.map((b) => b.name).join(", ")}] as const;`);
251
259
  lines.push("");
260
+ lines.push(`export const objects = [${objects.map((o) => o.importName).join(", ")}] as const;`);
261
+ lines.push("");
252
262
  lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
253
- lines.push("export const cms = createBackmatter({ ...config, models, blocks });");
263
+ lines.push("export const cms = createBackmatter({ ...config, models, blocks, objects, sync: true });");
254
264
  return `${lines.join(`
255
265
  `)}
256
266
  `;
@@ -321,6 +331,7 @@ function generate(options) {
321
331
  const fallbacks = listBlockFallbackFiles(root, options.blocksDir ?? DEFAULT_DIRS.blocks);
322
332
  const { blocks: mdx, skipped: skippedMdx } = listMdxFiles(root, options.mdxDir ?? DEFAULT_DIRS.mdx);
323
333
  const layouts = listLayoutFiles(root, options.layoutsDir ?? DEFAULT_DIRS.layouts);
334
+ const objects = listObjectFiles(root, options.objectsDir ?? DEFAULT_DIRS.objects);
324
335
  const sdk = options.sdk ?? detectSdk(root);
325
336
  const configFile = findConfigFile(root);
326
337
  const write = options.write ?? true;
@@ -330,7 +341,7 @@ function generate(options) {
330
341
  "block-fallbacks.ts": renderBlockFallbacksBarrel({ outDir, fallbacks }),
331
342
  "mdx.ts": renderMdxBarrel({ outDir, mdx }),
332
343
  "layouts.ts": renderLayoutsBarrel({ outDir, layouts }),
333
- "sync.ts": renderSyncBarrel({ outDir, models, blocks, configFile, sdk })
344
+ "sync.ts": renderSyncBarrel({ outDir, models, blocks, objects, configFile, sdk })
334
345
  };
335
346
  const outputs = REGISTRY_FILES.map((name) => {
336
347
  const file = import_node_path2.default.join(outDir, name);
@@ -350,6 +361,7 @@ function generate(options) {
350
361
  blocks,
351
362
  mdx,
352
363
  layouts,
364
+ objects,
353
365
  skippedBlocks,
354
366
  skippedMdx,
355
367
  configFile
@@ -364,10 +376,12 @@ function backmatterLoader(source) {
364
376
  const blocksDir = import_node_path3.default.resolve(root, options.blocksDir);
365
377
  const mdxDir = import_node_path3.default.resolve(root, options.mdxDir);
366
378
  const layoutsDir = import_node_path3.default.resolve(root, options.layoutsDir);
379
+ const objectsDir = import_node_path3.default.resolve(root, options.objectsDir);
367
380
  this.addContextDependency(modelsDir);
368
381
  this.addContextDependency(blocksDir);
369
382
  this.addContextDependency(mdxDir);
370
383
  this.addContextDependency(layoutsDir);
384
+ this.addContextDependency(objectsDir);
371
385
  this.cacheable?.(true);
372
386
  const result = generate({
373
387
  root,
@@ -376,6 +390,7 @@ function backmatterLoader(source) {
376
390
  blocksDir: options.blocksDir,
377
391
  mdxDir: options.mdxDir,
378
392
  layoutsDir: options.layoutsDir,
393
+ objectsDir: options.objectsDir,
379
394
  sdk: options.sdk
380
395
  });
381
396
  if (result.configFile)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backmatter/next",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Experimental Next.js adapter for Backmatter. APIs will break. Not ready for production.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -38,7 +38,7 @@
38
38
  "test": "bun test"
39
39
  },
40
40
  "dependencies": {
41
- "@backmatter/core": "^0.0.13",
41
+ "@backmatter/core": "^0.0.15",
42
42
  "@mdx-js/mdx": "^3.1.1",
43
43
  "remark-gfm": "^4.0.1"
44
44
  },
package/src/config.ts CHANGED
@@ -26,6 +26,7 @@ export type WithBackmatterOptions = {
26
26
  blocksDir?: string;
27
27
  mdxDir?: string;
28
28
  layoutsDir?: string;
29
+ objectsDir?: string;
29
30
  /** Called after the boot-time generation. Default: log what changed. */
30
31
  onGenerate?: (result: GenerateResult) => void;
31
32
  };
@@ -82,6 +83,7 @@ export function resolveLoaderOptions(options: WithBackmatterOptions = {}): Backm
82
83
  blocksDir: options.blocksDir ?? DEFAULT_DIRS.blocks,
83
84
  mdxDir: options.mdxDir ?? DEFAULT_DIRS.mdx,
84
85
  layoutsDir: options.layoutsDir ?? DEFAULT_DIRS.layouts,
86
+ objectsDir: options.objectsDir ?? DEFAULT_DIRS.objects,
85
87
  sdk: SDK,
86
88
  };
87
89
  }
package/src/loader.ts CHANGED
@@ -17,6 +17,7 @@ export type BackmatterLoaderOptions = {
17
17
  blocksDir: string;
18
18
  mdxDir: string;
19
19
  layoutsDir: string;
20
+ objectsDir: string;
20
21
  sdk: string;
21
22
  };
22
23
 
@@ -36,11 +37,13 @@ export default function backmatterLoader(this: BackmatterLoaderContext, source:
36
37
  const blocksDir = path.resolve(root, options.blocksDir);
37
38
  const mdxDir = path.resolve(root, options.mdxDir);
38
39
  const layoutsDir = path.resolve(root, options.layoutsDir);
40
+ const objectsDir = path.resolve(root, options.objectsDir);
39
41
 
40
42
  this.addContextDependency(modelsDir);
41
43
  this.addContextDependency(blocksDir);
42
44
  this.addContextDependency(mdxDir);
43
45
  this.addContextDependency(layoutsDir);
46
+ this.addContextDependency(objectsDir);
44
47
  this.cacheable?.(true);
45
48
 
46
49
  const result = generate({
@@ -50,6 +53,7 @@ export default function backmatterLoader(this: BackmatterLoaderContext, source:
50
53
  blocksDir: options.blocksDir,
51
54
  mdxDir: options.mdxDir,
52
55
  layoutsDir: options.layoutsDir,
56
+ objectsDir: options.objectsDir,
53
57
  sdk: options.sdk,
54
58
  });
55
59
  if (result.configFile) this.addDependency(result.configFile);
package/src/routes.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  // `route` template (including `/` via indexSlug), loads it and renders MDX
5
5
  // or JSON pages. An optional catch-all is required so `/` is a CMS route.
6
6
  import { Fragment, Suspense, createElement, type ReactNode } from "react";
7
- import { matchRoute, modelFormat, PREVIEW_CHECKOUT_QUERY, PREVIEW_COOKIE, readPreviewCookie, routeSegments, type BackmatterDoc, type ModelDef } from "@backmatter/core";
7
+ import { isRoutable, matchRoute, modelFormat, PREVIEW_CHECKOUT_QUERY, PREVIEW_COOKIE, readPreviewCookie, routeSegments, type BackmatterDoc, type ModelDef } from "@backmatter/core";
8
8
  import type { BackmatterClient } from "@backmatter/core/node/create-backmatter";
9
9
  import { fetchPreviewDoc } from "@backmatter/core/preview";
10
10
  import { renderDoc, type MdxComponents } from "./mdx-compile";
@@ -162,7 +162,7 @@ export function createCatchAll<Models extends readonly ModelDef[]>(
162
162
  const params: CatchAllParams[] = [];
163
163
  for (const doc of docs) {
164
164
  const model = byType.get(doc.type);
165
- if (!model) continue;
165
+ if (!model || !isRoutable(model)) continue;
166
166
  params.push({ [CATCH_ALL_PARAM]: routeSegments(model, doc.locale, doc.slug) });
167
167
  }
168
168
  return params;