create html part 16
All checks were successful
ci / build (push) Successful in 1m9s

This commit is contained in:
Christopher Hase 2025-03-27 15:29:19 +01:00
parent 27ceae30f0
commit a69ae5520f

View file

@ -16,12 +16,9 @@ exec('iching divine', (error, stdout, stderr) => {
return; return;
} }
//console.log(`Ergebnis:\n${stdout}`);
console.log(`Send E-Mail`); console.log(`Send E-Mail`);
sendEmail(stdout); sendEmail(stdout);
sleep(); sleep();
}); });
@ -40,9 +37,7 @@ async function sendEmail(content: string) {
to: "Christopher.Hase@telekom.com;test@mailhog.local", to: "Christopher.Hase@telekom.com;test@mailhog.local",
subject: "Your Horoscope Is Ready", subject: "Your Horoscope Is Ready",
text: content, text: content,
//html: "<p> ${content} </p>"
html: html(content) html: html(content)
//html: content
}); });
console.log("E-Mail sent: ", info.messageId); console.log("E-Mail sent: ", info.messageId);
@ -61,22 +56,22 @@ async function sleep() {
}, 3600000); }, 3600000);
} }
//node structure for the Parse Tree //node structure for the Parse Tree (it's a degenerated tree with one or zero children per node)
interface Node { interface Node {
type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ; type: "Root" | "Hexagram" | "Judgement" | "Images" | "ChangingLines" ;
child?: Node; child?: Node;
value?: string; value?: string;
//level?: number; // Für Header
} }
//generate 1) Parse Tree and 2) HTML
function html(inputText: string): string { function html(inputText: string): string {
// Parse Tree erstellen & HTML generieren
const parseTree = parse(inputText); const parseTree = parse(inputText);
const htmlOutput = render(parseTree); const htmlOutput = render(parseTree);
return htmlOutput; return htmlOutput;
} }
//generate the Parse Tree
function parse(input: string): Node { function parse(input: string): Node {
console.log("Parse input text"); console.log("Parse input text");
@ -91,7 +86,7 @@ function parse(input: string): Node {
const hexagram: Node = { type: "Hexagram"}; const hexagram: Node = { type: "Hexagram"};
currentNode.child = hexagram; currentNode.child = hexagram;
currentNode = hexagram; currentNode = hexagram;
currentNode.value = "<h1>" + line + "</h1>"; //TODO: formattierung currentNode.value = "<h1>" + line + "</h1>";
} else if (line.startsWith("Judgement")) { } else if (line.startsWith("Judgement")) {
const judgement: Node = { type: "Judgement"}; const judgement: Node = { type: "Judgement"};
currentNode.child = judgement; currentNode.child = judgement;
@ -106,7 +101,7 @@ function parse(input: string): Node {
const changingLines: Node = { type: "ChangingLines"}; const changingLines: Node = { type: "ChangingLines"};
currentNode.child = changingLines; currentNode.child = changingLines;
currentNode = changingLines; currentNode = changingLines;
currentNode.value = line + "<br>"; //TODO: formattierung currentNode.value = line + "<br>";
} else { } else {
currentNode.value = currentNode.value + line + "<br>"; currentNode.value = currentNode.value + line + "<br>";
@ -117,6 +112,7 @@ function parse(input: string): Node {
return root; return root;
} }
//generate HTML from Parse Tree
function render(node: Node): string { function render(node: Node): string {
if (node == undefined) { if (node == undefined) {
@ -135,7 +131,12 @@ function render(node: Node): string {
switch (node.type) { switch (node.type) {
case "Root": case "Root":
return render(node.child!); return render(node.child!);
//case "Hexagram": case "Hexagram":
outputHTML = "<p><i>" + node.value + "</i></p>";
outputHTML = outputHTML + render(node.child!);
return outputHTML;
case "ChangingLines" : case "ChangingLines" :
outputHTML = "<p style=\"color: gray;\">" + node.value + "</p>"; outputHTML = "<p style=\"color: gray;\">" + node.value + "</p>";
outputHTML = outputHTML + render(node.child!); outputHTML = outputHTML + render(node.child!);