@@ -22,10 +22,10 @@ import {
22
22
traverseAndUpdateAssetReferences ,
23
23
} from './packaging.utils.js' ;
24
24
import { saveFile } from '../shared/filesystem.js' ;
25
- import { sanitizeImageMappings } from './image -mapping.js' ;
25
+ import { sanitizeAssetMappings } from './asset -mapping.js' ;
26
26
27
27
let jcrPages = [ ] ;
28
- const IMAGE_MAPPING_FILE = 'image -mappings.json' ;
28
+ const ASSET_MAPPING_FILE = 'asset -mappings.json' ;
29
29
30
30
const init = ( ) => {
31
31
jcrPages = [ ] ;
@@ -41,10 +41,10 @@ const addPage = async (page, dir, prefix, zip) => {
41
41
* @param xml - The xml content of the page
42
42
* @param pageUrl - The url of the site page
43
43
* @param assetFolderName - The name of the asset folder(s) in AEM
44
- * @param imageMappings - A map to store the image urls and their corresponding jcr paths
44
+ * @param assetMappings - A map to store the asset urls and their corresponding jcr paths
45
45
* @returns {Promise<*|string> } - The updated xml content
46
46
*/
47
- export const updateAssetReferences = async ( xml , pageUrl , assetFolderName , imageMappings ) => {
47
+ export const updateAssetReferences = async ( xml , pageUrl , assetFolderName , assetMappings ) => {
48
48
let doc ;
49
49
try {
50
50
doc = getParsedXml ( xml ) ;
@@ -55,14 +55,14 @@ export const updateAssetReferences = async (xml, pageUrl, assetFolderName, image
55
55
}
56
56
57
57
// Start traversal from the document root and update the asset references
58
- traverseAndUpdateAssetReferences ( doc . documentElement , pageUrl , assetFolderName , imageMappings ) ;
58
+ traverseAndUpdateAssetReferences ( doc . documentElement , pageUrl , assetFolderName , assetMappings ) ;
59
59
60
60
const serializer = new XMLSerializer ( ) ;
61
61
return serializer . serializeToString ( doc ) ;
62
62
} ;
63
63
64
64
// eslint-disable-next-line max-len
65
- export const getJcrPages = async ( pages , siteFolderName , assetFolderName , imageMappings ) => Promise . all ( pages . map ( async ( page ) => ( {
65
+ export const getJcrPages = async ( pages , siteFolderName , assetFolderName , assetMappings ) => Promise . all ( pages . map ( async ( page ) => ( {
66
66
path : page . path ,
67
67
sourceXml : page . data ,
68
68
pageProperties : getPageProperties ( page . data ) ,
@@ -71,7 +71,7 @@ export const getJcrPages = async (pages, siteFolderName, assetFolderName, imageM
71
71
page . data ,
72
72
page . url ,
73
73
assetFolderName ,
74
- imageMappings ,
74
+ assetMappings ,
75
75
) ,
76
76
jcrPath : getJcrPagePath ( page . path , siteFolderName ) ,
77
77
contentXmlPath : `jcr_root${ getJcrPagePath ( page . path , siteFolderName ) } /.content.xml` ,
@@ -121,34 +121,34 @@ const getEmptyAncestorPages = (pages) => {
121
121
} ;
122
122
123
123
/**
124
- * Sanitizes (deleting entries without jcr path mapping) and saves the image mappings to a file.
125
- * @param {Array<string> } imageUrls - An array of image urls that were found in the markdown.
124
+ * Sanitizes (deleting entries without jcr path mapping) and saves the asset mappings to a file.
125
+ * @param {* } assetMappings - The asset mappings
126
126
* @param {* } outputDirectory - The directory handle
127
127
*/
128
- const sanitizeAndSaveImageMappings = async ( imageMappings , outputDirectory ) => {
129
- // Sanitize the image mappings
130
- const sanitizedMappings = sanitizeImageMappings ( imageMappings ) ;
128
+ const sanitizeAndSaveAssetMappings = async ( assetMappings , outputDirectory ) => {
129
+ // Sanitize the asset mappings
130
+ const sanitizedMappings = sanitizeAssetMappings ( assetMappings ) ;
131
131
132
132
// Convert Map to a plain object
133
133
const obj = Object . fromEntries ( sanitizedMappings ) ;
134
134
135
- // Save the updated image mapping content into a file
136
- await saveFile ( outputDirectory , IMAGE_MAPPING_FILE , JSON . stringify ( obj , null , 2 ) ) ;
135
+ // Save the updated asset mapping content into a file
136
+ await saveFile ( outputDirectory , ASSET_MAPPING_FILE , JSON . stringify ( obj , null , 2 ) ) ;
137
137
} ;
138
138
139
139
/**
140
140
* Creates a JCR content package from a directory containing pages.
141
141
* @param {* } outputDirectory - The directory handle
142
142
* @param {Array } pages - An array of pages
143
- * @param {Array<string> } imageUrls - An array of image urls that were found in the markdown.
143
+ * @param {Array<string> } assetUrls - An array of asset urls that were found in the markdown.
144
144
* @param {string } siteFolderName - The name of the site folder(s) in AEM
145
145
* @param {string } assetFolderName - The name of the asset folder(s) in AEM
146
146
* @returns {Promise } The file handle for the generated package.
147
147
*/
148
148
export const createJcrPackage = async (
149
149
outputDirectory ,
150
150
pages ,
151
- imageUrls ,
151
+ assetUrls ,
152
152
siteFolderName ,
153
153
assetFolderName ,
154
154
) => {
@@ -162,10 +162,10 @@ export const createJcrPackage = async (
162
162
const prefix = 'jcr' ;
163
163
164
164
// create a map using the provided asset urls as keys (values will be populated later)
165
- const imageMappings = new Map ( imageUrls . map ( ( url ) => [ url , '' ] ) ) ;
165
+ const assetMappings = new Map ( assetUrls . map ( ( url ) => [ url , '' ] ) ) ;
166
166
167
167
// add the pages
168
- jcrPages = await getJcrPages ( pages , siteFolderName , assetFolderName , imageMappings ) ;
168
+ jcrPages = await getJcrPages ( pages , siteFolderName , assetFolderName , assetMappings ) ;
169
169
for ( let i = 0 ; i < jcrPages . length ; i += 1 ) {
170
170
const page = jcrPages [ i ] ;
171
171
// eslint-disable-next-line no-await-in-loop
@@ -192,5 +192,5 @@ export const createJcrPackage = async (
192
192
await zip . generateAsync ( { type : outputType } )
193
193
. then ( async ( blob ) => saveFile ( outputDirectory , `${ packageName } .zip` , blob ) ) ;
194
194
195
- await sanitizeAndSaveImageMappings ( imageMappings , outputDirectory ) ;
195
+ await sanitizeAndSaveAssetMappings ( assetMappings , outputDirectory ) ;
196
196
} ;
0 commit comments