@marvalt/wparser 0.1.68 → 0.1.69
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/dist/index.cjs +44 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +44 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/contentExtractor.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1602,14 +1602,23 @@ function getBlockTextContent(block) {
|
|
|
1602
1602
|
*/
|
|
1603
1603
|
function getImageUrl(block) {
|
|
1604
1604
|
const attrs = block.attributes || {};
|
|
1605
|
-
// Check various possible URL attributes
|
|
1606
|
-
|
|
1607
|
-
attrs['
|
|
1608
|
-
attrs['
|
|
1609
|
-
attrs['
|
|
1610
|
-
attrs['
|
|
1611
|
-
|
|
1612
|
-
|
|
1605
|
+
// Check various possible URL attributes - prioritize Cloudflare URLs
|
|
1606
|
+
const possibleUrls = [
|
|
1607
|
+
attrs['url'],
|
|
1608
|
+
attrs['src'],
|
|
1609
|
+
attrs['imageUrl'],
|
|
1610
|
+
attrs['mediaUrl'],
|
|
1611
|
+
attrs['backgroundImage']
|
|
1612
|
+
].filter((url) => typeof url === 'string' && url.trim() !== '');
|
|
1613
|
+
// If any URL is a Cloudflare URL, return it
|
|
1614
|
+
for (const url of possibleUrls) {
|
|
1615
|
+
if (isValidCloudflareUrl(url)) {
|
|
1616
|
+
return url.trim();
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
// If no Cloudflare URL found, return first available URL
|
|
1620
|
+
if (possibleUrls.length > 0) {
|
|
1621
|
+
return possibleUrls[0].trim();
|
|
1613
1622
|
}
|
|
1614
1623
|
// Try to extract from innerHTML if it's an img tag
|
|
1615
1624
|
if (block.innerHTML) {
|
|
@@ -1713,24 +1722,46 @@ function extractImageUrlWithFallback(block) {
|
|
|
1713
1722
|
const attrs = block.attributes || {};
|
|
1714
1723
|
// Check for cloudflareUrl first (from WordPress plugin)
|
|
1715
1724
|
const cloudflareUrl = attrs['cloudflareUrl'];
|
|
1716
|
-
if (cloudflareUrl
|
|
1717
|
-
|
|
1725
|
+
if (cloudflareUrl) {
|
|
1726
|
+
// If cloudflareUrl exists, validate it
|
|
1727
|
+
if (isValidCloudflareUrl(cloudflareUrl)) {
|
|
1728
|
+
return cloudflareUrl;
|
|
1729
|
+
}
|
|
1730
|
+
// If cloudflareUrl exists but is invalid, log for debugging (in development)
|
|
1731
|
+
if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
|
|
1732
|
+
console.warn('extractImageUrlWithFallback: cloudflareUrl exists but is invalid:', cloudflareUrl);
|
|
1733
|
+
}
|
|
1718
1734
|
}
|
|
1719
1735
|
// Try to extract from innerHTML (should be converted by plugin)
|
|
1720
1736
|
if (block.innerHTML) {
|
|
1721
1737
|
// Extract img src from innerHTML
|
|
1722
1738
|
const imgMatch = block.innerHTML.match(/<img[^>]+src=["']([^"']+)["']/i);
|
|
1723
1739
|
if (imgMatch && imgMatch[1]) {
|
|
1724
|
-
|
|
1740
|
+
const innerHtmlUrl = imgMatch[1];
|
|
1741
|
+
// If innerHTML has a Cloudflare URL, use it (plugin converted it)
|
|
1742
|
+
if (isValidCloudflareUrl(innerHtmlUrl)) {
|
|
1743
|
+
return innerHtmlUrl;
|
|
1744
|
+
}
|
|
1745
|
+
// If innerHTML has WordPress URL, continue to check regular attributes
|
|
1725
1746
|
}
|
|
1726
1747
|
// Try background-image in style attribute
|
|
1727
1748
|
const bgMatch = block.innerHTML.match(/background-image:\s*url\(["']?([^"')]+)["']?\)/i);
|
|
1728
1749
|
if (bgMatch && bgMatch[1]) {
|
|
1729
|
-
|
|
1750
|
+
const bgUrl = bgMatch[1];
|
|
1751
|
+
// If background-image has a Cloudflare URL, use it
|
|
1752
|
+
if (isValidCloudflareUrl(bgUrl)) {
|
|
1753
|
+
return bgUrl;
|
|
1754
|
+
}
|
|
1730
1755
|
}
|
|
1731
1756
|
}
|
|
1732
1757
|
// Fall back to regular URL attributes
|
|
1733
|
-
|
|
1758
|
+
const regularUrl = getImageUrl(block);
|
|
1759
|
+
// If regular URL is a Cloudflare URL, use it
|
|
1760
|
+
if (regularUrl && isValidCloudflareUrl(regularUrl)) {
|
|
1761
|
+
return regularUrl;
|
|
1762
|
+
}
|
|
1763
|
+
// Last resort: return regular URL (WordPress URL as fallback)
|
|
1764
|
+
return regularUrl;
|
|
1734
1765
|
}
|
|
1735
1766
|
|
|
1736
1767
|
/**
|