Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function renderEmail(name, props, { pathPrefix } = {}) {
const thePathPrefix = pathPrefix || root;
const Email = require(`${thePathPrefix}/.nextmail/${name}`).default;
const { html } = render(Email(props));
const text = htmlToText.fromString(html);
return { html, text };
}
const initialProps = typeof Template.getInitialProps === 'function'
? await Template.getInitialProps({ payload })
: {};
debug('initialProps: %o', initialProps);
const props = Object.assign({}, payload, initialProps);
debug('props: %o', props);
const subject = typeof Template.getSubject === 'function'
? await Template.getSubject({ payload, props })
: null;
debug('subject: %s', subject);
const { html } = render(Template(props));
const text = htmlToText.fromString(html);
return { html, subject, text };
}
}