@adobe/helix-md2jcr 1.0.6 → 1.0.8

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 CHANGED
@@ -1,3 +1,18 @@
1
+ ## [1.0.8](https://github.com/adobe/helix-md2jcr/compare/v1.0.7...v1.0.8) (2025-02-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **sites-28652:** include model fields property into the generated xml node structure ([#45](https://github.com/adobe/helix-md2jcr/issues/45)) ([7699250](https://github.com/adobe/helix-md2jcr/commit/769925099ccb7edb37544dc5767aec857297ed4a))
7
+ * **sites-28737:** title should use title and not jcr:title ([#47](https://github.com/adobe/helix-md2jcr/issues/47)) ([e843c08](https://github.com/adobe/helix-md2jcr/commit/e843c0876e3a40473e06b40b999977ce6bee3422))
8
+
9
+ ## [1.0.7](https://github.com/adobe/helix-md2jcr/compare/v1.0.6...v1.0.7) (2025-02-03)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **deps:** update external fixes ([#44](https://github.com/adobe/helix-md2jcr/issues/44)) ([61fe813](https://github.com/adobe/helix-md2jcr/commit/61fe8134caba1f43b85264a2692cc478e3e09866))
15
+
1
16
  ## [1.0.6](https://github.com/adobe/helix-md2jcr/compare/v1.0.5...v1.0.6) (2025-02-03)
2
17
 
3
18
 
package/baseline-tests.sh CHANGED
@@ -65,7 +65,7 @@ for MD_FILE in $MD_FILES; do
65
65
  # if VERBOSE is true then echo a new line
66
66
  [ "$VERBOSE" = "true" ] && echo
67
67
 
68
- node "$NODE_SCRIPT" "$MD_FILE" $ARGS
68
+ node "$NODE_SCRIPT" "$MD_FILE" $ARGS 2>/dev/null
69
69
 
70
70
  # Check if the Node.js script executed successfully
71
71
  if [ $? -ne 0 ]; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-md2jcr",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Helix Service that converts markdown to JCR content structure",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  "handlebars": "^4.7.8",
38
38
  "hast-util-is-element": "3.0.0",
39
39
  "hast-util-to-html": "^9.0.3",
40
- "hast-util-to-mdast": "10.1.1",
40
+ "hast-util-to-mdast": "10.1.2",
41
41
  "image-size": "1.2.0",
42
42
  "mdast-util-to-hast": "^13.2.0",
43
43
  "mdast-util-to-string": "^4.0.0",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@adobe/eslint-config-helix": "2.0.8",
58
- "@adobe/helix-mediahandler": "2.5.48",
58
+ "@adobe/helix-mediahandler": "2.5.49",
59
59
  "@commitlint/cli": "^19.6.1",
60
60
  "@commitlint/config-conventional": "^19.6.0",
61
61
  "@semantic-release/changelog": "6.0.3",
@@ -21,13 +21,14 @@
21
21
  * Get the model id from the array of models.
22
22
  * @param {Array<Model>} models The array of models.
23
23
  * @param {string} modelId The model id.
24
- * @return {Model}
24
+ * @return {Model|null} The model or undefined if not found.
25
25
  */
26
26
  function findModelById(models, modelId) {
27
- if (!models || Object.keys(models)?.length === 0) {
28
- throw new Error('No models are provided. Check your model\'s JSON file.');
27
+ if (models && Object.keys(models)?.length > 0) {
28
+ return models.find((model) => model.id === modelId);
29
+ } else {
30
+ return undefined;
29
31
  }
30
- return models.find((model) => model.id === modelId);
31
32
  }
32
33
 
33
34
  /**
@@ -40,7 +41,21 @@ function getField(model, fieldName) {
40
41
  return model.fields.find((field) => field.name === fieldName);
41
42
  }
42
43
 
44
+ /**
45
+ * Return a comma-separated list of fields in the model. If no fields are found,
46
+ * return an empty string.
47
+ * @param model
48
+ * @return {string}
49
+ */
50
+ function getModelFields(model) {
51
+ return model.fields
52
+ .map((f) => f.name)
53
+ .filter((f) => f !== 'classes')
54
+ .join(',');
55
+ }
56
+
43
57
  export {
44
58
  getField,
45
59
  findModelById,
60
+ getModelFields,
46
61
  };
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { find } from 'unist-util-find';
13
13
  import { toString } from 'mdast-util-to-string';
14
- import { findModelById, getField } from '../../domain/Models.js';
14
+ import { findModelById, getField, getModelFields } from '../../domain/Models.js';
15
15
  import { findAll } from '../../utils/mdast.js';
16
16
  import { encodeHTMLEntities, stripNewlines } from '../../utils.js';
17
17
  import link from '../partials/supports/link.js';
@@ -66,6 +66,11 @@ function buildPageMetadata(table, models) {
66
66
  mappedMetadata[mappedKey] = value;
67
67
  });
68
68
 
69
+ if (model) {
70
+ const fields = getModelFields(model);
71
+ mappedMetadata.modelFields = `[${fields}]`;
72
+ }
73
+
69
74
  return mappedMetadata;
70
75
  }
71
76
 
@@ -13,13 +13,24 @@ import Handlebars from 'handlebars';
13
13
  import { find } from 'unist-util-find';
14
14
  import { toString } from 'mdast-util-to-string';
15
15
  import { findAll } from '../../utils/mdast.js';
16
+ import { findModelById, getModelFields } from '../../domain/Models.js';
16
17
 
17
18
  function sectionHelper(index, children, options) {
19
+ const {
20
+ models,
21
+ } = options.data.root;
22
+
18
23
  const attributes = {
19
24
  'sling:resourceType': 'core/franklin/components/section/v1/section',
20
25
  'jcr:primaryType': 'nt:unstructured',
21
26
  };
22
27
 
28
+ const model = findModelById(models, 'section-metadata');
29
+ if (model) {
30
+ const fields = getModelFields(model);
31
+ attributes.modelFields = `[${fields}]`;
32
+ }
33
+
23
34
  const uniqueName = Handlebars.helpers.nameHelper.call(this, 'section');
24
35
 
25
36
  // find the table that has a gtHeader that has a header value that contains 'section-metadata'
@@ -18,7 +18,7 @@ import { toHast } from 'mdast-util-to-hast';
18
18
  import { toHtml } from 'hast-util-to-html';
19
19
  import { getComponentById, getComponentByTitle, getModelId } from '../../domain/Definitions.js';
20
20
  import {
21
- findModelById, getField,
21
+ findModelById, getField, getModelFields,
22
22
  } from '../../domain/Models.js';
23
23
  import { findAll } from '../../utils/mdast.js';
24
24
  import link from './supports/link.js';
@@ -371,8 +371,13 @@ function getBlockItems(mdast, modelHelper, definitions, allowedComponents) {
371
371
  const fieldGroup = modelHelper.getModelFieldGroup(componentId);
372
372
  if (fieldGroup) {
373
373
  const component = getComponentById(definitions, componentId);
374
- const properties = { ...component.defaultFields };
374
+ const properties = {
375
+ ...component.defaultFields,
376
+ modelFields: `[${getModelFields(fieldGroup.model)}]`,
377
+ };
378
+
375
379
  extractProperties(row, fieldGroup.model, 'blockItem', component, fieldGroup.fields, properties);
380
+
376
381
  items.push(`<item_${items.length} sling:resourceType="core/franklin/components/block/v1/block/item" name="${fieldGroup.model.id}" ${Object.entries(properties).map(([k, v]) => `${k}="${v}"`).join(' ')}></item_${items.length}>`);
377
382
  }
378
383
  } else {
@@ -442,6 +447,10 @@ function gridTablePartial(context) {
442
447
  ...blockHeaderProperties,
443
448
  };
444
449
 
450
+ if (model) {
451
+ properties.modelFields = `[${getModelFields(model)}]`;
452
+ }
453
+
445
454
  let blockProperties = '';
446
455
  let fieldGroup;
447
456
 
@@ -47,7 +47,7 @@ function heading(context) {
47
47
 
48
48
  title = Handlebars.Utils.escapeExpression(context.children.map(parseInlineElements).join(''));
49
49
 
50
- return `<title${uniqueName} sling:resourceType="core/franklin/components/title/v1/title" jcr:primaryType="nt:unstructured" jcr:title="${title}" type="h${depth}"/>\n`;
50
+ return `<title${uniqueName} sling:resourceType="core/franklin/components/title/v1/title" jcr:primaryType="nt:unstructured" title="${title}" type="h${depth}"/>\n`;
51
51
  }
52
52
 
53
53
  export default heading;