mirror of
https://github.com/elyby/emails-renderer.git
synced 2024-12-23 13:49:48 +05:30
Allow images for BitmapText in nested directories
This commit is contained in:
parent
4f31f90c8f
commit
22be93347b
@ -9,29 +9,28 @@ export function BitmapText(props) {
|
|||||||
throw new Error('Only src/emails and src/components subdirectories supported for now');
|
throw new Error('Only src/emails and src/components subdirectories supported for now');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts.length !== 3) {
|
const fileName = parts.pop();
|
||||||
throw new Error('The message.id must contain 3 parts separated by dots');
|
const componentPath = parts.slice(1).join('/');
|
||||||
}
|
|
||||||
|
|
||||||
let src;
|
let src;
|
||||||
let size;
|
let size;
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
src = require(`emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`);
|
src = require(`emails/${componentPath}/images/${props.intl.locale}/${fileName}.png`);
|
||||||
// TODO: we can improve this loader in future by adding an option to disable file emitting
|
// TODO: we can improve this loader in future by adding an option to disable file emitting
|
||||||
// because this thing is handled by url-loader
|
// because this thing is handled by url-loader
|
||||||
size = require(`image-size!emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`);
|
size = require(`image-size!emails/${componentPath}/images/${props.intl.locale}/${fileName}.png`);
|
||||||
} catch (err) { // fallback to default locale
|
} catch (err) { // fallback to default locale
|
||||||
src = require(`emails/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`);
|
src = require(`emails/${componentPath}/images/${props.intl.defaultLocale}/${fileName}.png`);
|
||||||
size = require(`image-size!emails/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`);
|
size = require(`image-size!emails/${componentPath}/images/${props.intl.defaultLocale}/${fileName}.png`);
|
||||||
}
|
}
|
||||||
} catch (err) { // try components
|
} catch (err) { // try components
|
||||||
try {
|
try {
|
||||||
src = require(`components/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`);
|
src = require(`components/${componentPath}/images/${props.intl.locale}/${fileName}.png`);
|
||||||
size = require(`image-size!components/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`);
|
size = require(`image-size!components/${componentPath}/images/${props.intl.locale}/${fileName}.png`);
|
||||||
} catch (err) { // fallback to default locale
|
} catch (err) { // fallback to default locale
|
||||||
src = require(`components/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`);
|
src = require(`components/${componentPath}/images/${props.intl.defaultLocale}/${fileName}.png`);
|
||||||
size = require(`image-size!components/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`);
|
size = require(`image-size!components/${componentPath}/images/${props.intl.defaultLocale}/${fileName}.png`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user