Compare commits
2 Commits
8d1a6ba740
...
669032fb48
| Author | SHA1 | Date | |
|---|---|---|---|
|
669032fb48
|
|||
|
46c34ba545
|
@@ -0,0 +1,10 @@
|
|||||||
|
# ✝️ holybar
|
||||||
|
Simple menu bar app to show the daily readings from the Bible. It uses the [United States Conference of Catholic Bishops](https://bible.usccb.org/) as the source and the Roman Calendar (romcal) package to determine the liturgical color.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```bash
|
||||||
|
# Install dependencies
|
||||||
|
npm install
|
||||||
|
# Run the application
|
||||||
|
npm start
|
||||||
|
```
|
||||||
@@ -3,6 +3,11 @@ import * as cheerio from "cheerio";
|
|||||||
import { error, reading } from "../helpers/html.mjs";
|
import { error, reading } from "../helpers/html.mjs";
|
||||||
import { log } from "../helpers/logger.mjs";
|
import { log } from "../helpers/logger.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the daily Bible reading from the USCCB website and updates the app's HTML.
|
||||||
|
*
|
||||||
|
* @param {Object} app - The application instance to update with the fetched reading.
|
||||||
|
*/
|
||||||
export default async function refresh(app) {
|
export default async function refresh(app) {
|
||||||
const key = format(startOfToday(), "MMddyy");
|
const key = format(startOfToday(), "MMddyy");
|
||||||
|
|
||||||
|
|||||||
+22
-3
@@ -1,13 +1,19 @@
|
|||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import Handlebars from "handlebars";
|
import Handlebars from "handlebars";
|
||||||
import romcal from "romcal";
|
import romcal from "romcal";
|
||||||
import { isToday } from "date-fns";
|
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() {
|
function css() {
|
||||||
let color = "#007acc"; // Default color
|
let color = "#007acc"; // Default color
|
||||||
|
|
||||||
|
// Get today's liturgical event from the Roman calendar
|
||||||
const event = romcal
|
const event = romcal
|
||||||
.calendarFor(new Date().getFullYear())
|
.calendarFor(getYear(startOfToday()))
|
||||||
.find((e) => isToday(new Date(e.moment)));
|
.find((e) => isToday(new Date(e.moment)));
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
@@ -81,8 +87,15 @@ const readingTemplate = Handlebars.compile(`
|
|||||||
</html>
|
</html>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
export function reading(title, readings) {
|
||||||
const now = new Date();
|
const now = startOfToday();
|
||||||
const url = `https://bible.usccb.org/bible/readings/${format(now, "MMddyy")}.cfm`;
|
const url = `https://bible.usccb.org/bible/readings/${format(now, "MMddyy")}.cfm`;
|
||||||
const date = format(now, "MMMM d, yyyy");
|
const date = format(now, "MMMM d, yyyy");
|
||||||
|
|
||||||
@@ -94,6 +107,12 @@ export function reading(title, readings) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
export function error(status) {
|
||||||
return `
|
return `
|
||||||
<html>
|
<html>
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* A simple logging utility that prefixes log messages with a timestamp and a tag.
|
||||||
|
*
|
||||||
|
* @param {...any} args - The arguments to log, which can be of any type.
|
||||||
|
*/
|
||||||
export const log = (...args) => {
|
export const log = (...args) => {
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
console.log(`[holybar] [${timestamp}]`, ...args);
|
console.log(`[holybar] [${timestamp}]`, ...args);
|
||||||
|
|||||||
Reference in New Issue
Block a user