domma-cms 1.67.2 → 1.69.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.
- package/CHANGELOG.md +39 -0
- package/CLAUDE.md +2 -0
- package/admin/js/lib/layouts-arrange.js +1 -1
- package/admin/js/lib/rich-field.js +9 -2
- package/admin/js/lib/seo-defaults.js +1 -1
- package/admin/js/templates/docs/api-content.html +3 -2
- package/admin/js/templates/docs/api-layouts.html +1 -1
- package/admin/js/templates/docs/usage-navigation.html +2 -1
- package/admin/js/templates/docs/usage-pages.html +3 -1
- package/admin/js/templates/docs/usage-search-engines.html +3 -0
- package/admin/js/templates/page-editor.html +3 -3
- package/admin/js/views/form-editor.js +5 -5
- package/admin/js/views/layouts.js +7 -7
- package/admin/js/views/menu-editor.js +20 -20
- package/admin/js/views/page-editor.js +9 -9
- package/admin/js/views/seo.js +31 -30
- package/docs/DommaFeatures.md +6 -2
- package/docs/api-reference.md +7 -3
- package/docs/guides/multi-page-forms.md +1 -1
- package/docs/markdown-shortcodes.md +1 -1
- package/docs/plugin-development.md +20 -0
- package/package.json +1 -1
- package/plugins/blog/CHANGELOG.md +3 -0
- package/plugins/blog/CLAUDE.md +15 -0
- package/plugins/blog/admin/views/categories.js +5 -2
- package/plugins/blog/admin/views/kit.js +19 -0
- package/plugins/blog/docs/guide.md +2 -0
- package/plugins/blog/plugin.js +18 -2
- package/plugins/blog/plugin.json +6 -6
- package/plugins/blog/plugin.public.js +16 -2
- package/plugins/blog/public/blog.css +3 -0
- package/plugins/blog/tests/public.test.js +29 -2
- package/plugins/feedback/CLAUDE.md +22 -0
- package/plugins/feedback/admin/css/index.css +2 -0
- package/plugins/feedback/admin/views/inbox.js +5 -2
- package/plugins/feedback/admin/views/send.js +12 -5
- package/plugins/feedback/docs/guide.md +3 -2
- package/plugins/feedback/lib/sender.js +1 -1
- package/plugins/feedback/lib/shape.js +72 -11
- package/plugins/feedback/plugin.js +3 -3
- package/plugins/feedback/plugin.json +3 -2
- package/plugins/feedback/tests/api.test.js +47 -1
- package/plugins/feedback/tests/shape.test.js +87 -1
- package/plugins/free-tier.lock.json +43 -42
- package/plugins/shopping-cart/CHANGELOG.md +20 -0
- package/plugins/shopping-cart/CLAUDE.md +38 -1
- package/plugins/shopping-cart/admin/css/index.css +4 -0
- package/plugins/shopping-cart/admin/lib/kit.js +1 -0
- package/plugins/shopping-cart/admin/views/products.js +95 -3
- package/plugins/shopping-cart/admin/views/shop.js +2 -1
- package/plugins/shopping-cart/docs/guide.md +6 -1
- package/plugins/shopping-cart/inject/body.html +2 -2
- package/plugins/shopping-cart/lib/description.js +173 -0
- package/plugins/shopping-cart/lib/render.js +3 -2
- package/plugins/shopping-cart/lib/shop.js +4 -1
- package/plugins/shopping-cart/plugin.js +17 -2
- package/plugins/shopping-cart/plugin.json +3 -2
- package/plugins/shopping-cart/plugin.public.js +6 -9
- package/plugins/shopping-cart/public/lib/products.js +40 -3
- package/plugins/shopping-cart/public/shop.css +1 -0
- package/plugins/shopping-cart/tests/pure.test.js +26 -1
- package/plugins/shopping-cart/tests/seo.test.js +174 -0
- package/public/js/collection-browser.js +1 -1
- package/public/js/menu-cards.mjs +4 -4
- package/public/js/menu-look.mjs +1 -1
- package/public/js/rich-text.mjs +4 -4
- package/public/js/site.js +1 -1
- package/server/routes/api/collections.js +26 -12
- package/server/routes/api/forms.js +5 -3
- package/server/routes/api/layouts.js +8 -4
- package/server/routes/api/seo.js +10 -4
- package/server/services/adapters/FileAdapter.js +4 -3
- package/server/services/adapters/MongoAdapter.js +4 -2
- package/server/services/content.js +23 -0
- package/server/services/contentApi.js +27 -4
- package/server/services/filterEngine.js +33 -0
- package/server/services/forms.js +58 -2
- package/server/services/health.js +3 -1
- package/server/services/markdown.js +288 -38
- package/server/services/menus.js +56 -6
- package/server/services/renderer.js +28 -4
- package/server/services/richText.js +56 -3
- package/server/services/search.js +5 -2
- package/server/services/sitemap.js +5 -3
- package/server/templates/page.html +2 -2
|
@@ -18,6 +18,7 @@ import {applyTransforms, getSanitizeExtensions, getShortcodeProcessors} from './
|
|
|
18
18
|
import {getConfig} from '../config.js';
|
|
19
19
|
import {getCollection, listEntries} from './collections.js';
|
|
20
20
|
import {pagesAllowed} from './collectionAccess.js';
|
|
21
|
+
import {confineFilter} from './filterEngine.js';
|
|
21
22
|
import {getMenu, navbarOverrideFromAttrs, resolveLocation, resolveMenuDecorations} from './menus.js';
|
|
22
23
|
import {contentsOverrideFromAttrs} from './pageContents.js';
|
|
23
24
|
import {buildMenuNav} from './menuRender.js';
|
|
@@ -27,7 +28,7 @@ import {buildTextStyle, buildTextMotion} from '../../public/js/text-style.mjs';
|
|
|
27
28
|
import {buildScribeStyle} from '../../public/js/scribe-style.mjs';
|
|
28
29
|
import {CHARACTERS, resolveCharacterSize} from '../../public/js/celebrations/character-catalog.mjs';
|
|
29
30
|
import {publicButtonSettings} from '../../public/js/form-submit.mjs';
|
|
30
|
-
import {FILE_LIMITS_TAG, publicFileLimits} from './forms.js';
|
|
31
|
+
import {FILE_LIMITS_TAG, publicFileLimits, publicFormDescriptions} from './forms.js';
|
|
31
32
|
import {applyShortcodeExpiry} from './shortcodeExpiry.js';
|
|
32
33
|
import {richTextToPlain} from '../../public/js/rich-text.mjs';
|
|
33
34
|
|
|
@@ -128,6 +129,37 @@ function escapeHtmlText(str) {
|
|
|
128
129
|
* @param {Record<string, string>} attrs - All parsed shortcode attributes
|
|
129
130
|
* @returns {Record<string, string>} Filter object suitable for filterEngine
|
|
130
131
|
*/
|
|
132
|
+
const FIELD_ATTRS = ['title-field', 'body-field', 'date-field', 'status-field', 'icon-field', 'image-field'];
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Shortcode attributes cut down to a set of field names: `fields` keeps only
|
|
136
|
+
* those (all of them when it named none), a `*-field` naming another goes,
|
|
137
|
+
* a `where_` on another goes (the legacy `where=""` whole), and so does a sort.
|
|
138
|
+
* The result has no prototype, and no `__proto__` key is copied: these
|
|
139
|
+
* attributes are a browser's JSON, and an inherited `where` would be read.
|
|
140
|
+
*
|
|
141
|
+
* @param {Record<string, unknown>} attrs
|
|
142
|
+
* @param {Set<string>} allowed
|
|
143
|
+
* @returns {Record<string, unknown>}
|
|
144
|
+
*/
|
|
145
|
+
function confineAttrsToFields(attrs, allowed) {
|
|
146
|
+
const out = Object.create(null);
|
|
147
|
+
const wheres = {};
|
|
148
|
+
for (const key of Object.keys(attrs)) {
|
|
149
|
+
if (key === 'where' || key === '__proto__' || key === 'constructor' || key === 'prototype') continue;
|
|
150
|
+
const value = attrs[key];
|
|
151
|
+
if (key.startsWith('where_')) { wheres[key.slice('where_'.length)] = value; continue; }
|
|
152
|
+
if (FIELD_ATTRS.includes(key) && !allowed.has(String(value))) continue;
|
|
153
|
+
out[key] = value;
|
|
154
|
+
}
|
|
155
|
+
for (const [inner, value] of Object.entries(confineFilter(wheres, allowed))) out[`where_${inner}`] = value;
|
|
156
|
+
const named = typeof attrs.fields === 'string'
|
|
157
|
+
? attrs.fields.split(',').map(f => f.trim()).filter(f => allowed.has(f)) : [];
|
|
158
|
+
out.fields = (named.length ? named : [...allowed]).join(',');
|
|
159
|
+
if (out.sort !== undefined && !allowed.has(String(out.sort)) && !['createdAt', 'updatedAt'].includes(String(out.sort))) delete out.sort;
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
|
|
131
163
|
function buildShortcodeFilter(attrs) {
|
|
132
164
|
const filter = {};
|
|
133
165
|
|
|
@@ -416,7 +448,9 @@ function blockTemplateFields(tpl) {
|
|
|
416
448
|
export function buildBlockStyleTag(blockName, css) {
|
|
417
449
|
if (!css || !css.trim()) return '';
|
|
418
450
|
const body = String(css)
|
|
419
|
-
|
|
451
|
+
// A "<" that could open a tag, as a CSS escape: the sanitiser drops a <style>
|
|
452
|
+
// that holds one. (`width < 600px` and `<=` in a media query stay as written.)
|
|
453
|
+
.replace(/<(?=[a-zA-Z\/!?])/g, '\\3C ')
|
|
420
454
|
.replace(/\n\s*\n+/g, '\n')
|
|
421
455
|
.trim();
|
|
422
456
|
return `<style>[data-block="${escapeAttr(blockName)}"] {\n${body}\n}</style>\n`;
|
|
@@ -443,24 +477,182 @@ export function buildBlockStyleTag(blockName, css) {
|
|
|
443
477
|
* blank lines stay: they are how a template hands a Markdown value to marked.
|
|
444
478
|
* Each line is filled by itself, in one pass as before.
|
|
445
479
|
*/
|
|
480
|
+
/**
|
|
481
|
+
* A placeholder written inside an attribute VALUE of the template's own tag
|
|
482
|
+
* (`<a href="{{{url}}}">`, `title="{{name}}"`, `width={{w}}`), or inside one of
|
|
483
|
+
* the template's own shortcode tags (`[button href="{{url}}"]`), stays inside
|
|
484
|
+
* that value. Quotes and angle brackets become entities, so a `{{{raw}}}` value
|
|
485
|
+
* cannot close the attribute and add its own; line breaks and square brackets
|
|
486
|
+
* do too, because a blank line would end the HTML block and hand the rest of
|
|
487
|
+
* the value to Markdown, whose link output carries a quote, and a `]` would
|
|
488
|
+
* end the shortcode tag. In an unquoted value, spaces and `=` as well. `&` is
|
|
489
|
+
* left alone (entities stay entities).
|
|
490
|
+
*/
|
|
491
|
+
function keepInAttrValue(value, unquoted) {
|
|
492
|
+
return String(value).replace(unquoted ? /["'<>\[\]`\s=]/g : /["'<>\[\]`\r\n]/g, ch => `&#${ch.charCodeAt(0)};`);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Where each placeholder of one template line sits, read the way a browser
|
|
497
|
+
* reads tags:
|
|
498
|
+
* 'quoted' / 'unquoted' inside an attribute value
|
|
499
|
+
* 'tag' between a tag's attributes (`<input {{checked}}>`)
|
|
500
|
+
* 'name' part of a tag or attribute name (`<h{{level}}>`)
|
|
501
|
+
* 'shortcode' / 'shortcode-bare' inside one of the template's shortcode tags, in a quoted value / not
|
|
502
|
+
* nothing in text.
|
|
503
|
+
* `state` carries over lines (a tag may span several): T text, G inside a tag
|
|
504
|
+
* between attributes, E after `=`, U an unquoted value, S / S" / S' inside a
|
|
505
|
+
* shortcode tag, or the open quote.
|
|
506
|
+
*/
|
|
507
|
+
function placeholderContexts(line, spans, state) {
|
|
508
|
+
const at = new Map();
|
|
509
|
+
let next = 0;
|
|
510
|
+
for (let i = 0; i < line.length; i++) {
|
|
511
|
+
const span = spans[next];
|
|
512
|
+
if (span && i === span.index) {
|
|
513
|
+
if (state === '"' || state === "'") at.set(i, 'quoted');
|
|
514
|
+
else if (state === 'E' || state === 'U') { at.set(i, 'unquoted'); state = 'U'; }
|
|
515
|
+
else if (state === 'G') at.set(i, /[\w<:-]/.test(line[i - 1] ?? ' ') ? 'name' : 'tag');
|
|
516
|
+
else if (state[0] === 'S') at.set(i, state === 'S' ? 'shortcode-bare' : 'shortcode');
|
|
517
|
+
i += span[0].length - 1;
|
|
518
|
+
next++;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const ch = line[i];
|
|
522
|
+
if (state === 'T') {
|
|
523
|
+
if (ch === '<' && (/[a-zA-Z/]/.test(line[i + 1] || '') || line.startsWith('{{', i + 1))) state = 'G';
|
|
524
|
+
else if (ch === '[' && /[a-zA-Z/]/.test(line[i + 1] || '')) {
|
|
525
|
+
// A shortcode tag that closes on this line - and not as a Markdown link, [words](address).
|
|
526
|
+
const close = line.indexOf(']', i);
|
|
527
|
+
if (close !== -1 && line[close + 1] !== '(') state = 'S';
|
|
528
|
+
}
|
|
529
|
+
} else if (state === 'G') {
|
|
530
|
+
if (ch === '>') state = 'T'; else if (ch === '=') state = 'E';
|
|
531
|
+
} else if (state === 'E') {
|
|
532
|
+
if (ch === '"' || ch === "'") state = ch;
|
|
533
|
+
else if (ch === '>') state = 'T';
|
|
534
|
+
else if (!/\s/.test(ch)) state = 'U';
|
|
535
|
+
} else if (state === 'U') {
|
|
536
|
+
if (ch === '>') state = 'T'; else if (/\s/.test(ch)) state = 'G';
|
|
537
|
+
} else if (state === 'S') {
|
|
538
|
+
// A quote opens a value only after "=": [don't miss this] has none.
|
|
539
|
+
if (ch === ']') state = 'T'; else if ((ch === '"' || ch === "'") && line[i - 1] === '=') state = `S${ch}`;
|
|
540
|
+
} else if (state[0] === 'S') {
|
|
541
|
+
if (ch === state[1]) state = 'S';
|
|
542
|
+
} else if (ch === state) state = 'G';
|
|
543
|
+
}
|
|
544
|
+
// A line break ends an unquoted value; a quoted one runs on. A shortcode tag
|
|
545
|
+
// is followed on its own line only.
|
|
546
|
+
if (state === 'U') state = 'G';
|
|
547
|
+
if (state[0] === 'S') state = 'T';
|
|
548
|
+
return {at, state};
|
|
549
|
+
}
|
|
550
|
+
|
|
446
551
|
function fillTemplateLines(template, fill) {
|
|
447
552
|
const PLACEHOLDER = /\{\{\{(\w+)\}\}\}|\{\{([\w_]+)(?::([^{}]+))?\}\}/g;
|
|
448
553
|
const out = [];
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
554
|
+
let state = 'T';
|
|
555
|
+
const lines = template.split('\n');
|
|
556
|
+
lines.forEach((line, n) => {
|
|
557
|
+
const spans = [...line.matchAll(PLACEHOLDER)];
|
|
558
|
+
// Alone on its line with a blank line (or the template's edge) either side,
|
|
559
|
+
// in text: where a template hands a value to Markdown.
|
|
560
|
+
const alone = state === 'T' && spans.length === 1 && line.trim() === spans[0][0]
|
|
561
|
+
&& !(lines[n - 1] ?? '').trim() && !(lines[n + 1] ?? '').trim();
|
|
562
|
+
const where = placeholderContexts(line, spans, state);
|
|
563
|
+
state = where.state;
|
|
564
|
+
const filled = line.replace(PLACEHOLDER, (m, raw, key, fmt, offset) => {
|
|
565
|
+
const context = where.at.get(offset) || (alone ? 'markdown' : undefined);
|
|
566
|
+
const value = fill(m, raw, key, fmt, context);
|
|
567
|
+
return ['quoted', 'unquoted', 'shortcode', 'shortcode-bare'].includes(context)
|
|
568
|
+
? keepInAttrValue(value, context === 'unquoted' || context === 'shortcode-bare') : value;
|
|
569
|
+
});
|
|
570
|
+
if (!filled.trim() && line.trim() && /\{\{/.test(line)) return;
|
|
452
571
|
out.push(filled);
|
|
453
|
-
}
|
|
572
|
+
});
|
|
454
573
|
return out.join('\n');
|
|
455
574
|
}
|
|
456
575
|
|
|
576
|
+
/**
|
|
577
|
+
* Entry HTML that reaches a page as HTML (a `{{{raw}}}` placeholder, a body
|
|
578
|
+
* field read as Markdown) may carry content, never the site's own machinery.
|
|
579
|
+
* `data-` attributes are what site.js and the displays act on (a table payload,
|
|
580
|
+
* an Action button, a slideover target), and a <div> an entry dressed as a
|
|
581
|
+
* collection table ran script. So such HTML is PARSED here and written out
|
|
582
|
+
* again under the entry profile of sanitizePageHtml (no `data-*`, no component
|
|
583
|
+
* tags, no <style>, no plugin extensions) - by the same parser the page's own
|
|
584
|
+
* sanitiser uses, so the two cannot read a tag differently. Rewriting the text
|
|
585
|
+
* instead (an entity for the hyphen) was tried and was got round twice.
|
|
586
|
+
*
|
|
587
|
+
* A value with nothing that could open a tag is returned as it is: it is text
|
|
588
|
+
* or Markdown, and cannot make an element. A `>` that starts a line is put
|
|
589
|
+
* back as `>` after the pass (text there, never inside a tag: attribute values
|
|
590
|
+
* come out on one line) so a Markdown quote beside HTML survives.
|
|
591
|
+
*
|
|
592
|
+
* @param {unknown} value
|
|
593
|
+
* @returns {string}
|
|
594
|
+
*/
|
|
595
|
+
function entryHtml(value) {
|
|
596
|
+
const text = String(value ?? '').replace(/[\x02\x03]/g, '');
|
|
597
|
+
// No tag in it: it is text or Markdown and is left alone, but for a "<" at
|
|
598
|
+
// its very end, which would open a tag with whatever the template puts next.
|
|
599
|
+
if (!/<[a-zA-Z\/!?]/.test(text)) return text.replace(/<(\s*)$/, '<$1');
|
|
600
|
+
return sanitizePageHtml(text, {entry: true}).replace(/^(?:> ?)+/gm, quote => quote.replace(/>/g, '>'));
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* An entry value written between a tag's attributes (`<input {{checked}}>`,
|
|
605
|
+
* `<div {{{extra}}}>`): read as attributes and nothing else, and written back
|
|
606
|
+
* one by one. No `data-` name and no handler; the page sanitiser still decides
|
|
607
|
+
* which of the rest the tag may keep.
|
|
608
|
+
*
|
|
609
|
+
* @param {unknown} value
|
|
610
|
+
* @returns {string}
|
|
611
|
+
*/
|
|
612
|
+
function entryAttrs(value) {
|
|
613
|
+
const text = String(value ?? '').replace(/[\x02\x03<>]/g, ' ');
|
|
614
|
+
const kept = [];
|
|
615
|
+
for (const [, name, dq, sq, bare] of text.matchAll(/([^\s"'=\/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=`]+)))?/g)) {
|
|
616
|
+
if (!/^[a-zA-Z][\w:.-]*$/.test(name) || /^on/i.test(name) || (/^data-/i.test(name) && !/^data-(?:icon|copy)$/i.test(name))) continue;
|
|
617
|
+
const given = dq ?? sq ?? bare;
|
|
618
|
+
kept.push(given === undefined ? name : `${name}="${escapeAttr(given.replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&'))}"`);
|
|
619
|
+
}
|
|
620
|
+
return kept.join(' ');
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* An entry's body read as Markdown and kept as content (the entry profile):
|
|
625
|
+
* the body field of the accordion, timeline, carousel and list group displays,
|
|
626
|
+
* and a `{{{raw}}}` value a template hands to Markdown. No line of the result
|
|
627
|
+
* is blank - a blank line (inside a code block, say) would end the HTML block
|
|
628
|
+
* in a later Markdown pass and the rest would be read as Markdown again.
|
|
629
|
+
*/
|
|
630
|
+
function entryBody(value, inline = false) {
|
|
631
|
+
const text = String(value ?? '').replace(/[\x02\x03]/g, '');
|
|
632
|
+
let html = sanitizePageHtml(inline ? marked.parseInline(text) : marked.parse(text), {entry: true});
|
|
633
|
+
// (An inline body - the list group's - keeps its blank lines: they are its paragraphs.)
|
|
634
|
+
while (!inline && /\n[ \t]*\n/.test(html)) html = html.replace(/\n([ \t]*)\n/g, '\n$1 ');
|
|
635
|
+
return html;
|
|
636
|
+
}
|
|
637
|
+
|
|
457
638
|
function interpolateBlockTemplate(blockTemplate, e) {
|
|
458
639
|
// One pass: a raw value put in (pre-rendered HTML) is never read again for
|
|
459
640
|
// placeholders - text that shows "{{title}}" keeps it.
|
|
460
|
-
return fillTemplateLines(blockTemplate, (_, raw, key, fmt) => {
|
|
641
|
+
return fillTemplateLines(blockTemplate, (_, raw, key, fmt, context) => {
|
|
461
642
|
// Entry values never carry a shortcode into the page (inertShortcodes);
|
|
462
|
-
// the template's own markup is untouched.
|
|
463
|
-
|
|
643
|
+
// the template's own markup is untouched. Where the placeholder sits
|
|
644
|
+
// decides what a value may be: attributes between a tag's attributes,
|
|
645
|
+
// name characters inside a name, content (entryHtml / entryBody) in text.
|
|
646
|
+
// Inside an attribute value fillTemplateLines keeps it there.
|
|
647
|
+
const field = raw ?? key;
|
|
648
|
+
const stored = field === '_id' ? e.id : field === '_createdAt' ? e.meta?.createdAt
|
|
649
|
+
: field === '_updatedAt' ? e.meta?.updatedAt : e.data?.[field];
|
|
650
|
+
if (context === 'tag') return inertShortcodes(entryAttrs(stored));
|
|
651
|
+
if (context === 'name') return String(stored ?? '').replace(/[^\w-]/g, '');
|
|
652
|
+
if (raw !== undefined) {
|
|
653
|
+
if (context === 'markdown') return inertShortcodes(entryBody(stored).trim());
|
|
654
|
+
return inertShortcodes(context ? String(stored ?? '') : entryHtml(stored));
|
|
655
|
+
}
|
|
464
656
|
let value;
|
|
465
657
|
if (key === '_id') value = e.id ?? '';
|
|
466
658
|
else if (key === '_createdAt') value = e.meta?.createdAt ?? '';
|
|
@@ -739,7 +931,8 @@ function fileRefHtml(ref) {
|
|
|
739
931
|
const url = escapeAttr(ref.url);
|
|
740
932
|
const name = escapeHtmlText(ref.name);
|
|
741
933
|
if (String(ref.mime || '').startsWith('image/')) {
|
|
742
|
-
|
|
934
|
+
// alt is an attribute: escapeAttr (line breaks as entities), not the text escaper.
|
|
935
|
+
return `<a href="${url}" target="_blank" rel="noopener"><img src="${url}" alt="${escapeAttr(ref.name ?? '')}" loading="lazy" class="dm-file-thumb"></a>`;
|
|
743
936
|
}
|
|
744
937
|
return `<a href="${url}" download>${name}</a>`;
|
|
745
938
|
}
|
|
@@ -903,7 +1096,7 @@ function renderCollectionAccordion(entries, titleField, bodyField, multiple, emp
|
|
|
903
1096
|
const items = entries.map(e => {
|
|
904
1097
|
const title = escapeHtmlText(String(e.data?.[titleField] ?? e.id ?? '(untitled)'));
|
|
905
1098
|
const bodyVal = String(e.data?.[bodyField] ?? '');
|
|
906
|
-
const bodyHtml =
|
|
1099
|
+
const bodyHtml = entryBody(bodyVal);
|
|
907
1100
|
return (
|
|
908
1101
|
`<div class="accordion-item${entryClassSuffix(ctxOpts)}" data-entry-id="${inertShortcodes(escapeAttr(String(e.id ?? '')))}">\n` +
|
|
909
1102
|
` <h3 class="accordion-header"><button class="accordion-button" type="button">${title}` +
|
|
@@ -949,7 +1142,7 @@ function renderCollectionTimeline(entries, opts, ctxOpts = {}) {
|
|
|
949
1142
|
// icon, replacing its children - which wiped each item's title and body before site.js read them.
|
|
950
1143
|
const icon = iconField && e.data?.[iconField] != null ? ` data-event-icon="${escapeAttr(String(e.data[iconField]))}"` : '';
|
|
951
1144
|
const bodyHtml = bodyField
|
|
952
|
-
?
|
|
1145
|
+
? entryBody(e.data?.[bodyField])
|
|
953
1146
|
: '';
|
|
954
1147
|
return `<div class="dm-progression-item${entryClassSuffix(ctxOpts)}" data-entry-id="${inertShortcodes(escapeAttr(String(e.id ?? '')))}"${date}${status}${icon}><div class="dm-progression-item-title">${title}</div><div class="dm-progression-item-body">${bodyHtml}</div></div>`;
|
|
955
1148
|
}).join('\n');
|
|
@@ -1009,7 +1202,7 @@ function renderCollectionCarousel(entries, opts, ctxOpts = {}) {
|
|
|
1009
1202
|
? `<h2 class="carousel-slide-title">${escapeHtmlText(String(e.data[titleField]))}</h2>`
|
|
1010
1203
|
: '';
|
|
1011
1204
|
const bodyHtml = bodyField && e.data?.[bodyField] != null
|
|
1012
|
-
? `<div class="carousel-slide-description">${
|
|
1205
|
+
? `<div class="carousel-slide-description">${entryBody(e.data[bodyField])}</div>`
|
|
1013
1206
|
: '';
|
|
1014
1207
|
inner = inertShortcodes(img + (title || bodyHtml ? `<div class="carousel-slide-content">${title}${bodyHtml}</div>` : ''));
|
|
1015
1208
|
}
|
|
@@ -1102,7 +1295,7 @@ function renderCollectionListgroup(entries, opts, ctxOpts = {}) {
|
|
|
1102
1295
|
? `<strong>${escapeHtmlText(String(e.data[titleField]))}</strong>`
|
|
1103
1296
|
: '';
|
|
1104
1297
|
const body = bodyField && e.data?.[bodyField] != null
|
|
1105
|
-
? `${title ? ' ' : ''}${
|
|
1298
|
+
? `${title ? ' ' : ''}${entryBody(e.data[bodyField], true)}`
|
|
1106
1299
|
: '';
|
|
1107
1300
|
inner = inertShortcodes((title + body) || escapeHtmlText(String(e.id ?? '')));
|
|
1108
1301
|
}
|
|
@@ -1805,13 +1998,17 @@ export const FALLBACK_MAX = 1000;
|
|
|
1805
1998
|
* @param {Array<object>} [opts.entries] - Entries already fetched (a browser shell's), drawn instead of querying
|
|
1806
1999
|
* @returns {Promise<string>} HTML fragment ready to inject into a page
|
|
1807
2000
|
*/
|
|
1808
|
-
export async function renderCollectionFragment(attrs, { extraFilter = null, scope = '', entries: given = null } = {}) {
|
|
2001
|
+
export async function renderCollectionFragment(attrs, { extraFilter = null, scope = '', entries: given = null, readFields = null } = {}) {
|
|
1809
2002
|
const slug = attrs.slug || '';
|
|
1810
2003
|
if (!slug) return '';
|
|
2004
|
+
// Attributes that came from a browser (render-fragment) see only the fields the
|
|
2005
|
+
// collection's public read lists: nothing else is named, filtered or sorted on.
|
|
2006
|
+
const confined = Array.isArray(readFields) && readFields.length ? new Set(readFields) : null;
|
|
2007
|
+
if (confined) attrs = confineAttrsToFields(attrs, confined);
|
|
1811
2008
|
|
|
1812
2009
|
const display = attrs.display || 'table';
|
|
1813
2010
|
const limitAttr = parseInt(attrs.limit, 10) || 0;
|
|
1814
|
-
const sort = attrs.sort
|
|
2011
|
+
const sort = typeof attrs.sort === 'string' && attrs.sort ? attrs.sort : 'createdAt';
|
|
1815
2012
|
const order = attrs.order || 'desc';
|
|
1816
2013
|
const titleField = attrs['title-field'] || '';
|
|
1817
2014
|
const columns = attrs.columns || '3';
|
|
@@ -1855,9 +2052,12 @@ export async function renderCollectionFragment(attrs, { extraFilter = null, scop
|
|
|
1855
2052
|
if (Object.keys(filter).length) listOpts.filter = filter;
|
|
1856
2053
|
|
|
1857
2054
|
// A browser shell hands over the entries it already fetched (refs resolved).
|
|
1858
|
-
|
|
2055
|
+
let {entries} = Array.isArray(given) ? {entries: given} : await listEntries(slug, listOpts);
|
|
2056
|
+
const only = (object) => Object.fromEntries(Object.entries(object || {}).filter(([k]) => confined.has(k)));
|
|
2057
|
+
if (confined) entries = entries.map(e => ({...e, data: only(e.data), ...(e._refs && {_refs: only(e._refs)})}));
|
|
1859
2058
|
|
|
1860
2059
|
let fields = schema.fields || [];
|
|
2060
|
+
if (confined) fields = fields.filter(f => confined.has(f.name));
|
|
1861
2061
|
if (fieldFilter?.length) {
|
|
1862
2062
|
fields = fieldFilter.map(name => fields.find(f => f.name === name) || { name, label: name });
|
|
1863
2063
|
} else {
|
|
@@ -2713,11 +2913,19 @@ export function classToken(value) {
|
|
|
2713
2913
|
}
|
|
2714
2914
|
|
|
2715
2915
|
export function escapeAttr(str) {
|
|
2916
|
+
// ' and line breaks too. A value is often entry data, and the HTML this makes
|
|
2917
|
+
// is read again by Markdown: a blank line inside an attribute value ended the
|
|
2918
|
+
// HTML block there, the rest of the value was read as Markdown, and the quotes
|
|
2919
|
+
// a Markdown link writes closed the attribute and added others. As entities a
|
|
2920
|
+
// browser reads the same value, and a later pass sees one unbroken line.
|
|
2716
2921
|
return String(str)
|
|
2717
2922
|
.replace(/&/g, '&')
|
|
2718
2923
|
.replace(/"/g, '"')
|
|
2924
|
+
.replace(/'/g, ''')
|
|
2719
2925
|
.replace(/</g, '<')
|
|
2720
|
-
.replace(/>/g, '>')
|
|
2926
|
+
.replace(/>/g, '>')
|
|
2927
|
+
.replace(/\r/g, ' ')
|
|
2928
|
+
.replace(/\n/g, ' ');
|
|
2721
2929
|
}
|
|
2722
2930
|
|
|
2723
2931
|
/**
|
|
@@ -3680,9 +3888,16 @@ function processCardBlocks(markdown) {
|
|
|
3680
3888
|
const body = restore(range.name === 'card' && layout === 'code-snippet'
|
|
3681
3889
|
? rawBody : render(rawBody, true));
|
|
3682
3890
|
const renderer = LAYOUT_RENDERERS[layout] || renderLegacyCard;
|
|
3683
|
-
const
|
|
3891
|
+
const drawn = range.name === 'box'
|
|
3684
3892
|
? renderBox(attrs, body)
|
|
3685
3893
|
: renderer(attrs, body, inertMarked, escapeAttr);
|
|
3894
|
+
// A code span in an attribute (title="Run `npm test`") is still its scrub
|
|
3895
|
+
// placeholder here (the body's were restored above): print it as the words
|
|
3896
|
+
// written - escaped, brackets as entities - so it is never markup or a tag.
|
|
3897
|
+
const html = drawn.replace(SCRUB_PLACEHOLDER, mark => {
|
|
3898
|
+
const written = restore(mark);
|
|
3899
|
+
return written === mark ? mark : bracketSafeAttr(written);
|
|
3900
|
+
});
|
|
3686
3901
|
const token = `<!--cms-card-${nonce}-${held.size}-->`;
|
|
3687
3902
|
held.set(token, html);
|
|
3688
3903
|
const gap = nested ? '\n\n' : '';
|
|
@@ -5022,9 +5237,12 @@ async function expandReferenceFields(form) {
|
|
|
5022
5237
|
const r = await listEntries(targetSlug, {limit: REF_LIMIT, sort: displayField, order: 'asc'});
|
|
5023
5238
|
const options = (r.entries || []).map(e => ({
|
|
5024
5239
|
value: e.id,
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5240
|
+
// Words, never markup: Domma writes an option's label as HTML, and
|
|
5241
|
+
// this one is another collection's entry value. Angle brackets
|
|
5242
|
+
// become their look-alikes (right whether it is read as HTML or text).
|
|
5243
|
+
label: String((e.data?.[displayField] != null && e.data[displayField] !== '')
|
|
5244
|
+
? e.data[displayField]
|
|
5245
|
+
: e.id).replace(/</g, '\u2039').replace(/>/g, '\u203A')
|
|
5028
5246
|
}));
|
|
5029
5247
|
|
|
5030
5248
|
// Replace with a select; preserve label/required/helper from the original.
|
|
@@ -5105,7 +5323,7 @@ async function processFormBlocks(markdown, tagSet) {
|
|
|
5105
5323
|
const {actions: _actions, ...publicForm} = form;
|
|
5106
5324
|
// A Cancel link that is not safe to draw stays out of the page source.
|
|
5107
5325
|
if (publicForm.settings) publicForm.settings = publicButtonSettings(publicForm.settings);
|
|
5108
|
-
const drawn = publicFileLimits(publicForm);
|
|
5326
|
+
const drawn = publicFileLimits(publicFormDescriptions(publicForm));
|
|
5109
5327
|
if (drawn.fileLimits) tagSet?.add(FILE_LIMITS_TAG);
|
|
5110
5328
|
const encoded = Buffer.from(JSON.stringify(drawn)).toString('base64');
|
|
5111
5329
|
const extraClass = attrs.class ? ` ${escapeAttr(attrs.class)}` : '';
|
|
@@ -5234,11 +5452,14 @@ function holdBannerTags(markdown) {
|
|
|
5234
5452
|
const held = new Map();
|
|
5235
5453
|
if (!/\[banner/i.test(markdown)) return {text: markdown, held};
|
|
5236
5454
|
const nonce = randomUUID();
|
|
5237
|
-
|
|
5455
|
+
// A [banner] in a code example is an example: it is not held, and not run.
|
|
5456
|
+
const {scrubbed, restore} = scrubCodeRegions(markdown);
|
|
5457
|
+
const text = restore(scrubbed.replace(/\[banner([^\]]*)\]/gi, (_, attrStr) => {
|
|
5238
5458
|
const token = `dmb-${nonce}-${held.size}`;
|
|
5239
|
-
|
|
5459
|
+
// The attributes as written: a code span in one (title="Run `npm test`") goes back in.
|
|
5460
|
+
held.set(token, restore(attrStr));
|
|
5240
5461
|
return `[banner ${token}]`;
|
|
5241
|
-
});
|
|
5462
|
+
}));
|
|
5242
5463
|
return {text, held};
|
|
5243
5464
|
}
|
|
5244
5465
|
|
|
@@ -5261,7 +5482,8 @@ function holdBannerTags(markdown) {
|
|
|
5261
5482
|
* @returns {string}
|
|
5262
5483
|
*/
|
|
5263
5484
|
function processBannerBlocks(markdown, held = null) {
|
|
5264
|
-
|
|
5485
|
+
const {scrubbed, restore} = scrubCodeRegions(markdown);
|
|
5486
|
+
return restore(scrubbed.replace(
|
|
5265
5487
|
/(<p>)?\[banner([^\]]*)\]([\s\S]*?)\[\/banner\](<\/p>)?/gi,
|
|
5266
5488
|
(_, openP, rawAttrStr, rawBody, closeP) => {
|
|
5267
5489
|
// A tag the author wrote carries a held token (holdBannerTags), so its
|
|
@@ -5271,7 +5493,7 @@ function processBannerBlocks(markdown, held = null) {
|
|
|
5271
5493
|
// because the quotes in entry data reach here as entities.
|
|
5272
5494
|
const token = rawAttrStr.trim();
|
|
5273
5495
|
const authored = !!held && held.has(token);
|
|
5274
|
-
const attrStr = authored ? held.get(token) : rawAttrStr;
|
|
5496
|
+
const attrStr = authored ? held.get(token) : restore(rawAttrStr);
|
|
5275
5497
|
const wrapped = authored && !!(openP && closeP);
|
|
5276
5498
|
let body = rawBody;
|
|
5277
5499
|
if (wrapped) {
|
|
@@ -5300,7 +5522,7 @@ function processBannerBlocks(markdown, held = null) {
|
|
|
5300
5522
|
const titleHtml = title
|
|
5301
5523
|
? `<strong class="dm-banner__title">${escapeAttr(title)}</strong>\n `
|
|
5302
5524
|
: '';
|
|
5303
|
-
const bodyHtml = markedBody(body.trim());
|
|
5525
|
+
const bodyHtml = markedBody(restore(body.trim()));
|
|
5304
5526
|
const dismissHtml = dismissible
|
|
5305
5527
|
? `\n <button type="button" class="dm-banner__dismiss" aria-label="Dismiss">×</button>`
|
|
5306
5528
|
: '';
|
|
@@ -5313,7 +5535,7 @@ function processBannerBlocks(markdown, held = null) {
|
|
|
5313
5535
|
`</div>\n${after}`
|
|
5314
5536
|
);
|
|
5315
5537
|
}
|
|
5316
|
-
);
|
|
5538
|
+
));
|
|
5317
5539
|
}
|
|
5318
5540
|
|
|
5319
5541
|
function processSlideoverBlocks(markdown) {
|
|
@@ -5551,8 +5773,12 @@ function processCtaBlocks(markdown) {
|
|
|
5551
5773
|
* @param {string} html
|
|
5552
5774
|
* @returns {string}
|
|
5553
5775
|
*/
|
|
5554
|
-
export function sanitizePageHtml(html) {
|
|
5555
|
-
|
|
5776
|
+
export function sanitizePageHtml(html, {entry = false} = {}) {
|
|
5777
|
+
// The entry profile (entryHtml): content an entry may carry - none of the
|
|
5778
|
+
// site's machinery. No data-* attribute, no component tag, no <style>, and
|
|
5779
|
+
// nothing a plugin added to the lists.
|
|
5780
|
+
const extensions = entry ? {tags: [], attributes: {}} : getSanitizeExtensions();
|
|
5781
|
+
const dmTags = entry ? [] : _dmTagAllowlist;
|
|
5556
5782
|
return sanitizeHtml(html, {
|
|
5557
5783
|
// `style` is intentionally allowed below so per-block custom CSS can
|
|
5558
5784
|
// reach the page. Admins write block templates; same trust model as
|
|
@@ -5572,6 +5798,28 @@ export function sanitizePageHtml(html) {
|
|
|
5572
5798
|
// definition, so the hostname gate has nothing to say about it: the gate
|
|
5573
5799
|
// exists to stop embedding somebody else's site, not your own page.
|
|
5574
5800
|
allowIframeRelativeUrls: true,
|
|
5801
|
+
// No event handler on any tag. The per-tag lists below already leave them
|
|
5802
|
+
// out, but a registered dm-<name> component takes every attribute ('*'),
|
|
5803
|
+
// and a handler on one ran: <dm-counter autofocus onfocus="…">.
|
|
5804
|
+
transformTags: {
|
|
5805
|
+
'*': (tagName, attribs) => {
|
|
5806
|
+
for (const name of Object.keys(attribs)) {
|
|
5807
|
+
if (/^on/i.test(name)) delete attribs[name];
|
|
5808
|
+
// Entry profile: a value on one line. A blank line inside one would end
|
|
5809
|
+
// the HTML block in a later Markdown pass, and what Markdown then wrote
|
|
5810
|
+
// (a link's quotes) would close the attribute and add others.
|
|
5811
|
+
else if (entry) attribs[name] = String(attribs[name]).replace(/\s*[\r\n]+\s*/g, ' ');
|
|
5812
|
+
}
|
|
5813
|
+
return {tagName, attribs};
|
|
5814
|
+
}
|
|
5815
|
+
},
|
|
5816
|
+
// CSS never needs a "<" that could open a tag (buildBlockStyleTag writes it as
|
|
5817
|
+
// an escape). A <style> holding one is markup waiting for a parser that reads
|
|
5818
|
+
// the element another way (<select><style></select><img onerror>), so the
|
|
5819
|
+
// whole element goes. (sanitize-html's textFilter is not run on <style> text,
|
|
5820
|
+
// so it cannot be escaped here instead: an inline <style> with an SVG data:
|
|
5821
|
+
// URI must write its "<" as %3C.)
|
|
5822
|
+
exclusiveFilter: frame => frame.tag === 'style' && /<[a-zA-Z\/!?]/.test(frame.text),
|
|
5575
5823
|
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
|
|
5576
5824
|
'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
5577
5825
|
'form', 'input', 'textarea', 'select', 'option', 'optgroup',
|
|
@@ -5581,11 +5829,11 @@ export function sanitizePageHtml(html) {
|
|
|
5581
5829
|
// <style> tags are emitted by block rendering (buildBlockStyleTag) so
|
|
5582
5830
|
// per-block custom CSS can reach the page. Admin-trust: block authors
|
|
5583
5831
|
// are admins, same security model as site-wide content/custom.css.
|
|
5584
|
-
'style',
|
|
5832
|
+
...(entry ? [] : ['style']),
|
|
5585
5833
|
// dm-<name> custom-element tags - one per registered component. Refreshed
|
|
5586
5834
|
// by refreshComponentTagAllowlist() on startup and after create/delete.
|
|
5587
5835
|
// Component authors are super-admins, same trust model as plugin code.
|
|
5588
|
-
...
|
|
5836
|
+
...dmTags,
|
|
5589
5837
|
...extensions.tags
|
|
5590
5838
|
]),
|
|
5591
5839
|
allowedAttributes: {
|
|
@@ -5594,7 +5842,9 @@ export function sanitizePageHtml(html) {
|
|
|
5594
5842
|
// drag grip) so it isn't announced as an empty item. aria-current marks
|
|
5595
5843
|
// the [menu] item for the page you are on. Both presentational only, no
|
|
5596
5844
|
// script surface - unlike the on* handlers stripped globally.
|
|
5597
|
-
|
|
5845
|
+
// Entry HTML keeps the two data- attributes that only decorate: an icon by
|
|
5846
|
+
// name, and text for a copy button. Nothing that carries a payload or an action.
|
|
5847
|
+
'*': ['class', 'id', 'style', ...(entry ? ['data-icon', 'data-copy'] : ['data-*']), 'aria-hidden', 'aria-current'],
|
|
5598
5848
|
img: ['src', 'alt', 'title', 'width', 'height', 'loading'],
|
|
5599
5849
|
form: ['action', 'method'],
|
|
5600
5850
|
input: ['type', 'name', 'placeholder', 'value', 'required', 'disabled',
|
|
@@ -5605,7 +5855,7 @@ export function sanitizePageHtml(html) {
|
|
|
5605
5855
|
select: ['name', 'required', 'disabled', 'multiple'],
|
|
5606
5856
|
option: ['value', 'selected', 'disabled'],
|
|
5607
5857
|
optgroup: ['label', 'disabled'],
|
|
5608
|
-
button: ['type', 'disabled', 'aria-label', 'data-action', 'data-entry', 'data-confirm'],
|
|
5858
|
+
button: ['type', 'disabled', 'aria-label', ...(entry ? [] : ['data-action', 'data-entry', 'data-confirm'])],
|
|
5609
5859
|
label: ['for'],
|
|
5610
5860
|
fieldset: ['disabled'],
|
|
5611
5861
|
iframe: ['src', 'title', 'width', 'height', 'allow', 'allowfullscreen',
|
|
@@ -5616,8 +5866,8 @@ export function sanitizePageHtml(html) {
|
|
|
5616
5866
|
// Allow any attribute on every registered dm-* tag. Props are
|
|
5617
5867
|
// author-defined and enumerating them at sanitise time has no security
|
|
5618
5868
|
// benefit - custom-element attributes cannot execute JS on their own,
|
|
5619
|
-
// and `on*` handlers
|
|
5620
|
-
...
|
|
5869
|
+
// and `on*` handlers are stripped from every tag by transformTags above.
|
|
5870
|
+
...dmTags.reduce((acc, tag) => { acc[tag] = ['*']; return acc; }, {}),
|
|
5621
5871
|
...extensions.attributes
|
|
5622
5872
|
}
|
|
5623
5873
|
});
|
package/server/services/menus.js
CHANGED
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
PRESET_COLOUR_VARS, PRESET_COLOUR_FALLBACKS, colourToCss, cssClassProblems
|
|
24
24
|
} from '../../public/js/menu-decor.mjs';
|
|
25
25
|
import {fileIn} from './safePath.js';
|
|
26
|
-
import {normaliseLook, lookProblems, itemLookProblems} from '../../public/js/menu-look.mjs';
|
|
27
|
-
import {cleanRichText} from './richText.js';
|
|
26
|
+
import {normaliseLook, lookProblems, itemLookProblems, DESCRIPTION_MARKUP_MAX} from '../../public/js/menu-look.mjs';
|
|
27
|
+
import {cleanRichText, isRichText, renderRichTextPhrasing, richTextLine} from './richText.js';
|
|
28
28
|
|
|
29
29
|
export {normaliseLook};
|
|
30
30
|
|
|
@@ -457,8 +457,13 @@ export async function resolveMenuDecorations(items, opts = {}) {
|
|
|
457
457
|
|
|
458
458
|
async function walk(list) {
|
|
459
459
|
return Promise.all((list || []).map(async (it) => {
|
|
460
|
-
if (!it
|
|
461
|
-
|
|
460
|
+
if (!it) return it;
|
|
461
|
+
if (isStructuralItem(it)) {
|
|
462
|
+
if (!('descriptionHtml' in it)) return it;
|
|
463
|
+
const {descriptionHtml: _forged, ...rest} = it;
|
|
464
|
+
return rest;
|
|
465
|
+
}
|
|
466
|
+
const next = servedDescription({...it});
|
|
462
467
|
if (it.badge && it.badge.countFrom) {
|
|
463
468
|
try {
|
|
464
469
|
const n = await countEntries(it.badge.countFrom);
|
|
@@ -475,6 +480,51 @@ export async function resolveMenuDecorations(items, opts = {}) {
|
|
|
475
480
|
return walk(items);
|
|
476
481
|
}
|
|
477
482
|
|
|
483
|
+
/**
|
|
484
|
+
* An item's card caption (`description`) as the page is given it. The caption
|
|
485
|
+
* is rich text, and menu JSON is hand-editable, so what is stored is not
|
|
486
|
+
* trusted here: a rich caption goes out as `description` (its words, for
|
|
487
|
+
* anything that draws text) plus `descriptionHtml`, cleaned to inline
|
|
488
|
+
* formatting - it is drawn inside the entry's link, so no blocks and no links.
|
|
489
|
+
* A plain caption is left as it is and drawn as text. `descriptionHtml` is
|
|
490
|
+
* never taken from the file: only this function writes it.
|
|
491
|
+
*
|
|
492
|
+
* @param {object} item - a copy, changed and returned
|
|
493
|
+
* @returns {object}
|
|
494
|
+
*/
|
|
495
|
+
function servedDescription(item) {
|
|
496
|
+
delete item.descriptionHtml;
|
|
497
|
+
if (!isRichText(item.description)) return item;
|
|
498
|
+
const html = renderRichTextPhrasing(item.description, {links: false});
|
|
499
|
+
item.description = richTextLine(item.description);
|
|
500
|
+
if (html) item.descriptionHtml = html;
|
|
501
|
+
return item;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* A menu's items as they are stored: each caption cleaned as rich text
|
|
506
|
+
* (richText.js) and any `descriptionHtml` dropped - that key is only ever
|
|
507
|
+
* made on the way out, by resolveMenuDecorations. Everything else is left
|
|
508
|
+
* exactly as sent; validateMenu has already judged it.
|
|
509
|
+
*
|
|
510
|
+
* @param {*} items
|
|
511
|
+
* @returns {Array}
|
|
512
|
+
*/
|
|
513
|
+
export function cleanItemDescriptions(items) {
|
|
514
|
+
if (!Array.isArray(items)) return [];
|
|
515
|
+
return items.map((it) => {
|
|
516
|
+
if (!it || typeof it !== 'object' || Array.isArray(it)) return it;
|
|
517
|
+
const {descriptionHtml: _made, ...next} = it;
|
|
518
|
+
if (typeof next.description === 'string') {
|
|
519
|
+
const cleaned = cleanRichText(next.description, {max: DESCRIPTION_MARKUP_MAX});
|
|
520
|
+
if (cleaned) next.description = cleaned;
|
|
521
|
+
else delete next.description;
|
|
522
|
+
}
|
|
523
|
+
if (Array.isArray(next.items)) next.items = cleanItemDescriptions(next.items);
|
|
524
|
+
return next;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
478
528
|
/**
|
|
479
529
|
* Ensure MENUS_DIR exists. Safe to call repeatedly.
|
|
480
530
|
*
|
|
@@ -634,7 +684,7 @@ export async function createMenu(input) {
|
|
|
634
684
|
...(normaliseMobile(input.mobile) && {mobile: normaliseMobile(input.mobile)}),
|
|
635
685
|
...(normaliseLook(input.look) && {look: normaliseLook(input.look)}),
|
|
636
686
|
...(binding != null && {binding}),
|
|
637
|
-
items:
|
|
687
|
+
items: cleanItemDescriptions(input.items),
|
|
638
688
|
meta: {
|
|
639
689
|
createdAt: now,
|
|
640
690
|
updatedAt: now,
|
|
@@ -708,7 +758,7 @@ export async function updateMenu(slug, input, opts = {}) {
|
|
|
708
758
|
...(normaliseMobile(input.mobile) && {mobile: normaliseMobile(input.mobile)}),
|
|
709
759
|
...(normaliseLook(input.look) && {look: normaliseLook(input.look)}),
|
|
710
760
|
...(binding != null && {binding}),
|
|
711
|
-
items:
|
|
761
|
+
items: cleanItemDescriptions(input.items),
|
|
712
762
|
meta: {
|
|
713
763
|
...existing.meta,
|
|
714
764
|
...(input.meta || {}),
|