diff --git a/src/commands/users/daily.ts b/src/commands/users/daily.ts index abb1771..2c54c4d 100644 --- a/src/commands/users/daily.ts +++ b/src/commands/users/daily.ts @@ -45,7 +45,10 @@ export default class DailyCommand extends BotCommand { return interaction.editReply({ content: "You've already submitted an answer for today's question! Check back tomorrow." }); } - const imagePath = await client.typst.renderToImage(question.typst_source); + const imagePath = await client.typst.renderToImage(question.typst_source, { + topic: question.topic, + difficulty: question.difficulty_rating + }); if (!imagePath) { // Log error to logs channel diff --git a/src/commands/users/weekly.ts b/src/commands/users/weekly.ts index b8efcac..6d3d6ee 100644 --- a/src/commands/users/weekly.ts +++ b/src/commands/users/weekly.ts @@ -45,7 +45,10 @@ export default class WeeklyCommand extends BotCommand { return interaction.editReply({ content: "You've already submitted an answer for this week's question! Check back next Sunday." }); } - const imagePath = await client.typst.renderToImage(question.typst_source); + const imagePath = await client.typst.renderToImage(question.typst_source, { + topic: question.topic, + difficulty: question.difficulty_rating + }); if (!imagePath) { // Log error to logs channel diff --git a/src/libs/Typst.ts b/src/libs/Typst.ts index df0bf51..a75da95 100644 --- a/src/libs/Typst.ts +++ b/src/libs/Typst.ts @@ -92,14 +92,30 @@ export default class Typst { return result; } - async renderToImage(typstCode: string): Promise { + async renderToImage(typstCode: string, metadata?: { topic?: string; difficulty?: string }): Promise { + const metadataHeader = metadata ? ` +#align(center)[ + #block( + fill: rgb("#e0f2fe"), + inset: 10pt, + radius: 4pt, + [ + #text(weight: "bold", size: 14pt)[Topic: ${metadata.topic || "N/A"}] \ + #text(size: 12pt, fill: rgb("#64748b"))[Difficulty: ${metadata.difficulty || "N/A"}] + ] + ) +] + +#v(0.8em) +` : ''; + const styledCode = ` #set page(width: 210mm, height: auto, margin: (x: 20pt, y: 25pt), fill: white) #set text(size: 16pt, font: "New Computer Modern") #set par(justify: true, leading: 0.65em) #set block(spacing: 1.2em) -${typstCode} +${metadataHeader}${typstCode} `; const result = await this.compile(styledCode, { cleanup: false });