domma-cms 1.63.0 → 1.64.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.
@@ -120,7 +120,7 @@ async function readPageSummary(filePath) {
120
120
  * for a few hundred. A caller that reads only the front matter (title, status,
121
121
  * layout, tags, seo, ...) or the Markdown source (`content`) asks for
122
122
  * `{render: false}` and gets exactly those plus `urlPath` and
123
- * `resolvedProject`: no `html`, `usedComponents`, `cacheTags`, `perViewer` or
123
+ * `resolvedProject`: no `html`, `background`, `usedComponents`, `cacheTags`, `perViewer` or
124
124
  * `hasExpiry`. Lists, badges, search and the sitemap all do.
125
125
  *
126
126
  * The rendered rows come through the parsed-page memo while the response
@@ -224,9 +224,9 @@ export async function getPage(urlPath, opts = {}) {
224
224
  */
225
225
  export async function buildPreviewPage(urlPath, frontmatter, body, opts = {}) {
226
226
  const raw = serialiseMarkdown({...(frontmatter || {})}, body || '');
227
- const {data, content, html, usedComponents, tags, perViewer, hasExpiry} =
227
+ const {data, content, html, background, usedComponents, tags, perViewer, hasExpiry} =
228
228
  await parseMarkdown(raw, {user: opts.user || null, urlPath, expiry:{preview:true}});
229
- return {...data, urlPath, content, html, usedComponents, cacheTags: tags, perViewer, hasExpiry};
229
+ return {...data, urlPath, content, html, background, usedComponents, cacheTags: tags, perViewer, hasExpiry};
230
230
  }
231
231
 
232
232
  /**
@@ -625,7 +625,7 @@ async function readPageFile(filePath, opts = {}) {
625
625
  const urlPath = filePathToUrlPath(filePath);
626
626
  // urlPath is passed through so `[menu location="…"]` in the body resolves
627
627
  // against menus bound to this page or its project, exactly as the navbar does.
628
- const { data, content, html, usedComponents, tags, perViewer, hasExpiry } =
628
+ const { data, content, html, background, usedComponents, tags, perViewer, hasExpiry } =
629
629
  await parseMarkdown(raw, {user: opts.user || null, urlPath, expiry:opts.expiry || (opts.user ? {preview:true} : {})});
630
630
  // parseMarkdown's `tags` are CACHE tags (`block:x`, `collection:y`), not
631
631
  // the page's editorial tags. Spreading them last used to shadow the
@@ -634,7 +634,7 @@ async function readPageFile(filePath, opts = {}) {
634
634
  // cache internals in its Tags column. Keep them apart.
635
635
  // perViewer: a row-scoped [view] renders per user - the public route keeps
636
636
  // such a page out of the role-keyed response cache for signed-in viewers.
637
- return { ...data, urlPath, content, html, usedComponents, cacheTags: tags, perViewer, hasExpiry };
637
+ return { ...data, urlPath, content, html, background, usedComponents, cacheTags: tags, perViewer, hasExpiry };
638
638
  }
639
639
 
640
640
  /**
@@ -3,6 +3,7 @@ import {decodeMessageAttribute} from '../../public/js/celebrations/message-attrs
3
3
  * Markdown Service
4
4
  * Parses frontmatter with gray-matter and renders Markdown to HTML with marked.
5
5
  */
6
+ import {normaliseBackground, backgroundStyle} from '../../public/js/background-style.mjs';
6
7
  import {cssClasses} from '../../public/js/css-classes.mjs';
7
8
  import matter from 'gray-matter';
8
9
  import {marked} from 'marked';
@@ -41,7 +42,7 @@ export const BUILTIN_SHORTCODES = new Set([
41
42
  'accordion', 'item', 'carousel', 'slide', 'countdown', 'timeline',
42
43
  'event', 'listgroup', 'spacer', 'center', 'icon', 'demo', 'embed', 'map', 'image', 'form', 'hero', 'table', 'badge',
43
44
  'text', 'button', 'link', 'cta', 'grid', 'row', 'col', 'card', 'box',
44
- 'banner', 'slideover', 'menu',
45
+ 'banner', 'slideover', 'menu', 'background',
45
46
  // effects
46
47
  'counter', 'celebrate', 'firework', 'fireworks', 'scribe',
47
48
  'reveal', 'breathe', 'pulse', 'shake', 'scramble', 'ripple', 'twinkle',
@@ -1993,7 +1994,7 @@ let scrubCallId = 0;
1993
1994
  * (a nested list, code) keeps the difference. The indent is only ever for the reader.
1994
1995
  */
1995
1996
  export const SHORT_TAG_CONTAINERS = Object.freeze([
1996
- 'grid', 'row', 'col', 'card', 'box', 'header', 'footer', 'tabs', 'tab', 'accordion', 'item', 'carousel', 'slide',
1997
+ 'background', 'grid', 'row', 'col', 'card', 'box', 'header', 'footer', 'tabs', 'tab', 'accordion', 'item', 'carousel', 'slide',
1997
1998
  'timeline', 'event', 'hero', 'banner', 'slideover', 'center', 'listgroup', 'table', 'dconfig', 'reveal', 'animate',
1998
1999
  'pulse', 'shake', 'scramble', 'ripple', 'breathe', 'ambient', 'twinkle', 'fireworks', 'scribe', 'wait', 'render', 'redraw'
1999
2000
  ]);
@@ -2454,81 +2455,82 @@ function responsiveGridCols(cols) {
2454
2455
  return map[String(cols)] ?? [`grid-cols-${classToken(cols)}`];
2455
2456
  }
2456
2457
 
2457
- function processGridBlocks(markdown) {
2458
- const {scrubbed, restore} = scrubCodeRegions(markdown);
2459
- // Pass 1: [col span="N"]...[/col] → <div class="col-span-N">...</div>
2460
- // [col]...[/col] → <div class="col">...</div> (enables flex stacking in [row])
2461
- let result = scrubbed.replace(
2462
- /\[col([^\]]*)\]([\s\S]*?)\[\/col\]/gi,
2463
- (_, attrStr, body) => {
2464
- const attrs = parseShortcodeAttrs(attrStr);
2465
- const COL_INJECTABLE = ['reveal', 'breathe', 'animate', 'ripple'];
2466
- const injected = extractInjectedEffects(attrs, COL_INJECTABLE);
2467
- const baseCls = attrs.span ? `col-span-${classToken(attrs.span)}` : 'col';
2468
- // Explicit alignment takes precedence over the shorthand flags.
2469
- const alignment = typeof attrs.align === 'string'
2470
- ? attrs.align.trim().toLowerCase()
2471
- : ['center', 'centre', 'left', 'right'].find(value => attrs[value] === true);
2472
- const align = alignment === 'centre' ? 'center' : alignment;
2473
- const alignClasses = ['left', 'center', 'right'].includes(align) ? [`text-${align}`] : [];
2474
- const allClasses = [baseCls, ...alignClasses, ...injected.effectClasses].join(' ');
2475
- const cls = ` class="${allClasses}"`;
2476
- const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2477
- // Restore the col body before passing it downstream - otherwise the
2478
- // scrub placeholders from this processor's store get carried into
2479
- // processCardBlocks, which creates its own empty store and fails to
2480
- // decode them, producing the literal string "undefined" in place of
2481
- // whatever was in <pre>, ``` fences, or `inline code`.
2482
- return `<div${cls}${id}${injected.effectDataAttrs}>${markedBody(processCardBlocks(processInlineShortcodes(restore(body.trim()))))}</div>`;
2483
- }
2484
- );
2485
-
2486
- // Pass 2: [row gap="N" class="extra" reveal reveal-mode="stagger"]...[/row]
2487
- result = result.replace(
2488
- /\[row([^\]]*)\]([\s\S]*?)\[\/row\]/gi,
2489
- (_, attrStr, inner) => {
2490
- const attrs = parseShortcodeAttrs(attrStr);
2491
- const classes = ['row'];
2492
- if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2493
- if (attrs.class) classes.push(escapeAttr(attrs.class));
2494
- const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2495
- const reveal = attrs.reveal !== undefined ? ' data-reveal="true"' : '';
2496
- const revealMode = attrs['reveal-mode'] ? ` data-reveal-mode="${escapeAttr(attrs['reveal-mode'])}"` : '';
2497
- const revealAnimation = attrs['reveal-animation'] ? ` data-reveal-animation="${escapeAttr(attrs['reveal-animation'])}"` : '';
2498
- const revealDuration = attrs['reveal-duration'] ? ` data-reveal-duration="${escapeAttr(attrs['reveal-duration'])}"` : '';
2499
- const revealStagger = attrs['reveal-stagger'] ? ` data-reveal-stagger="${escapeAttr(attrs['reveal-stagger'])}"` : '';
2500
- const revealDelay = attrs['reveal-delay'] ? ` data-reveal-delay="${escapeAttr(attrs['reveal-delay'])}"` : '';
2501
- const revealDirection = attrs['reveal-direction'] ? ` data-reveal-direction="${escapeAttr(attrs['reveal-direction'])}"` : '';
2502
- // Swoosh in again each time the row comes back up into view; cards that lean toward the pointer.
2503
- const revealReplay = isTruthyAttr(attrs['reveal-replay']) ? ' data-reveal-replay="true"' : '';
2504
- const tilt = isTruthyAttr(attrs.tilt) ? ' data-tilt="true"' : '';
2505
- return `<div class="${classes.join(' ')}"${id}${reveal}${revealMode}${revealAnimation}${revealDuration}${revealStagger}${revealDelay}${revealDirection}${revealReplay}${tilt}>${inner}</div>\n`;
2506
- }
2507
- );
2508
-
2509
- // Pass 3: [grid cols="N" gap="N"]...[/grid] → <div class="grid grid-cols-1 grid-cols-md-N ...">
2510
- // responsive="false" disables the mobile-first stacking behaviour
2511
- result = result.replace(
2512
- /\[grid([^\]]*)\]([\s\S]*?)\[\/grid\]/gi,
2513
- (_, attrStr, inner) => {
2514
- const attrs = parseShortcodeAttrs(attrStr);
2515
- const classes = ['grid'];
2516
- if (attrs.cols) {
2517
- if (attrs.responsive === 'false') {
2518
- classes.push(`grid-cols-${classToken(attrs.cols)}`);
2519
- } else {
2520
- classes.push(...responsiveGridCols(attrs.cols));
2458
+ // Parse balanced containers from the outside, restoring code before entering each child store.
2459
+ function processGridBlocks(markdown, depth = 0) {
2460
+ if (depth >= 64) return markdown;
2461
+ const {scrubbed, restore} = scrubCodeRegions(markdown);
2462
+ const renderers = {
2463
+ background: (attrStr, inner) => {
2464
+ const css = backgroundStyle(parseShortcodeAttrs(attrStr));
2465
+ const body = markedBody(processCardBlocks(processInlineShortcodes(inner.trim())));
2466
+ return `<section class="cms-background"${css ? ` style="${escapeAttr(css)}"` : ''}>${body}</section>\n`;
2467
+ },
2468
+ col: (attrStr, body) => {
2469
+ const attrs = parseShortcodeAttrs(attrStr);
2470
+ const injected = extractInjectedEffects(attrs, ['reveal', 'breathe', 'animate', 'ripple']);
2471
+ const baseCls = attrs.span ? `col-span-${classToken(attrs.span)}` : 'col';
2472
+ // Explicit alignment takes precedence over the shorthand flags.
2473
+ const alignment = typeof attrs.align === 'string'
2474
+ ? attrs.align.trim().toLowerCase()
2475
+ : ['center', 'centre', 'left', 'right'].find(value => attrs[value] === true);
2476
+ const align = alignment === 'centre' ? 'center' : alignment;
2477
+ const alignClasses = ['left', 'center', 'right'].includes(align) ? [`text-${align}`] : [];
2478
+ const classes = [baseCls, ...alignClasses, ...injected.effectClasses];
2479
+ const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2480
+ return `<div class="${classes.join(' ')}"${id}${injected.effectDataAttrs}>${markedBody(processCardBlocks(processInlineShortcodes(body.trim())))}</div>`;
2481
+ },
2482
+ row: (attrStr, inner) => {
2483
+ const attrs = parseShortcodeAttrs(attrStr);
2484
+ const classes = ['row'];
2485
+ if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2486
+ if (attrs.class) classes.push(escapeAttr(attrs.class));
2487
+ const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2488
+ const reveal = attrs.reveal !== undefined ? ' data-reveal="true"' : '';
2489
+ const revealMode = attrs['reveal-mode'] ? ` data-reveal-mode="${escapeAttr(attrs['reveal-mode'])}"` : '';
2490
+ const revealAnimation = attrs['reveal-animation'] ? ` data-reveal-animation="${escapeAttr(attrs['reveal-animation'])}"` : '';
2491
+ const revealDuration = attrs['reveal-duration'] ? ` data-reveal-duration="${escapeAttr(attrs['reveal-duration'])}"` : '';
2492
+ const revealStagger = attrs['reveal-stagger'] ? ` data-reveal-stagger="${escapeAttr(attrs['reveal-stagger'])}"` : '';
2493
+ const revealDelay = attrs['reveal-delay'] ? ` data-reveal-delay="${escapeAttr(attrs['reveal-delay'])}"` : '';
2494
+ const revealDirection = attrs['reveal-direction'] ? ` data-reveal-direction="${escapeAttr(attrs['reveal-direction'])}"` : '';
2495
+ const revealReplay = isTruthyAttr(attrs['reveal-replay']) ? ' data-reveal-replay="true"' : '';
2496
+ const tilt = isTruthyAttr(attrs.tilt) ? ' data-tilt="true"' : '';
2497
+ return `<div class="${classes.join(' ')}"${id}${reveal}${revealMode}${revealAnimation}${revealDuration}${revealStagger}${revealDelay}${revealDirection}${revealReplay}${tilt}>${markedBody(processCardBlocks(processInlineShortcodes(inner.trim())))}</div>\n`;
2498
+ },
2499
+ grid: (attrStr, inner) => {
2500
+ const attrs = parseShortcodeAttrs(attrStr);
2501
+ const classes = ['grid'];
2502
+ if (attrs.cols) {
2503
+ classes.push(...(attrs.responsive === 'false'
2504
+ ? [`grid-cols-${classToken(attrs.cols)}`]
2505
+ : responsiveGridCols(attrs.cols)));
2521
2506
  }
2507
+ if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2508
+ if (attrs.class) classes.push(escapeAttr(attrs.class));
2509
+ if (attrs.fullwidth === 'true') classes.push('grid-breakout');
2510
+ const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2511
+ return `<div class="${classes.join(' ')}"${id}>${markedBody(processCardBlocks(processInlineShortcodes(inner.trim())))}</div>\n`;
2522
2512
  }
2523
- if (attrs.gap) classes.push(`gap-${classToken(attrs.gap)}`);
2524
- if (attrs.class) classes.push(escapeAttr(attrs.class));
2525
- if (attrs.fullwidth === 'true') classes.push('grid-breakout');
2526
- const id = attrs.id ? ` id="${escapeAttr(attrs.id)}"` : '';
2527
- return `<div class="${classes.join(' ')}"${id}>${inner}</div>\n`;
2513
+ };
2514
+ let result = scrubbed;
2515
+ for (const range of pairedRanges(scrubbed, new Set(['grid', 'row', 'col', 'background'])).reverse()) {
2516
+ const inner = processGridBlocks(restore(scrubbed.slice(range.bodyStart, range.bodyEnd)), depth + 1);
2517
+ const html = renderers[range.name](range.attrs, inner);
2518
+ result = result.slice(0, range.start) + html + result.slice(range.end);
2528
2519
  }
2529
- );
2520
+ return restore(result);
2521
+ }
2530
2522
 
2531
- return restore(result);
2523
+ /** Extract page-level singleton tags before any container can render or escape them. */
2524
+ function extractPageBackground(markdown) {
2525
+ const {scrubbed, restore} = scrubCodeRegions(markdown);
2526
+ const sections = pairedRanges(scrubbed, new Set(['background']));
2527
+ let background = null;
2528
+ const output = scrubbed.replace(/\[background(?=[\s/\]])((?:"[^"]*"|'[^']*'|[^\]"'])*?)\]/gi, (tag, attrs, offset) => {
2529
+ if (sections.some(range => offset >= range.start && offset < range.end)) return tag;
2530
+ background = normaliseBackground(parseShortcodeAttrs(attrs.replace(/\/\s*$/, ''))) || background;
2531
+ return '';
2532
+ });
2533
+ return {output: restore(output), background};
2532
2534
  }
2533
2535
 
2534
2536
  /**
@@ -5471,7 +5473,7 @@ export async function parseMarkdown(raw, opts = {}) {
5471
5473
  // → dconfig → effects → plugin shortcodes → tabs → accordion → carousel → countdown → timeline
5472
5474
  // → listgroup → spacer → center → icon → demo → embed → image → form → hero → table
5473
5475
  // → badge → text → button → link → cta → grid → card (+ box) → banner → slideover
5474
- // → marked → sanitize → afterParse
5476
+ // → background → marked → sanitize → afterParse
5475
5477
  // Comments must be removed before shortcodes are expanded. Protect code
5476
5478
  // examples first; four-space-indented lines remain Markdown code too.
5477
5479
  const comments = scrubCodeRegions(content, true);
@@ -5483,7 +5485,8 @@ export async function parseMarkdown(raw, opts = {}) {
5483
5485
  ...(opts.expiry || {}), urlPath: opts.urlPath || '/', parseAttrs: parseShortcodeAttrs
5484
5486
  });
5485
5487
  const visible = expirySafe.restore(expiry.markdown);
5486
- const preprocessed = opts[SLOT_FRAGMENT] ? visible : applyTransforms('markdown:beforeParse', visible);
5488
+ const withBackground = extractPageBackground(visible);
5489
+ const preprocessed = opts[SLOT_FRAGMENT] ? withBackground.output : applyTransforms('markdown:beforeParse', withBackground.output);
5487
5490
  const tagSet = new Set();
5488
5491
  const flags = {perViewer: false, hasExpiry:expiry.hasExpiry};
5489
5492
  const slotComponents = new Set();
@@ -5538,7 +5541,7 @@ export async function parseMarkdown(raw, opts = {}) {
5538
5541
  const filteredUsed = [...usedComponents].filter(name => allowed.has(name));
5539
5542
 
5540
5543
  // `content` is the body as written: the editor loads it from here, and the nesting indent is the person's.
5541
- return {data, content: written, html, usedComponents: filteredUsed, tags: [...tagSet], perViewer: flags.perViewer, hasExpiry:flags.hasExpiry};
5544
+ return {data, content: written, html, background: withBackground.background, usedComponents: filteredUsed, tags: [...tagSet], perViewer: flags.perViewer, hasExpiry:flags.hasExpiry};
5542
5545
  }
5543
5546
 
5544
5547
  /**
@@ -1,3 +1,4 @@
1
+ import {pageBackgroundStyleTag} from '../../public/js/background-style.mjs';
1
2
  /**
2
3
  * Renderer Service
3
4
  * Assembles the full HTML page shell from the template + page data + site config.
@@ -672,7 +673,7 @@ export async function renderPage(page, opts = {}) {
672
673
  // generated, custom.css is hand-written, and the hand-written one stays
673
674
  // the last word.
674
675
  headInjectLate: [injection.headLate, searchAssets.headTag, motionAssets.headTag, embed ? '' : switcherAssets.headTag,
675
- launcherAssets.headTag, embed ? EMBED_HEAD_TAG : '', themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
676
+ launcherAssets.headTag, embed ? EMBED_HEAD_TAG : '', themeView.customThemeStyleTag, themeView.overrideStyleTag, themeView.backgroundStyleTag, customCssTag, navbarStyleTag]
676
677
  .filter(Boolean).join('\n'),
677
678
  bodyEndInject: [
678
679
  // Draft banner - first, so it is the topmost fixed element and a
@@ -1189,7 +1190,8 @@ async function buildThemeView(page = {}) {
1189
1190
  fontStyleTag: fontOverride ? `<style>${fontOverride}</style>` : '',
1190
1191
  // Only the custom themes this page can show: its own, and day/night's.
1191
1192
  customThemeStyleTag: buildCustomThemeStyleTag([activeTheme, autoTheme?.dayTheme, autoTheme?.nightTheme]),
1192
- overrideStyleTag: buildOverrideStyleTag(cfg)
1193
+ overrideStyleTag: buildOverrideStyleTag(cfg),
1194
+ backgroundStyleTag: pageBackgroundStyleTag(page.background || cfg.background)
1193
1195
  };
1194
1196
  }
1195
1197
 
@@ -1455,7 +1457,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1455
1457
  // Theme overrides land BEFORE content/custom.css: the overrides are
1456
1458
  // generated, custom.css is hand-written, and the hand-written one stays
1457
1459
  // the last word.
1458
- headInjectLate: [bare ? '' : injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, launcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
1460
+ headInjectLate: [bare ? '' : injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, launcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, themeView.backgroundStyleTag, customCssTag, navbarStyleTag]
1459
1461
  .filter(Boolean).join('\n'),
1460
1462
  bodyEndInject: [
1461
1463
  overlayMenus,
@@ -1,3 +1,4 @@
1
+ import {normaliseBackground} from '../../public/js/background-style.mjs';
1
2
  /**
2
3
  * Theme settings - config/theme.json.
3
4
  *
@@ -109,6 +110,7 @@ export function defaultThemeConfig() {
109
110
  lightTheme: 'charcoal-light',
110
111
  darkTheme: 'charcoal-dark'
111
112
  },
113
+ background: null,
112
114
  overrides: []
113
115
  };
114
116
  }
@@ -412,6 +414,7 @@ function definedOnly(obj) {
412
414
  function mergeDefaults(raw) {
413
415
  const d = defaultThemeConfig();
414
416
  const cfg = {...d, ...definedOnly(raw)};
417
+ cfg.background = normaliseBackground(raw?.background);
415
418
  cfg.autoTheme = {...d.autoTheme, ...definedOnly(raw?.autoTheme)};
416
419
  cfg.font = {...d.font, ...definedOnly(raw?.font)};
417
420
  cfg.switcher = {...d.switcher, ...definedOnly(raw?.switcher)};
@@ -649,6 +652,7 @@ export function validateThemeConfig(input, {remembered = [], currentSwitcher = {
649
652
  const errors = [];
650
653
  if (!input || typeof input !== 'object') return ['Theme config must be an object'];
651
654
 
655
+ if (input.background != null && !normaliseBackground(input.background)) errors.push('Choose a valid background type, preset or colour');
652
656
  const builtins = listThemeIds();
653
657
  // Custom themes (a plugin's) are chosen like any other - except by the
654
658
  // public switcher below, which switches through Domma's engine. One the
@@ -25,7 +25,7 @@
25
25
  <link rel="stylesheet" href="/dist/domma/themes/domma-themes.css">
26
26
 
27
27
  <!-- Site CSS -->
28
- <link rel="stylesheet" href="/public/css/site.css?v=20261112-card-body-align">
28
+ <link rel="stylesheet" href="/public/css/site.css?v=20261112-backgrounds">
29
29
  <link rel="stylesheet" href="/public/css/forms.css?v=20261031-forms-reduce-motion">
30
30
  <!-- Menu item hover / current-page effects. Loaded after site.css so a
31
31
  menu's own highlight wins over the blanket link styling there. -->