@adobe/helix-html-pipeline 1.0.4 → 1.0.5
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 +7 -0
- package/package.json +1 -1
- package/src/html-pipe.js +2 -0
- package/src/steps/unwrap-sole-images.js +38 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.0.5](https://github.com/adobe/helix-html-pipeline/compare/v1.0.4...v1.0.5) (2022-03-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* re-add lost image unwrapper ([#10](https://github.com/adobe/helix-html-pipeline/issues/10)) ([0f2b66e](https://github.com/adobe/helix-html-pipeline/commit/0f2b66eed2157717d0edc321fbd3430d4ce4b42c))
|
|
7
|
+
|
|
1
8
|
## [1.0.4](https://github.com/adobe/helix-html-pipeline/compare/v1.0.3...v1.0.4) (2022-03-08)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/html-pipe.js
CHANGED
|
@@ -30,6 +30,7 @@ import rewriteIcons from './steps/rewrite-icons.js';
|
|
|
30
30
|
import setXSurrogateKeyHeader from './steps/set-x-surrogate-key-header.js';
|
|
31
31
|
import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
|
|
32
32
|
import splitSections from './steps/split-sections.js';
|
|
33
|
+
import unwrapSoleImages from './steps/unwrap-sole-images.js';
|
|
33
34
|
import tohtml from './steps/stringify-response.js';
|
|
34
35
|
import { PipelineStatusError } from './PipelineStatusError.js';
|
|
35
36
|
import { PipelineResponse } from './PipelineResponse.js';
|
|
@@ -84,6 +85,7 @@ export async function htmlPipe(state, req) {
|
|
|
84
85
|
await parseMarkdown(state);
|
|
85
86
|
await splitSections(state);
|
|
86
87
|
await getMetadata(state); // this one extracts the metadata from the mdast
|
|
88
|
+
await unwrapSoleImages(state);
|
|
87
89
|
await html(state);
|
|
88
90
|
await rewriteBlobImages(state);
|
|
89
91
|
await rewriteIcons(state);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { map } from 'unist-util-map';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Unwraps hero images to avoid the unnecessary paragraph.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} request The content request
|
|
18
|
+
*/
|
|
19
|
+
export default function unwrap({ content }) {
|
|
20
|
+
let sections = content.mdast.children.filter((node) => node.type === 'section');
|
|
21
|
+
if (!sections.length) {
|
|
22
|
+
sections = [content.mdast];
|
|
23
|
+
}
|
|
24
|
+
sections.forEach((section) => {
|
|
25
|
+
map(section, (node, index, parent) => {
|
|
26
|
+
if (node.type === 'paragraph' // If we have a paragraph
|
|
27
|
+
&& (parent.type === 'root' // … in the document root
|
|
28
|
+
|| parent.type === 'section') // … or in a section
|
|
29
|
+
&& parent.meta.types.includes('has-only-image') // … that only has images
|
|
30
|
+
&& parent.meta.types.includes('nb-image-1')) { // … and actually only 1 of them
|
|
31
|
+
// … then consider it a hero image, and unwrap from the paragraph
|
|
32
|
+
const position = parent.children.indexOf(node);
|
|
33
|
+
const [img] = parent.children[position].children;
|
|
34
|
+
parent.children[position] = img;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|