Comparing version 1.10.0 to 1.11.0
@@ -27,15 +27,18 @@ 'use strict'; | ||
let i = 0; | ||
findESIIncludeTags(html, options) | ||
.forEach(tag => { | ||
const placeholder = '<!-- esi-placeholder-' + i + ' -->'; | ||
const tags = findESIIncludeTags(html, options); | ||
if (!tags.length) { | ||
return Promise.resolve(html); | ||
} | ||
tags.forEach(tag => { | ||
const placeholder = '<!-- esi-placeholder-' + i + ' -->'; | ||
if(maxDepthReached) { | ||
html = html.replace(tag, ''); | ||
} else if(tag.includes('<esi:include')) { | ||
html = html.replace(tag, placeholder); | ||
subtasks[i] = getIncludeContents(tag, options) | ||
.then(result => html = html.replace(placeholder, result)); | ||
i++; | ||
} | ||
}); | ||
if(maxDepthReached) { | ||
html = html.replace(tag, ''); | ||
} else if(tag.includes('<esi:include')) { | ||
html = html.replace(tag, placeholder); | ||
subtasks[i] = getIncludeContents(tag, options) | ||
.then(result => html = html.replace(placeholder, result)); | ||
i++; | ||
} | ||
}); | ||
@@ -57,34 +60,12 @@ return Promise.all(subtasks) | ||
function hasESITag(html) { | ||
return html.includes('<esi:include'); | ||
return html.match(/<esi:include.*?(?:\/\s*>|<\/esi:include>)/gm) | ||
} | ||
function findESIIncludeTags(html) { | ||
const open = '<esi:include'; | ||
const fullClose = '</esi:include>'; | ||
const selfClose = '/>'; | ||
function findESIIncludeTags(html) { | ||
const re = /<esi:include.*?(?:\/\s*>|<\/esi:include>)/gm; | ||
const tags = []; | ||
let nextTagOpen; | ||
let nextTagFullClose; | ||
let nextTagSelfClose; | ||
let reducedHtml = html; | ||
do { | ||
nextTagOpen = reducedHtml.indexOf(open); | ||
if(nextTagOpen > -1) { | ||
reducedHtml = reducedHtml.substr(nextTagOpen); | ||
nextTagFullClose = reducedHtml.indexOf(fullClose); | ||
nextTagSelfClose = reducedHtml.indexOf(selfClose); | ||
if(nextTagFullClose > -1 && | ||
(Math.max(0, nextTagFullClose - fullClose.length) < Math.max(0, nextTagSelfClose - selfClose.length)) || | ||
nextTagSelfClose === -1) { | ||
tags.push(reducedHtml.substr(0, nextTagFullClose + fullClose.length)); | ||
reducedHtml = reducedHtml.substr(nextTagFullClose + fullClose.length); | ||
} else { | ||
tags.push(reducedHtml.substr(0, nextTagSelfClose + selfClose.length)); | ||
reducedHtml = reducedHtml.substr(nextTagSelfClose + selfClose.length); | ||
} | ||
} | ||
} while(nextTagOpen > -1); | ||
let match; | ||
while ((match = re.exec(html)) !== null) { | ||
tags.push(match[0]); | ||
} | ||
return tags; | ||
@@ -95,3 +76,4 @@ } | ||
const src = getDoubleQuotedSrc(tag) || getSingleQuotedSrc(tag) || getUnquotedSrc(tag); | ||
return get(src, options); | ||
const alt = getDoubleQuotedAlt(tag) || getSingleQuotedAlt(tag) || getUnquotedAlt(tag); | ||
return get([src, alt], options); | ||
} | ||
@@ -118,3 +100,7 @@ | ||
function get(src, options) { | ||
const getDoubleQuotedAlt = getBoundedString('alt="', '"'); | ||
const getSingleQuotedAlt = getBoundedString("alt='", "'"); | ||
const getUnquotedAlt = getBoundedString('alt=', '>'); | ||
function get([src, alt], options) { | ||
src = decode(src); | ||
@@ -133,3 +119,3 @@ src = dataProvider.toFullyQualifiedURL(src, options); | ||
.then(result => result.body) | ||
.catch(error => handleError(src, error)); | ||
.catch(error => alt ? get([alt], options) : handleError(src, error)); | ||
} | ||
@@ -136,0 +122,0 @@ |
{ | ||
"name": "nodesi", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "ESI: the good parts in node.js", | ||
@@ -5,0 +5,0 @@ "main": "esi.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19341
303