diff --git a/dist_scripts/scripts/generateJson/radar.js b/dist_scripts/scripts/generateJson/radar.js index 98e889c..6cfb410 100644 --- a/dist_scripts/scripts/generateJson/radar.js +++ b/dist_scripts/scripts/generateJson/radar.js @@ -117,6 +117,7 @@ var checkAttributes = function (fileName, attributes) { return attributes; }; var createRevisionsFromFiles = function (fileNames) { + var publicUrl = process.env.PUBLIC_URL; return Promise.all(fileNames.map(function (fileName) { return new Promise(function (resolve, reject) { fs_extra_1.readFile(fileName, "utf8", function (err, data) { @@ -127,7 +128,7 @@ var createRevisionsFromFiles = function (fileNames) { var fm = front_matter_1.default(data); // add target attribute to external links // todo: check path - var html = marked_1.default(fm.body.replace(/\]\(\//g, "](/techradar/")); + var html = marked_1.default(fm.body.replace(/\]\(\//g, "](" + publicUrl + "/")); html = html.replace(/a href="http/g, 'a target="_blank" rel="noopener noreferrer" href="http'); resolve(__assign(__assign(__assign({}, itemInfoFromFilename(fileName)), checkAttributes(fileName, fm.attributes)), { fileName: fileName, body: html })); } diff --git a/scripts/generateJson/radar.ts b/scripts/generateJson/radar.ts index 230b504..c877c74 100644 --- a/scripts/generateJson/radar.ts +++ b/scripts/generateJson/radar.ts @@ -44,34 +44,37 @@ const checkAttributes = (fileName: string, attributes: FMAttributes) => { return attributes; }; -const createRevisionsFromFiles = (fileNames: string[]) => - Promise.all( - fileNames.map((fileName) => { - return new Promise((resolve, reject) => { - readFile(fileName, "utf8", (err, data) => { - if (err) { - reject(err); - } else { - const fm = frontMatter(data); - // add target attribute to external links - // todo: check path - let html = marked(fm.body.replace(/\]\(\//g, "](/techradar/")); - html = html.replace( - /a href="http/g, - 'a target="_blank" rel="noopener noreferrer" href="http' - ); +const createRevisionsFromFiles = (fileNames: string[]) => { + const publicUrl = process.env.PUBLIC_URL; + return Promise.all( + fileNames.map( + (fileName) => + new Promise((resolve, reject) => { + readFile(fileName, "utf8", (err, data) => { + if (err) { + reject(err); + } else { + const fm = frontMatter(data); + // add target attribute to external links + // todo: check path + let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`)); + html = html.replace( + /a href="http/g, + 'a target="_blank" rel="noopener noreferrer" href="http' + ); - resolve({ - ...itemInfoFromFilename(fileName), - ...checkAttributes(fileName, fm.attributes), - fileName, - body: html, - } as Revision); - } - }); - }); - }) + resolve({ + ...itemInfoFromFilename(fileName), + ...checkAttributes(fileName, fm.attributes), + fileName, + body: html, + } as Revision); + } + }); + }) + ) ); +}; const itemInfoFromFilename = (fileName: string) => { const [release, name] = fileName.split(path.sep).slice(-2);