-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sites-29416)!: Add support for importing non-image assets #7
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fd5dc4d
fix: SITES-29316 Asset reference paths should be lowercased
ManasMaji 94da562
fix: SITES-29316 Asset reference paths should be lowercased
ManasMaji 97bfd06
fix: SITES-29316 Asset reference paths should be lowercased
ManasMaji 95cb751
fix: SITES-29316 Asset reference paths should be lowercased
ManasMaji 9aa4b7d
chore: fix tests
ManasMaji 6fc4ee5
fix: ensure not duplicate path structure for assets
ManasMaji cdc8b74
feat: add support for other assets like pdf, videos, docs, etc.
ManasMaji d9b435c
Revert "feat: add support for other assets like pdf, videos, docs, etc."
ManasMaji 135bfe3
fix: address feedback
ManasMaji 7e4c24e
fix: address feedback
ManasMaji 3baa085
test: add mystique url test
dda9ddb
chore: fix tests
ManasMaji 96ac401
feat: add support for other assets like pdf, videos, docs, etc.
ManasMaji 02c32b7
chore: code refactoring
ManasMaji ac88e19
chore: code refactoring
ManasMaji 7b6d8a4
chore: code refactoring
ManasMaji 823cba4
chore: add more tests
ManasMaji e11a46e
@releng: merge main
ManasMaji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ const imageRegex = /!\[([^\]]*)]\(([^) "]+)(?: *"([^"]*)")?\)|!\[([^\]]*)]\[([^\ | |
// Regex for reference definitions | ||
const referenceRegex = /\[([^\]]+)]:\s*(\S+)/g; | ||
|
||
// Regex for non-image asset links (PDFs, docs, excel etc.) | ||
const nonImageAssetRegex = /(?:\[(.*?)\]|\[.*?\])\(([^)]+\.(?:pdf|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odp|rtf|txt|csv))\)|\[(.*?)\]:\s*(\S+\.(?:pdf|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odp|rtf|txt|csv))/gi; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a unit test to validate that we are catching the different types of assets. |
||
|
||
/** | ||
* Function to find reference definitions in a markdown file. | ||
* | ||
|
@@ -36,51 +39,60 @@ const findReferenceDefinitionsInMarkdown = (markdownContent) => { | |
}; | ||
|
||
/** | ||
* Function to scan for images in a markdown file. | ||
* Function to scan for assets in a markdown file. | ||
* | ||
* @param markdownContent - The content of the markdown file | ||
* @returns {Array<string>} A Map of image urls as key | ||
* @returns {Array<string>} A Map of asset urls as key | ||
*/ | ||
const findImagesInMarkdown = (markdownContent) => { | ||
const findAssetsInMarkdown = (markdownContent) => { | ||
const references = findReferenceDefinitionsInMarkdown(markdownContent); | ||
|
||
const imageUrls = []; | ||
const assetUrls = []; | ||
|
||
// Identify each image url in the markdown content | ||
let match; | ||
let url; | ||
// eslint-disable-next-line no-cond-assign | ||
while ((match = imageRegex.exec(markdownContent)) !== null) { | ||
let url; | ||
if (match[2]) { // Inline image | ||
// eslint-disable-next-line prefer-destructuring | ||
url = match[2]; | ||
} else if (match[5]) { // Reference-style image | ||
url = references[match[5]] || null; // Resolve URL from reference map | ||
} | ||
if (url) { | ||
imageUrls.push(url); | ||
assetUrls.push(url); | ||
} | ||
} | ||
|
||
// Find and add only non-image asset links | ||
// eslint-disable-next-line no-cond-assign | ||
while ((match = nonImageAssetRegex.exec(markdownContent)) !== null) { | ||
url = match[2] || match[3]; | ||
if (url) { | ||
assetUrls.push(url); | ||
} | ||
} | ||
|
||
return imageUrls; | ||
return assetUrls; | ||
}; | ||
|
||
/** | ||
* Get the list image urls present in the markdown. | ||
* Get the list asset urls present in the markdown. | ||
* @param {string} markdownContent - The content of the markdown file | ||
* @returns {Array<string>} An array of image urls. | ||
* @returns {Array<string>} An array of asset urls. | ||
*/ | ||
const getImageUrlsFromMarkdown = (markdownContent) => { | ||
const getAssetUrlsFromMarkdown = (markdownContent) => { | ||
try { | ||
return findImagesInMarkdown(markdownContent); | ||
return findAssetsInMarkdown(markdownContent); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.warn('Error getting image urls from markdown:', error); | ||
console.warn('Error getting asset urls from markdown:', error); | ||
return []; | ||
} | ||
}; | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
getImageUrlsFromMarkdown, | ||
getAssetUrlsFromMarkdown, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
+---------------------------------------------+ | ||
| Hero | | ||
+=============================================+ | ||
| ![][image0] | | ||
+---------------------------------------------+ | ||
| # Say Hello to Effortless Webpage Creation! | | ||
+---------------------------------------------+ | ||
|
||
[image0]: https://experience-platform-mystique-deploy-ethos102-stage-88229c.stage.cloud.adobe.io/proxy-4b739f7f3d2b43009055c893cdf99ba8-4f279b4c398f4d1d98d4552e3cf521ca/assets/media_18c9c39f49c4050fb54d50b03085228a12a9b1666.png "Effortless Webpage Creation with Mystique's AEM Crosswalk" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" jcr:primaryType="cq:Page"> | ||
<jcr:content cq:template="/libs/core/franklin/templates/page" sling:resourceType="core/franklin/components/page/v1/page" jcr:primaryType="cq:PageContent"> | ||
<root jcr:primaryType="nt:unstructured" sling:resourceType="core/franklin/components/root/v1/root"> | ||
<section sling:resourceType="core/franklin/components/section/v1/section" jcr:primaryType="nt:unstructured"> | ||
<block sling:resourceType="core/franklin/components/block/v1/block" jcr:primaryType="nt:unstructured" image="https://experience-platform-mystique-deploy-ethos102-stage-88229c.stage.cloud.adobe.io/proxy-4b739f7f3d2b43009055c893cdf99ba8-4f279b4c398f4d1d98d4552e3cf521ca/assets/media_18c9c39f49c4050fb54d50b03085228a12a9b1666.png" model="hero" modelFields="[image,imageAlt,text]" name="Hero" text="<p><h1>Say Hello to Effortless Webpage Creation!</h1></p>"></block> | ||
</section> | ||
</root> | ||
</jcr:content> | ||
</jcr:root> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requires a full version bump when releasing!