57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
// 渲染两封示例邮件 HTML 到 .mail-preview/,供浏览器预览(不发送)
|
|||
|
|
// 用法(在仓库根目录):
|
||
|
|
// npx tsc tools/preview-mail.ts src/lib/mail.ts --outDir .mail-build --module commonjs --target es2022 --moduleResolution node --skipLibCheck --esModuleInterop --noEmit false
|
||
|
|
// node .mail-build/tools/preview-mail.js
|
||
|
|
import * as path from 'path';
|
||
|
|
const { replyMailHtml, adminMailHtml, replyMailSubject, adminMailSubject } = require('../src/lib/mail');
|
||
|
|
|
||
|
|
const now = Date.now();
|
||
|
|
const parent = {
|
||
|
|
id: 15630,
|
||
|
|
content: '终于恢复更新了啊 确实有点无聊了,做些损人不利己的事 :prophet:',
|
||
|
|
created_at: now - 3600_000,
|
||
|
|
page_key: '/comment.html',
|
||
|
|
};
|
||
|
|
const reply = {
|
||
|
|
id: 15631,
|
||
|
|
content: '恢复了,今天有空,把服务全部迁移到 cloudflare 上了,GitHub 仓库只做文件备份了 😄[doge]',
|
||
|
|
created_at: now,
|
||
|
|
page_key: '/comment.html',
|
||
|
|
};
|
||
|
|
const newMsg = {
|
||
|
|
id: 15632,
|
||
|
|
content: '测试留言:这个聊天气泡样式的邮件通知看起来真不错!',
|
||
|
|
created_at: now,
|
||
|
|
page_key: '/comment.html',
|
||
|
|
};
|
||
|
|
|
||
|
|
const site = { siteName: '优世界', siteUrl: 'https://usj.cc', pageTitle: '留言', pageUrl: 'https://usj.cc/comment.html' };
|
||
|
|
|
||
|
|
const replyHtml = replyMailHtml({
|
||
|
|
...site,
|
||
|
|
parentComment: parent,
|
||
|
|
parentNick: '扳布',
|
||
|
|
parentEmail: 'banbu@example.com',
|
||
|
|
comment: reply,
|
||
|
|
commenterNick: '小赵',
|
||
|
|
commenterEmail: 'imql@qq.com',
|
||
|
|
toNick: '扳布',
|
||
|
|
});
|
||
|
|
const adminHtml = adminMailHtml({
|
||
|
|
...site,
|
||
|
|
comment: newMsg,
|
||
|
|
commenterNick: '测试访客',
|
||
|
|
commenterEmail: 'guest@example.com',
|
||
|
|
adminNick: '小赵',
|
||
|
|
});
|
||
|
|
|
||
|
|
const fs = require('fs');
|
||
|
|
fs.mkdirSync(__dirname + '/.mail-preview', { recursive: true });
|
||
|
|
fs.writeFileSync(__dirname + '/.mail-preview/reply.html', replyHtml);
|
||
|
|
fs.writeFileSync(__dirname + '/.mail-preview/notice.html', adminHtml);
|
||
|
|
console.log('SUBJECT reply :', replyMailSubject({
|
||
|
|
...site, parentComment: parent, parentNick: 'a', parentEmail: 'a@a.com',
|
||
|
|
comment: reply, commenterNick: '小赵', commenterEmail: 'b@b.com', toNick: '扳布',
|
||
|
|
}));
|
||
|
|
console.log('SUBJECT notice:', adminMailSubject({ ...site, comment: newMsg, commenterNick: 'c', commenterEmail: 'c@c.com', adminNick: 'x' }));
|
||
|
|
console.log('OK');
|