Skip to content

Commit

Permalink
Merge pull request #992 from contentstack/fix/cs-38735
Browse files Browse the repository at this point in the history
fix for html rte asset reference
  • Loading branch information
abhinav-from-contentstack authored Aug 22, 2023
2 parents bc2bb2e + 009b524 commit 0f1e452
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.8.0",
"version": "1.8.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
15 changes: 14 additions & 1 deletion packages/contentstack-import/src/utils/asset-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export const lookupAssets = function (
) {
parent.push(schema[i].uid);
findFileUrls(schema[i], entryToFind, assetUrls);
if (schema[i].field_metadata.rich_text_type) {
findAssetIdsFromHtmlRte(entryToFind, schema[i]);
}
parent.pop();
}
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
Expand Down Expand Up @@ -145,6 +148,15 @@ export const lookupAssets = function (
});
}

function findAssetIdsFromHtmlRte(entryObj: any, ctSchema: any) {
const regex = /<img asset_uid=\\"([^"]+)\\"/g;
let match;
const entry = JSON.stringify(entryObj);
while ((match = regex.exec(entry)) !== null) {
assetUids.push(match[1]);
}
}

function findAssetIdsFromJsonRte(entryObj: any, ctSchema: any) {
for (const element of ctSchema) {
switch (element.data_type) {
Expand Down Expand Up @@ -350,7 +362,8 @@ function findFileUrls(schema: any, _entry: any, assetUrls: any) {
);
while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
if (markdownMatch && typeof markdownMatch[0] === 'string') {
assetUrls.push(markdownMatch[0]);
let assetUrl = markdownMatch[0].replace(/\\/g, '');
assetUrls.push(assetUrl);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@contentstack/cli-cm-clone": "~1.4.15",
"@contentstack/cli-cm-export": "~1.8.0",
"@contentstack/cli-cm-export-to-csv": "~1.3.12",
"@contentstack/cli-cm-import": "~1.8.0",
"@contentstack/cli-cm-import": "~1.8.1",
"@contentstack/cli-cm-migrate-rte": "~1.4.10",
"@contentstack/cli-cm-seed": "~1.4.14",
"@contentstack/cli-command": "~1.2.11",
Expand Down

0 comments on commit 0f1e452

Please sign in to comment.