Skip to content

Commit

Permalink
fix(import): remove html comments from imported content
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed Sep 10, 2020
1 parent 8499960 commit 9bce14e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/generic/HelixImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class HelixImporter {
if (this.useCache) {
const localPath = path.resolve(this.cache, `${new URL(url).pathname.replace(/\//gm, '')}.html`);
if (await fs.exists(localPath)) {
return fs.readFile(localPath);
const html = await fs.readFile(localPath);
if (html) {
return html.toString().replace(/<!--[\s\S]*?-->/gm, '');
}
}
}
const html = await rp({
Expand All @@ -63,7 +66,11 @@ class HelixImporter {
await fs.mkdirs(path.dirname(localPath));
await fs.writeFile(localPath, html);
}
return html;
if (html) {
// remove the comments
return html.toString().replace(/<!--[\s\S]*?-->/gm, '');
}
return '';
} catch (error) {
this.logger.error(`Request error or timeout for ${url}: ${error.message}`);
throw new Error(`Cannot get content for ${url}: ${error.message}`);
Expand Down

0 comments on commit 9bce14e

Please sign in to comment.