summaryrefslogtreecommitdiff
path: root/lib/mail/mailer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mail/mailer.ts')
-rw-r--r--lib/mail/mailer.ts48
1 files changed, 9 insertions, 39 deletions
diff --git a/lib/mail/mailer.ts b/lib/mail/mailer.ts
index 3474a373..329e2e52 100644
--- a/lib/mail/mailer.ts
+++ b/lib/mail/mailer.ts
@@ -15,48 +15,18 @@ const transporter = nodemailer.createTransport({
},
});
-// // Handlebars 템플릿 로더 함수
-// function loadTemplate(templateName: string, data: Record<string, any>) {
-// const templatePath = path.join(process.cwd(), 'lib', 'mail', 'templates', `${templateName}.hbs`);
-// const source = fs.readFileSync(templatePath, 'utf8');
-// const template = handlebars.compile(source);
-// return template(data);
-// }
-function applyLayout(layoutName: string, content: string, context: Record<string, any>) {
- const layoutPath = path.join(process.cwd(), 'lib', 'mail', 'layouts', `${layoutName}.hbs`);
- const layoutSource = fs.readFileSync(layoutPath, 'utf8');
- const layoutTemplate = handlebars.compile(layoutSource);
- return layoutTemplate({ ...context, body: content });
-}
-
-// Partials 자동 등록
-function registerPartials() {
- const partialsDir = path.join(process.cwd(), 'lib', 'mail', 'partials');
- const filenames = fs.readdirSync(partialsDir);
-
- filenames.forEach((filename) => {
- const name = path.parse(filename).name;
- const filepath = path.join(partialsDir, filename);
- const source = fs.readFileSync(filepath, 'utf8');
- handlebars.registerPartial(name, source); // {{> header }}, {{> footer }}
- });
-}
-
-
-// 템플릿 불러오기 + layout/partials 적용
-function loadTemplate(templateName: string, context: Record<string, any>, layout = 'base') {
- registerPartials();
-
+// 템플릿 로더 함수 - 단순화된 버전
+function loadTemplate(templateName: string, data: Record<string, unknown>) {
const templatePath = path.join(process.cwd(), 'lib', 'mail', 'templates', `${templateName}.hbs`);
const source = fs.readFileSync(templatePath, 'utf8');
const template = handlebars.compile(source);
-
- const content = template(context); // 본문 먼저 처리
- return applyLayout(layout, content, context); // base.hbs로 감싸기
+ return template(data);
}
-handlebars.registerHelper('t', function(key: string, options: any) {
- // options.hash에는 Handlebars에서 넘긴 named parameter들(location=location 등)이 들어있음
- return i18next.t(key, options.hash || {});
- });
+
+// i18next 헬퍼 등록
+handlebars.registerHelper('t', function(key: string, options: { hash?: Record<string, unknown> }) {
+ // options.hash에는 Handlebars에서 넘긴 named parameter들이 들어있음
+ return i18next.t(key, options.hash || {});
+});
export { transporter, loadTemplate }; \ No newline at end of file