summaryrefslogtreecommitdiff
path: root/src/lib/handlebars.ts
diff options
context:
space:
mode:
authorGavin Mogan <git@gavinmogan.com>2025-04-23 15:06:54 -0700
committerGavin Mogan <git@gavinmogan.com>2025-04-23 15:30:37 -0700
commitaace2c7e6ccb6e74df83faac74c427d43bfaf79b (patch)
tree72853ba15eae2c1ec46afc0dbf62fe2c0b4550cf /src/lib/handlebars.ts
parenta9a33edbd90f8eb7a011ec839994fb07f084bd8b (diff)
Fix ReferenceError: nodemailerTransporter is not defined
Part of https://github.com/lowercasename/gathio/pull/200 was migrating more code to use the shared init email function, but all the local usages of nodemailerTransporter were missed
Diffstat (limited to 'src/lib/handlebars.ts')
-rw-r--r--src/lib/handlebars.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/handlebars.ts b/src/lib/handlebars.ts
index d5a8b6e..42f8010 100644
--- a/src/lib/handlebars.ts
+++ b/src/lib/handlebars.ts
@@ -1,4 +1,5 @@
import { Request } from "express";
+import { ExpressHandlebars } from "express-handlebars";
export const renderTemplate = async (
req: Request,
@@ -21,3 +22,29 @@ export const renderTemplate = async (
);
});
};
+
+export const renderEmail = async (
+ hbsInstance: ExpressHandlebars,
+ templateName: string,
+ data: Record<string, unknown>,
+): Promise<{ html: string, text: string }> => {
+ const [html, text] = await Promise.all([
+ hbsInstance.renderView(
+ `./views/emails/${templateName}Html.handlebars`,
+ {
+ cache: true,
+ layout: "email.handlebars",
+ ...data,
+ }
+ ),
+ hbsInstance.renderView(
+ `./views/emails/${templateName}Text.handlebars`,
+ {
+ cache: true,
+ layout: "email.handlebars",
+ ...data,
+ }
+ ),
+ ]);
+ return { html, text }
+}