Skip to content

Commit bdfd128

Browse files
authored
fix(@W-17943542): fix content path for inline media file inside nested folders (#1518)
* feat(@W-17728287): introducing lwc content type in site metadata * fix(@W-17943542): fix content path for inline media file inside nested folders * fix(@W-17943542): add digitalexperiences index check * fix(@W-17943542): review comments
1 parent 17b2db8 commit bdfd128

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

src/resolve/adapters/digitalExperienceSourceAdapter.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
7575
const pathToContent = dirname(path);
7676
const parts = pathToContent.split(sep);
7777
/* Handle mobile or tablet variants.Eg- digitalExperiences/site/lwr11/sfdc_cms__view/home/mobile/mobile.json
78-
Go back to one level in that case
79-
Bundle hierarchy baseType/spaceApiName/contentType/contentApiName/variantFolders/file */
78+
or inline media files where files can be in any subdiretory. Eg - digitalExperiences/site/lwr11/sfdc_cms__lwc/localComp/folder1/foler1_1/localCompHelper.html
79+
from the digitalExperience folder go till we find the ContentApiName folder
80+
*/
8081
const digitalExperiencesIndex = parts.indexOf('digitalExperiences');
8182
if (digitalExperiencesIndex > -1) {
82-
const depth = parts.length - digitalExperiencesIndex - 1;
83-
if (depth === digitalExperienceBundleWithVariantsDepth) {
84-
parts.pop();
83+
const digitalExperiencesLength = digitalExperiencesIndex + 1;
84+
const contentFolderLength = digitalExperiencesLength + contentParts.length;
85+
if (parts.length > contentFolderLength) {
86+
parts.length = contentFolderLength;
8587
return parts.join(sep);
8688
}
8789
}
@@ -164,6 +166,5 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
164166
* @returns name of type/apiName format
165167
*/
166168
const calculateNameFromPath = (contentPath: string): string => `${parentName(contentPath)}/${baseName(contentPath)}`;
167-
168-
// Bundle hierarchy baseType/spaceApiName/contentType/contentApiName/variantFolders/file
169-
const digitalExperienceBundleWithVariantsDepth = 5;
169+
const digitalExperienceStructure = join('BaseType', 'SpaceApiName', 'ContentType', 'ContentApiName');
170+
const contentParts = digitalExperienceStructure.split(sep);

test/resolve/adapters/digitalExperienceSourceAdapter.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ describe('DigitalExperienceSourceAdapter', () => {
3535
const LWC_META_FILE = join(LWC_PATH, DE_METAFILE);
3636
const LWC_CONTENT_FILE = join(LWC_PATH, 'content.json');
3737
const LWC_JS_META_XML_FILE = join(LWC_PATH, 'localComp.js-meta.xml');
38+
const LWC_JS_FILE = join(LWC_PATH, 'localComp.js');
39+
const LWC_HTML_FILE = join(LWC_PATH, 'localComp.html');
40+
const LWC_CSS_FILE = join(LWC_PATH, 'localComp.css');
41+
const LWC_EDITOR_JSON_FILE = join(LWC_PATH, 'editor.json');
42+
const LWC_SVG_FILE = join(LWC_PATH, 'localComp.svg');
43+
const LWC_NESTED_FOLDERS_HTML_FILE = join(LWC_PATH, 'folder1', 'folder1_1', 'folder1_1_1', 'compHelper.html');
3844

3945
const registryAccess = new RegistryAccess();
4046
const forceIgnore = new ForceIgnore();
@@ -48,6 +54,12 @@ describe('DigitalExperienceSourceAdapter', () => {
4854
LWC_META_FILE,
4955
LWC_CONTENT_FILE,
5056
LWC_JS_META_XML_FILE,
57+
LWC_JS_FILE,
58+
LWC_HTML_FILE,
59+
LWC_CSS_FILE,
60+
LWC_EDITOR_JSON_FILE,
61+
LWC_SVG_FILE,
62+
LWC_NESTED_FOLDERS_HTML_FILE,
5163
]);
5264

5365
const bundleAdapter = new DigitalExperienceSourceAdapter(
@@ -154,10 +166,21 @@ describe('DigitalExperienceSourceAdapter', () => {
154166
forceIgnore
155167
);
156168

157-
it('should return a SourceComponent for content json and .js-meta.xml', () => {
158-
expect(digitalExperienceAdapter.getComponent(LWC_CONTENT_FILE)).to.deep.equal(component);
159-
expect(digitalExperienceAdapter.getComponent(LWC_META_FILE)).to.deep.equal(component);
160-
expect(digitalExperienceAdapter.getComponent(LWC_JS_META_XML_FILE)).to.deep.equal(component);
169+
it('should return a SourceComponent for files in inline media content', () => {
170+
const files: string[] = [
171+
LWC_CONTENT_FILE,
172+
LWC_META_FILE,
173+
LWC_JS_META_XML_FILE,
174+
LWC_JS_FILE,
175+
LWC_HTML_FILE,
176+
LWC_CSS_FILE,
177+
LWC_EDITOR_JSON_FILE,
178+
LWC_SVG_FILE,
179+
LWC_NESTED_FOLDERS_HTML_FILE,
180+
];
181+
files.forEach((file) => {
182+
expect(digitalExperienceAdapter.getComponent(file)).to.deep.equal(component);
183+
});
161184
});
162185
});
163186
});

0 commit comments

Comments
 (0)