import { format, getMonth } from "date-fns"; import Handlebars from "handlebars"; import romcal from "romcal"; import { isToday, startOfToday, getYear } from "date-fns"; /** * Generates CSS styles for the HTML content, dynamically adjusting colors based on the current liturgical event. * * @returns {string} A string containing the CSS styles. */ function css() { const now = startOfToday(); let color = "#007acc"; // Default color // Get today's liturgical event from the Roman calendar const event = romcal .calendarFor({ year: getYear(now), country: "croatia", query: { month: getMonth(now), }, }) .find((e) => isToday(new Date(e.moment))); if (event) { if (event.data.meta.liturgicalColor.key.toLowerCase() === "white") { color = "goldenrod"; // Use goldenrod for better visibility on white } else { color = event.data.meta.liturgicalColor.value; } } return ` `; } export const base = ` ${css()}

Loading...

`; const readingTemplate = Handlebars.compile(` ${css()}

{{title}}

{{date}}
{{#each readings}}

{{this.title}}

{{{this.content}}}

{{/each}} `); /** * Generates the HTML content for the daily Bible reading, including the title, readings, and a link to the source. * * @param {string} title - The title of the reading. * @param {Array} readings - An array of reading objects, each containing a title, content, and URL. * @returns {string} A string containing the generated HTML content for the reading. */ export function reading(title, readings) { const now = startOfToday(); const url = `https://bible.usccb.org/bible/readings/${format(now, "MMddyy")}.cfm`; const date = format(now, "MMMM d, yyyy"); return readingTemplate({ title, readings, url, date, }); } /** * Generates the HTML content for an error message when fetching the reading fails. * * @param {number} status - The HTTP status code of the error. * @returns {string} A string containing the generated HTML content for the error message. */ export function error(status) { return ` ${css}

Error fetching reading

Status: ${status}

`; }