Fix PUBLIC_URL bug referencing images in md files
This commit is contained in:
@@ -117,6 +117,7 @@ var checkAttributes = function (fileName, attributes) {
|
|||||||
return attributes;
|
return attributes;
|
||||||
};
|
};
|
||||||
var createRevisionsFromFiles = function (fileNames) {
|
var createRevisionsFromFiles = function (fileNames) {
|
||||||
|
var publicUrl = process.env.PUBLIC_URL;
|
||||||
return Promise.all(fileNames.map(function (fileName) {
|
return Promise.all(fileNames.map(function (fileName) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
fs_extra_1.readFile(fileName, "utf8", function (err, data) {
|
fs_extra_1.readFile(fileName, "utf8", function (err, data) {
|
||||||
@@ -127,7 +128,7 @@ var createRevisionsFromFiles = function (fileNames) {
|
|||||||
var fm = front_matter_1.default(data);
|
var fm = front_matter_1.default(data);
|
||||||
// add target attribute to external links
|
// add target attribute to external links
|
||||||
// todo: check path
|
// 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');
|
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 }));
|
resolve(__assign(__assign(__assign({}, itemInfoFromFilename(fileName)), checkAttributes(fileName, fm.attributes)), { fileName: fileName, body: html }));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,34 +44,37 @@ const checkAttributes = (fileName: string, attributes: FMAttributes) => {
|
|||||||
return attributes;
|
return attributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createRevisionsFromFiles = (fileNames: string[]) =>
|
const createRevisionsFromFiles = (fileNames: string[]) => {
|
||||||
Promise.all(
|
const publicUrl = process.env.PUBLIC_URL;
|
||||||
fileNames.map((fileName) => {
|
return Promise.all(
|
||||||
return new Promise<Revision>((resolve, reject) => {
|
fileNames.map(
|
||||||
readFile(fileName, "utf8", (err, data) => {
|
(fileName) =>
|
||||||
if (err) {
|
new Promise<Revision>((resolve, reject) => {
|
||||||
reject(err);
|
readFile(fileName, "utf8", (err, data) => {
|
||||||
} else {
|
if (err) {
|
||||||
const fm = frontMatter<FMAttributes>(data);
|
reject(err);
|
||||||
// add target attribute to external links
|
} else {
|
||||||
// todo: check path
|
const fm = frontMatter<FMAttributes>(data);
|
||||||
let html = marked(fm.body.replace(/\]\(\//g, "](/techradar/"));
|
// add target attribute to external links
|
||||||
html = html.replace(
|
// todo: check path
|
||||||
/a href="http/g,
|
let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`));
|
||||||
'a target="_blank" rel="noopener noreferrer" href="http'
|
html = html.replace(
|
||||||
);
|
/a href="http/g,
|
||||||
|
'a target="_blank" rel="noopener noreferrer" href="http'
|
||||||
|
);
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
...itemInfoFromFilename(fileName),
|
...itemInfoFromFilename(fileName),
|
||||||
...checkAttributes(fileName, fm.attributes),
|
...checkAttributes(fileName, fm.attributes),
|
||||||
fileName,
|
fileName,
|
||||||
body: html,
|
body: html,
|
||||||
} as Revision);
|
} as Revision);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
})
|
)
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const itemInfoFromFilename = (fileName: string) => {
|
const itemInfoFromFilename = (fileName: string) => {
|
||||||
const [release, name] = fileName.split(path.sep).slice(-2);
|
const [release, name] = fileName.split(path.sep).slice(-2);
|
||||||
|
|||||||
Reference in New Issue
Block a user