domma-cms 0.13.5 → 0.14.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 (40) hide show
  1. package/admin/css/admin.css +1 -1
  2. package/admin/js/api.js +1 -1
  3. package/admin/js/app.js +2 -2
  4. package/admin/js/config/sidebar-config.js +1 -1
  5. package/admin/js/lib/markdown-toolbar.js +24 -18
  6. package/admin/js/lib/scribe-composer.js +4 -0
  7. package/admin/js/lib/simple-editor.js +49 -0
  8. package/admin/js/templates/block-editor.html +76 -18
  9. package/admin/js/templates/blocks.html +18 -8
  10. package/admin/js/templates/component-editor.html +141 -0
  11. package/admin/js/templates/components.html +18 -0
  12. package/admin/js/views/block-editor-enhance.js +1 -0
  13. package/admin/js/views/block-editor.js +8 -8
  14. package/admin/js/views/blocks.js +11 -4
  15. package/admin/js/views/component-editor.js +28 -0
  16. package/admin/js/views/components.js +11 -0
  17. package/admin/js/views/index.js +1 -1
  18. package/admin/js/views/layouts.js +1 -1
  19. package/admin/js/views/page-editor.js +6 -6
  20. package/admin/js/views/pages.js +5 -2
  21. package/config/navigation.json +5 -0
  22. package/config/plugins.json +5 -5
  23. package/config/presets.json +92 -40
  24. package/config/site.json +75 -8
  25. package/package.json +2 -2
  26. package/public/css/site.css +1 -1
  27. package/server/routes/api/blocks.js +128 -60
  28. package/server/routes/api/components.js +115 -0
  29. package/server/routes/api/layouts.js +24 -0
  30. package/server/routes/api/pages.js +135 -132
  31. package/server/routes/api/versions.js +16 -0
  32. package/server/server.js +6 -0
  33. package/server/services/blocks.js +387 -284
  34. package/server/services/components.js +653 -0
  35. package/server/services/content.js +334 -334
  36. package/server/services/hooks.js +28 -0
  37. package/server/services/markdown.js +2836 -2629
  38. package/server/services/permissionRegistry.js +13 -0
  39. package/server/services/renderer.js +13 -3
  40. package/server/services/versions.js +37 -0
@@ -48,6 +48,19 @@ export const REGISTRY = [
48
48
  {key: 'delete', label: 'Delete', description: 'Delete blocks'}
49
49
  ]
50
50
  },
51
+ {
52
+ key: 'components',
53
+ label: 'Components',
54
+ description: 'Manage reusable Domma components.',
55
+ icon: 'component',
56
+ group: 'Content',
57
+ actions: [
58
+ {key: 'read', label: 'View', description: 'View components'},
59
+ {key: 'create', label: 'Create', description: 'Create new components'},
60
+ {key: 'update', label: 'Edit', description: 'Edit existing components'},
61
+ {key: 'delete', label: 'Delete', description: 'Delete components'}
62
+ ]
63
+ },
51
64
  {
52
65
  key: 'navigation',
53
66
  label: 'Navigation',
@@ -69,7 +69,9 @@ export async function renderPage(page) {
69
69
 
70
70
  const preset = presets[page.layout] || presets['default'] || {};
71
71
 
72
- const layoutWidth = VALID_LAYOUT_WIDTHS.has(preset.width) ? preset.width : 'normal';
72
+ // Per-page `width:` frontmatter overrides the preset's width when valid.
73
+ const pageWidth = VALID_LAYOUT_WIDTHS.has(page.width) ? page.width : null;
74
+ const layoutWidth = pageWidth || (VALID_LAYOUT_WIDTHS.has(preset.width) ? preset.width : 'normal');
73
75
  const layoutBodyClass = ['dm-layout-' + layoutWidth, preset.class || ''].filter(Boolean).join(' ');
74
76
  const pageBodyStyleParts = [];
75
77
  const BG_COLOR_SAFE = /^[a-zA-Z0-9#(),.\s%/-]+$/;
@@ -155,7 +157,10 @@ export async function renderPage(page) {
155
157
  bodyEndInject: [
156
158
  injection.bodyEnd,
157
159
  site.backToTop?.enabled ? '<script src="/public/js/btt.js"></script>' : '',
158
- site.cookieConsent?.enabled ? '<script src="/public/js/cookie-consent.js"></script>' : ''
160
+ site.cookieConsent?.enabled ? '<script src="/public/js/cookie-consent.js"></script>' : '',
161
+ (page.usedComponents || [])
162
+ .map(n => `<script type="module" src="/api/components/${n}.js"></script>`)
163
+ .join('\n')
159
164
  ].filter(Boolean).join('\n'),
160
165
  dconfigScript,
161
166
  };
@@ -356,7 +361,12 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
356
361
  }).replace(/<\/script>/gi, '<\\/script>'),
357
362
  headInject: [ogTags, injection.head, navbarFontLink].filter(Boolean).join('\n'),
358
363
  headInjectLate: [injection.headLate, customCssTag, navbarStyleTag].filter(Boolean).join('\n'),
359
- bodyEndInject: injection.bodyEnd || '',
364
+ bodyEndInject: [
365
+ injection.bodyEnd,
366
+ (page.usedComponents || [])
367
+ .map(n => `<script type="module" src="/api/components/${n}.js"></script>`)
368
+ .join('\n')
369
+ ].filter(Boolean).join('\n'),
360
370
  dconfigScript: ''
361
371
  };
362
372
 
@@ -157,6 +157,43 @@ export async function listVersions(urlPath) {
157
157
  return [...meta].sort((a, b) => b.createdAt.localeCompare(a.createdAt));
158
158
  }
159
159
 
160
+ /**
161
+ * Count versions for a page without loading their content.
162
+ * Returns 0 if the page has no versions directory.
163
+ *
164
+ * @param {string} urlPath
165
+ * @returns {Promise<number>}
166
+ */
167
+ export async function getVersionCount(urlPath) {
168
+ const dir = versionsDirForPath(urlPath);
169
+ const meta = await readMeta(dir);
170
+ return meta.length;
171
+ }
172
+
173
+ /**
174
+ * Prune a page's version history, retaining only the most recent `keep` entries
175
+ * (and any others your retention policy decides to preserve).
176
+ *
177
+ * @param {string} urlPath
178
+ * @param {{ keep?: number }} options
179
+ * @returns {Promise<{ deleted: number, kept: number }>}
180
+ */
181
+ export async function pruneVersions(urlPath, {keep = 5} = {}) {
182
+ const dir = versionsDirForPath(urlPath);
183
+ const meta = await readMeta(dir);
184
+
185
+ // Newest first — index 0 is the most recent snapshot
186
+ const sorted = [...meta].sort((a, b) => b.createdAt.localeCompare(a.createdAt));
187
+
188
+ // Manually-named snapshots are always preserved (deliberate restore points).
189
+ // Auto snapshots beyond the newest `keep` are deleted.
190
+ const expendable = sorted.filter(m => m.type !== 'manual');
191
+ const toDelete = expendable.slice(keep).map(m => m.filename);
192
+
193
+ if (toDelete.length) await deleteVersions(urlPath, toDelete);
194
+ return {deleted: toDelete.length, kept: sorted.length - toDelete.length};
195
+ }
196
+
160
197
  /**
161
198
  * Get the raw content of a specific version file plus its meta entry.
162
199
  *