Skip to content

Commit

Permalink
Add myEventsToClassicApi for triennial refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Nov 11, 2024
1 parent 3df5463 commit c1e6788
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@
"eslint": "^9.14.0",
"eslint-plugin-n": "^17.13.1",
"globals": "^15.12.0",
"rollup": "^4.24.4"
"rollup": "^4.25.0"
},
"dependencies": {
"@hebcal/core": "^5.7.7",
"@hebcal/core": "^5.8.0",
"@hebcal/geo-sqlite": "^5.0.6",
"@hebcal/hdate": "^0.12.0",
"@hebcal/icalendar": "^5.1.1",
"@hebcal/icalendar": "^6.0.2",
"@hebcal/learning": "^5.1.2",
"@hebcal/leyning": "^9.0.1",
"@hebcal/locales": "^5.0.1",
"@hebcal/rest-api": "^5.2.0",
"@hebcal/triennial": "^5.1.3",
"@hebcal/leyning": "^9.0.2",
"@hebcal/locales": "^5.0.2",
"@hebcal/rest-api": "^6.0.2",
"@hebcal/triennial": "^6.0.1",
"better-sqlite3": "^11.5.0",
"dayjs": "^1.11.13",
"ejs": "^3.1.10",
Expand Down
12 changes: 4 additions & 8 deletions src/hebcal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {makeHebcalOptions, processCookieAndQuery, possiblySetCookie,
import {getDefaultYear, getDefaultHebrewYear} from './dateUtil.js';
import {makeDownloadProps} from './makeDownloadProps.js';
import {HDate, Locale} from '@hebcal/core';
import {eventsToClassicApi, eventToFullCalendar,
import {
eventToFullCalendar,
eventToClassicApiObject,
locationToPlainObj,
getCalendarTitle,
Expand All @@ -31,12 +32,10 @@ import dayjs from 'dayjs';
import localeData from 'dayjs/plugin/localeData.js';
import './dayjs-locales.js';
import '@hebcal/locales';
import {readJSON} from './readJSON.js';
import {myEventsToClassicApi} from './myEventsToClassicApi.js';

dayjs.extend(localeData);

const pkg = readJSON('../package.json');

export async function hebcalApp(ctx) {
if (ctx.method === 'POST') {
ctx.set('Allow', 'GET');
Expand Down Expand Up @@ -438,10 +437,7 @@ function renderJson(ctx) {
if (q.hdp === '1') {
options.heDateParts = true;
}
let obj = eventsToClassicApi(events, options, !leyningOff);
if (typeof obj.version === 'string') {
obj.version += '-' + pkg.version;
}
let obj = myEventsToClassicApi(events, options, leyningOff);
const cb = empty(q.callback) ? false : q.callback.replace(/[^\w\.]/g, '');
if (cb) {
obj = cb + '(' + JSON.stringify(obj) + ')\n';
Expand Down
37 changes: 37 additions & 0 deletions src/myEventsToClassicApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {flags} from '@hebcal/core';
import {formatAliyahWithBook} from '@hebcal/leyning';
import {
eventsToClassicApiHeader, eventToClassicApiObject,
} from '@hebcal/rest-api';
import {getTriennialForParshaHaShavua} from '@hebcal/triennial';
import {readJSON} from './readJSON.js';

export const pkg = readJSON('../package.json');

export function myEventsToClassicApi(events, options, leyningOff) {
const obj = eventsToClassicApiHeader(events, options);
if (typeof obj.version === 'string') {
obj.version += '-' + pkg.version;
}
obj.items = events.map((ev) => {
const apiObj = eventToClassicApiObject(ev, options, !leyningOff);
if (!leyningOff &&
(ev.getFlags() & flags.PARSHA_HASHAVUA) &&
ev.getDate().getFullYear() >= 5745) {
const triReading = getTriennialForParshaHaShavua(ev, options.il);
const aliyot = triReading?.aliyot;
if (aliyot) {
const triAliyot = {};
for (const [num, aliyah] of Object.entries(aliyot)) {
if (typeof aliyah !== 'undefined') {
const k = num === 'M' ? 'maftir' : num;
triAliyot[k] = formatAliyahWithBook(aliyah);
}
}
apiObj.leyning.triennial = triAliyot;
}
}
return apiObj;
});
return obj;
}
11 changes: 3 additions & 8 deletions src/shabbat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ import {makeDownloadProps} from './makeDownloadProps.js';
import '@hebcal/locales';
import dayjs from 'dayjs';
import {countryNames, getEventCategories, renderTitleWithoutTime, makeAnchor,
eventsToRss2, eventsToClassicApi, appendIsraelAndTracking} from '@hebcal/rest-api';
eventsToRss2, appendIsraelAndTracking} from '@hebcal/rest-api';
import utc from 'dayjs/plugin/utc.js';
import timezone from 'dayjs/plugin/timezone.js';
import './dayjs-locales.js';
import {GeoDb} from '@hebcal/geo-sqlite';
import {readJSON} from './readJSON.js';
import {myEventsToClassicApi} from './myEventsToClassicApi.js';

dayjs.extend(utc);
dayjs.extend(timezone);

const pkg = readJSON('../package.json');

const BASE_URL = 'https://www.hebcal.com/shabbat';

export async function shabbatApp(ctx) {
Expand Down Expand Up @@ -84,10 +82,7 @@ export async function shabbatApp(ctx) {
if (q.hdp === '1') {
ctx.state.options.heDateParts = true;
}
let obj = eventsToClassicApi(ctx.state.events, ctx.state.options, !leyningOff);
if (typeof obj.version === 'string') {
obj.version += '-' + pkg.version;
}
let obj = myEventsToClassicApi(ctx.state.events, ctx.state.options, !leyningOff);
const cb = empty(q.callback) ? false : q.callback.replace(/[^\w\.]/g, '');
if (cb) {
obj = cb + '(' + JSON.stringify(obj) + ')\n';
Expand Down
11 changes: 3 additions & 8 deletions src/yahrzeit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {Event, HDate, HebrewCalendar, Locale,
Location,
flags, gematriya, months} from '@hebcal/core';
import {IcalEvent, icalEventsToString} from '@hebcal/icalendar';
import {eventsToCsv, eventsToClassicApi, eventToFullCalendar} from '@hebcal/rest-api';
import {eventsToCsv, eventToFullCalendar} from '@hebcal/rest-api';
import {myEventsToClassicApi} from './myEventsToClassicApi.js';
import {isoDateStringToDate} from './dateUtil.js';
import dayjs from 'dayjs';
import {basename} from 'path';
Expand All @@ -24,12 +25,9 @@ import {getMaxYahrzeitId, isNumKey, summarizeAnniversaryTypes,
import {makeLogInfo} from './logger.js';
import {isDeepStrictEqual} from 'node:util';
import {murmur128HexSync, murmur32HexSync} from 'murmurhash3';
import {readJSON} from './readJSON.js';

const urlPrefix = process.env.NODE_ENV == 'production' ? 'https://download.hebcal.com' : 'http://127.0.0.1:8081';

const pkg = readJSON('../package.json');

/**
* @param {*} ctx
* @return {*}
Expand Down Expand Up @@ -213,10 +211,7 @@ async function renderJson(maxId, q) {
if (q.hdp === '1') {
options.heDateParts = true;
}
const results = eventsToClassicApi(events, options, false);
if (typeof results.version === 'string') {
results.version += '-' + pkg.version;
}
const results = myEventsToClassicApi(events, options, false);
for (const item of results.items) {
delete item.hebrew;
delete item.category;
Expand Down

0 comments on commit c1e6788

Please sign in to comment.