@adobe/helix-importer 3.3.7 → 3.4.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 +14 -0
- package/package.json +6 -6
- package/src/importer/defaults/rules/createMetadata.js +1 -79
- package/src/utils/Blocks.js +100 -30
- package/src/utils/DOMUtils.js +1 -3
- package/test/utils/Blocks.spec.js +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [3.4.0](https://github.com/adobe/helix-importer/compare/v3.3.8...v3.4.0) (2024-05-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* simplify block creation [#350](https://github.com/adobe/helix-importer/issues/350) ([#351](https://github.com/adobe/helix-importer/issues/351)) ([b766954](https://github.com/adobe/helix-importer/commit/b766954210d30bd9385ea7a785dee006efcd625a))
|
|
7
|
+
|
|
8
|
+
## [3.3.8](https://github.com/adobe/helix-importer/compare/v3.3.7...v3.3.8) (2024-04-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update adobe fixes ([#344](https://github.com/adobe/helix-importer/issues/344)) ([9495d94](https://github.com/adobe/helix-importer/commit/9495d949131a13e963517195f94e89f4f193090a))
|
|
14
|
+
|
|
1
15
|
## [3.3.7](https://github.com/adobe/helix-importer/compare/v3.3.6...v3.3.7) (2024-04-23)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-importer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Helix Importer tool: create md / docx from html",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@adobe/eslint-config-helix": "2.0.6",
|
|
30
30
|
"@adobe/helix-docx2md": "1.6.0",
|
|
31
|
-
"@adobe/helix-mediahandler": "2.5.
|
|
31
|
+
"@adobe/helix-mediahandler": "2.5.4",
|
|
32
32
|
"@esm-bundle/chai": "4.3.4-fix.0",
|
|
33
33
|
"@semantic-release/changelog": "6.0.3",
|
|
34
34
|
"@semantic-release/exec": "6.0.3",
|
|
35
35
|
"@semantic-release/git": "10.0.1",
|
|
36
|
-
"@web/test-runner": "0.18.
|
|
36
|
+
"@web/test-runner": "0.18.2",
|
|
37
37
|
"@web/test-runner-commands": "0.9.0",
|
|
38
38
|
"@web/test-runner-mocha": "0.9.0",
|
|
39
39
|
"c8": "9.1.0",
|
|
40
|
-
"chai": "5.1.
|
|
40
|
+
"chai": "5.1.1",
|
|
41
41
|
"dirname-filename-esm": "1.1.1",
|
|
42
42
|
"eslint": "8.57.0",
|
|
43
43
|
"husky": "9.0.11",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"mocha-multi-reporters": "1.5.1",
|
|
48
48
|
"mock-fs": "5.2.0",
|
|
49
49
|
"remark-parse": "11.0.0",
|
|
50
|
-
"semantic-release": "23.
|
|
50
|
+
"semantic-release": "23.1.1",
|
|
51
51
|
"unist-util-inspect": "8.0.0"
|
|
52
52
|
},
|
|
53
53
|
"license": "Apache-2.0",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@adobe/helix-markdown-support": "7.1.2",
|
|
56
|
-
"@adobe/helix-md2docx": "2.1.
|
|
56
|
+
"@adobe/helix-md2docx": "2.1.56",
|
|
57
57
|
"@adobe/mdast-util-gridtables": "4.0.4",
|
|
58
58
|
"@adobe/remark-gridtables": "3.0.4",
|
|
59
59
|
"form-data": "4.0.0",
|
|
@@ -12,86 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
import Blocks from '../../../utils/Blocks.js';
|
|
14
14
|
|
|
15
|
-
function getMetadata(name, document) {
|
|
16
|
-
const attr = name && name.includes(':') ? 'property' : 'name';
|
|
17
|
-
const meta = [...document.head.querySelectorAll(`meta[${attr}="${name}"]`)]
|
|
18
|
-
.map((m) => m.content)
|
|
19
|
-
.join(', ');
|
|
20
|
-
return meta || '';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
15
|
export default function createMetadata(main, document) {
|
|
24
|
-
const meta =
|
|
25
|
-
|
|
26
|
-
const title = document.querySelector('title');
|
|
27
|
-
if (title) {
|
|
28
|
-
meta.Title = title.textContent.replace(/[\n\t]/gm, '');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const desc = getMetadata('description', document);
|
|
32
|
-
if (desc) {
|
|
33
|
-
meta.Description = desc;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const img = getMetadata('og:image', document);
|
|
37
|
-
if (img) {
|
|
38
|
-
const el = document.createElement('img');
|
|
39
|
-
el.src = img;
|
|
40
|
-
meta.Image = el;
|
|
41
|
-
|
|
42
|
-
const imgAlt = getMetadata('og:image:alt', document);
|
|
43
|
-
if (imgAlt) {
|
|
44
|
-
el.alt = imgAlt;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const ogtitle = getMetadata('og:title', document);
|
|
49
|
-
if (ogtitle && ogtitle !== meta.Title) {
|
|
50
|
-
if (meta.Title) {
|
|
51
|
-
meta['og:title'] = ogtitle;
|
|
52
|
-
} else {
|
|
53
|
-
meta.Title = ogtitle;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ogdesc = getMetadata('og:description', document);
|
|
58
|
-
if (ogdesc && ogdesc !== meta.Description) {
|
|
59
|
-
if (meta.Description) {
|
|
60
|
-
meta['og:description'] = ogdesc;
|
|
61
|
-
} else {
|
|
62
|
-
meta.Description = ogdesc;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const ttitle = getMetadata('twitter:title', document);
|
|
67
|
-
if (ttitle && ttitle !== meta.Title) {
|
|
68
|
-
if (meta.Title) {
|
|
69
|
-
meta['twitter:title'] = ttitle;
|
|
70
|
-
} else {
|
|
71
|
-
meta.Title = ttitle;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const tdesc = getMetadata('twitter:description', document);
|
|
76
|
-
if (tdesc && tdesc !== meta.Description) {
|
|
77
|
-
if (meta.Description) {
|
|
78
|
-
meta['twitter:description'] = tdesc;
|
|
79
|
-
} else {
|
|
80
|
-
meta.Description = tdesc;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const timg = getMetadata('twitter:image', document);
|
|
85
|
-
if (timg && timg !== img) {
|
|
86
|
-
const el = document.createElement('img');
|
|
87
|
-
el.src = timg;
|
|
88
|
-
meta['twitter:image'] = el;
|
|
89
|
-
|
|
90
|
-
const imgAlt = getMetadata('twitter:image:alt', document);
|
|
91
|
-
if (imgAlt) {
|
|
92
|
-
el.alt = imgAlt;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
16
|
+
const meta = Blocks.getMetadata(document);
|
|
95
17
|
|
|
96
18
|
if (Object.keys(meta).length > 0) {
|
|
97
19
|
const block = Blocks.getMetadataBlock(document, meta);
|
package/src/utils/Blocks.js
CHANGED
|
@@ -11,47 +11,117 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import DOMUtils from './DOMUtils.js';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
function getDocumentMetadata(name, document) {
|
|
15
|
+
const attr = name && name.includes(':') ? 'property' : 'name';
|
|
16
|
+
const meta = [...document.head.querySelectorAll(`meta[${attr}="${name}"]`)]
|
|
17
|
+
.map((m) => m.content)
|
|
18
|
+
.join(', ');
|
|
19
|
+
return meta || '';
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
export default class Blocks {
|
|
17
|
-
static
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const hCell = document.createElement('th');
|
|
24
|
-
row.append(hCell);
|
|
25
|
-
|
|
26
|
-
hCell.innerHTML = 'Metadata';
|
|
27
|
-
hCell.setAttribute('colspan', DEFAULT_COLSPAN);
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
|
30
|
-
for (const key in metadata) {
|
|
31
|
-
row = document.createElement('tr');
|
|
32
|
-
table.append(row);
|
|
33
|
-
const keyCell = document.createElement('td');
|
|
34
|
-
row.append(keyCell);
|
|
35
|
-
keyCell.textContent = key;
|
|
36
|
-
const valueCell = document.createElement('td');
|
|
37
|
-
row.append(valueCell);
|
|
38
|
-
const value = metadata[key];
|
|
39
|
-
if (value) {
|
|
23
|
+
static createBlock(document, { name, variants = [], cells: data }) {
|
|
24
|
+
const headerRow = variants.length ? [`${Blocks.computeBlockName(name)} (${variants.join(', ')})`] : [Blocks.computeBlockName(name)];
|
|
25
|
+
let blockRows = data;
|
|
26
|
+
if (!Array.isArray(data)) {
|
|
27
|
+
blockRows = Object.entries(data).map(([key, value]) => {
|
|
28
|
+
let colItems = [];
|
|
40
29
|
if (Array.isArray(value)) {
|
|
41
|
-
value.
|
|
30
|
+
colItems = value.map((v) => {
|
|
42
31
|
const p = document.createElement('p');
|
|
43
32
|
p.innerHTML = v;
|
|
44
|
-
|
|
33
|
+
return p;
|
|
45
34
|
});
|
|
46
|
-
} else if (typeof value === 'string') {
|
|
47
|
-
valueCell.textContent = value;
|
|
48
35
|
} else {
|
|
49
|
-
|
|
36
|
+
colItems = [value];
|
|
50
37
|
}
|
|
38
|
+
return [key, colItems];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return DOMUtils.createTable([headerRow, ...blockRows], document);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static getMetadataBlock(document, metadata) {
|
|
45
|
+
return Blocks.createBlock(document, {
|
|
46
|
+
name: 'Metadata',
|
|
47
|
+
cells: metadata,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static getMetadata(document) {
|
|
52
|
+
const meta = {};
|
|
53
|
+
|
|
54
|
+
const title = document.querySelector('title');
|
|
55
|
+
if (title) {
|
|
56
|
+
meta.Title = title.textContent.replace(/[\n\t]/gm, '');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const desc = getDocumentMetadata('description', document);
|
|
60
|
+
if (desc) {
|
|
61
|
+
meta.Description = desc;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const img = getDocumentMetadata('og:image', document);
|
|
65
|
+
if (img) {
|
|
66
|
+
const el = document.createElement('img');
|
|
67
|
+
el.src = img;
|
|
68
|
+
meta.Image = el;
|
|
69
|
+
|
|
70
|
+
const imgAlt = getDocumentMetadata('og:image:alt', document);
|
|
71
|
+
if (imgAlt) {
|
|
72
|
+
el.alt = imgAlt;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const ogtitle = getDocumentMetadata('og:title', document);
|
|
77
|
+
if (ogtitle && ogtitle !== meta.Title) {
|
|
78
|
+
if (meta.Title) {
|
|
79
|
+
meta['og:title'] = ogtitle;
|
|
80
|
+
} else {
|
|
81
|
+
meta.Title = ogtitle;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const ogdesc = getDocumentMetadata('og:description', document);
|
|
86
|
+
if (ogdesc && ogdesc !== meta.Description) {
|
|
87
|
+
if (meta.Description) {
|
|
88
|
+
meta['og:description'] = ogdesc;
|
|
89
|
+
} else {
|
|
90
|
+
meta.Description = ogdesc;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const ttitle = getDocumentMetadata('twitter:title', document);
|
|
95
|
+
if (ttitle && ttitle !== meta.Title) {
|
|
96
|
+
if (meta.Title) {
|
|
97
|
+
meta['twitter:title'] = ttitle;
|
|
98
|
+
} else {
|
|
99
|
+
meta.Title = ttitle;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const tdesc = getDocumentMetadata('twitter:description', document);
|
|
104
|
+
if (tdesc && tdesc !== meta.Description) {
|
|
105
|
+
if (meta.Description) {
|
|
106
|
+
meta['twitter:description'] = tdesc;
|
|
107
|
+
} else {
|
|
108
|
+
meta.Description = tdesc;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const timg = getDocumentMetadata('twitter:image', document);
|
|
113
|
+
if (timg && timg !== img) {
|
|
114
|
+
const el = document.createElement('img');
|
|
115
|
+
el.src = timg;
|
|
116
|
+
meta['twitter:image'] = el;
|
|
117
|
+
|
|
118
|
+
const imgAlt = getDocumentMetadata('twitter:image:alt', document);
|
|
119
|
+
if (imgAlt) {
|
|
120
|
+
el.alt = imgAlt;
|
|
51
121
|
}
|
|
52
122
|
}
|
|
53
123
|
|
|
54
|
-
return
|
|
124
|
+
return meta;
|
|
55
125
|
}
|
|
56
126
|
|
|
57
127
|
static computeBlockName(str) {
|
package/src/utils/DOMUtils.js
CHANGED
|
@@ -140,3 +140,34 @@ describe('Blocks#getMetadataBlock tests', () => {
|
|
|
140
140
|
test({ title: 'Some title', Tags: ['Creative', 'Experience Cloud', 'Photography'] }, '<table><tr><th colspan="2">Metadata</th></tr><tr><td>title</td><td>Some title</td></tr><tr><td>Tags</td><td><p>Creative</p><p>Experience Cloud</p><p>Photography</p></td></tr></table>');
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
|
+
|
|
144
|
+
describe('Blocks#createBlock tests', () => {
|
|
145
|
+
const test = (name, variants = [], cells = [], expected = '') => {
|
|
146
|
+
const { document } = (new JSDOM()).window;
|
|
147
|
+
const table = Blocks.createBlock(document, { name, variants, cells });
|
|
148
|
+
strictEqual(trim(table.outerHTML), trim(expected));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
it('createBlock empty block', () => {
|
|
152
|
+
test('test block', [], [], '<table><tr><th>Test Block</th></tr></table>');
|
|
153
|
+
test('Test Block', [], [], '<table><tr><th>Test Block</th></tr></table>');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('createBlock with variants', () => {
|
|
157
|
+
test('test block', ['variant-1'], [], '<table><tr><th>Test Block (variant-1)</th></tr></table>');
|
|
158
|
+
test('test block', ['variant-1', 'variant-2'], [], '<table><tr><th>Test Block (variant-1, variant-2)</th></tr></table>');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('createBlock block config', () => {
|
|
162
|
+
test('Test Block', [], { title: 'Some title' }, '<table><tr><th colspan="2">Test Block</th></tr><tr><td>title</td><td>Some title</td></tr></table>');
|
|
163
|
+
test('Test Block', [], { Author: 'Name of the author', 'Creation Date': '2022/01/01' }, '<table><tr><th colspan="2">Test Block</th></tr><tr><td>Author</td><td>Name of the author</td></tr><tr><td>Creation Date</td><td>2022/01/01</td></tr></table>');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('createBlock cell array', () => {
|
|
167
|
+
const cells = [
|
|
168
|
+
['Row 1 - Col 1', 'Row 1 - Col 2'],
|
|
169
|
+
['Row 2 - Col 1', 'Row 2 - Col 2'],
|
|
170
|
+
];
|
|
171
|
+
test('Test Block', [], cells, '<table><tr><th colspan="2">Test Block</th></tr><tr><td>Row 1 - Col 1</td><td>Row 1 - Col 2</td></tr><tr><td>Row 2 - Col 1</td><td>Row 2 - Col 2</td></tr></table>');
|
|
172
|
+
});
|
|
173
|
+
});
|