Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { EmailTemplate } from "../dtos/email/EmailTemplate";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const emailTemplatesDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "./templates");
|
||||
|
||||
export default async function emailTemplates(): Promise<EmailTemplate[]> {
|
||||
const items: EmailTemplate[] = [];
|
||||
|
||||
const dir = emailTemplatesDir;
|
||||
const fileNames = fs.readdirSync(dir);
|
||||
fileNames.forEach((file) => {
|
||||
if (path.parse(file).ext === ".md") {
|
||||
const fileName = path.parse(file).name;
|
||||
const content = fs.readFileSync(path.join(dir, file), "utf8").split("`");
|
||||
const alias = content[1].replace(/(\r\n|\n|\r)/gm, "");
|
||||
const subject = content[3].replace(/(\r\n|\n|\r)/gm, "");
|
||||
const body = content[5];
|
||||
items.push({
|
||||
type: alias.startsWith("layout-") ? "layout" : "standard",
|
||||
name: fileName,
|
||||
alias,
|
||||
subject,
|
||||
htmlBody: body,
|
||||
active: false,
|
||||
associatedServerId: -1,
|
||||
templateId: -1,
|
||||
});
|
||||
}
|
||||
});
|
||||
function cmp(a: any, b: any) {
|
||||
if (a > b) return +1;
|
||||
if (a < b) return -1;
|
||||
return 0;
|
||||
}
|
||||
return items.sort((x, y) => cmp(x.type, y.type) || cmp(Number(x.name.split("-")[0]), Number(y.name.split("-")[0])));
|
||||
}
|
||||
Reference in new issue
Block a user