Skip to content

Commit

Permalink
More precise comparison between Israel and Diaspora triennial schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jul 17, 2024
1 parent 27cbd9e commit 572ad0f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 deletions.
68 changes: 56 additions & 12 deletions src/sedrot.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ export async function parshaDetail(ctx) {
makePrevNext(parsha, date, hd, il);
const hasTriennial = hyear >= 5744;
const triennial = hasTriennial ? makeTriennial(parsha, date, parshaEv, hyear, il) : {};
const titleYear = date ? ' ' + hyear : '';
const [israelDiasporaDiffer, otherLocationAnchor, otherLocationParsha] =
doIsraelDiasporaDiffer(parsha, il, hd, triennial.variation);
doIsraelDiasporaDiffer(parsha, il, hd, triennial);
const title = makeTitle(parsha, date ? hyear : 0, israelDiasporaDiffer, il);
const translations0 = Object.keys(langNames)
.map((lang) => {
const str = Locale.lookupTranslation(parsha.name, lang);
Expand All @@ -185,11 +185,11 @@ export async function parshaDetail(ctx) {
// doubled parsha overwrites first half
Object.assign(commentary, drash[parsha.name]);
await ctx.render('parsha-detail', {
title: `${parsha.name}${titleYear} - Torah Portion - Hebcal`,
title,
parsha,
parshaName: parsha.name.replace(/'/g, '’'),
parshaAnchor,
parshaDateAnchor: getParshaDateAnchor(parshaEv).anchor + iSuffix,
parshaDateAnchor: getParshaDateAnchor(parshaEv).anchor,
reading,
il,
iSuffix,
Expand All @@ -210,6 +210,18 @@ export async function parshaDetail(ctx) {
});
}

function makeTitle(parsha, hyear, israelDiasporaDiffer, il) {
let title = parsha.name;
if (hyear) {
title += ' ' + hyear;
}
if (israelDiasporaDiffer) {
title += ' - ' + (il ? 'Israel' : 'Diaspora');
}
title += ' - Torah Portion - Hebcal';
return title;
}

function makeReading(date, parshaEv, il, parshaName) {
const reading = date ?
getLeyningForParshaHaShavua(parshaEv, il) :
Expand Down Expand Up @@ -252,16 +264,39 @@ function getRawTriennial(parshaName, hd, il) {
return reading;
}

function doTriennialDiffer(a, b) {
if (a.variation !== b.variation) {
return true;
}
if (a.readSeparately && b.readSeparately) {
return false;
}
if (!a.date.isSameDate(b)) {
return true;
}
return false;
}

/**
* @param {any} parsha
* @param {boolean} il
* @param {HDate} hd
* @param {string} variation
* @param {any} triennial
* @return {[boolean, string, string]}
*/
function doIsraelDiasporaDiffer(parsha, il, hd, variation) {
function doIsraelDiasporaDiffer(parsha, il, hd, triennial) {
const parshaName = parsha.name;
const hyear = hd.getFullYear();
if (triennial.readings) {
// compare each 3-year index page
const otherReadings = make3yearTriennial(hyear, parshaName, !il);
for (let yr = 0; yr <= 2; yr++) {
if (doTriennialDiffer(otherReadings[yr], triennial.readings[yr])) {
return [true, '', ''];
}
}
return [false, '', ''];
}
const otherSedra = HebrewCalendar.getSedra(hyear, !il);
const otherParsha = otherSedra.lookup(hd);
const otherParshaName = parshaToString(otherParsha.parsha);
Expand All @@ -286,7 +321,7 @@ function doIsraelDiasporaDiffer(parsha, il, hd, variation) {
}
}
const otherTriennial = getRawTriennial(parshaName, hd, !il);
if (variation !== otherTriennial.variation) {
if (doTriennialDiffer(otherTriennial, triennial)) {
const anchor = parshaDateAnchor(parshaName, dayjs(hd.greg()), !il);
return [true, anchor, parshaName];
}
Expand Down Expand Up @@ -355,7 +390,8 @@ function getParshaDateAnchor(ev) {

function makeTriennial(parsha, date, parshaEv, hyear, il) {
if (!date) {
return make3yearTriennial(hyear, parsha.name, il);
const readings = make3yearTriennial(hyear, parsha.name, il);
return {readings};
}
const reading = getTriennialForParshaHaShavua(parshaEv, il);
if (parsha.name === VEZOT_HABERAKHAH) {
Expand All @@ -369,6 +405,9 @@ function makeTriennial(parsha, date, parshaEv, hyear, il) {
fullParsha: reading.fullParsha,
hyear: hyear,
variation: reading.variation,
date: reading.date,
readSeparately: reading.readSeparately,
readTogether: reading.readTogether,
};
if (reading.haft) {
triennial.haftara = reading.haftara;
Expand All @@ -382,17 +421,22 @@ function makeTriennial(parsha, date, parshaEv, hyear, il) {
return triennial;
}

/**
* @param {number} hyear
* @param {string} parshaName
* @param {boolean} il
* @return {any[]}
*/
function make3yearTriennial(hyear, parshaName, il) {
const triennial = {};
const startYear = Triennial.getCycleStartYear(hyear);
const tri = getTriennial(startYear, il);
triennial.readings = Array(3);
const readings = Array(3);
for (let yr = 0; yr < 3; yr++) {
const reading = makeTriReading(tri, yr, parshaName, il);
reading.hyear = startYear + yr;
triennial.readings[yr] = reading;
readings[yr] = reading;
}
return triennial;
return readings;
}

function makeTriReading(tri, yr, parshaName, il) {
Expand Down
10 changes: 5 additions & 5 deletions views/parsha-detail.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ ol.list-unstyled li {margin-bottom: 0.33em}
<%- await include('partials/warning-1752.ejs') -%>
<% } -%>
<p>Parashat <%=parshaName%> is the <%=parsha.ordinal%> weekly Torah portion in the annual Jewish cycle of Torah reading.
<% if (date && israelDiasporaDiffer) { -%>
<p><small>This page displays the <%=il?'Israel':'Diaspora'%> Torah reading for <%=parshaName%> <%=hd.getFullYear()%>.
The <a href="<%=otherLocationAnchor%>"><%=il?'Diaspora':'Israel'%> schedule</a> is used
by Jews living <%=il?'outside of':'in'%> modern Israel.</small></p>
<% } -%>
<% if (!date) { -%>
Next read <% if (israelDiasporaDiffer) { %>in <%=locationName%><% } %> on <a href="<%=parshaDateAnchor%>"><time datetime="<%= d.format('YYYY-MM-DD') %>" class="text-nowrap"><%= d.format('D MMMM YYYY') %></time> / <span class="text-nowrap"><%= hd.toString().replace(/'/g, '') %></span></a>.
<% } -%>
</p>
<% if (israelDiasporaDiffer) { -%>
<p><small>This page displays the <%=il?'Israel':'Diaspora'%> Torah reading for <%=parshaName%><%= date ? ' ' + hd.getFullYear() : '' %>.
The <a href="<%=date ? otherLocationAnchor : parshaAnchor + (il?'':'?i=on')%>"><%=il?'Diaspora':'Israel'%> schedule</a> is used
by Jews living <%=il?'outside of':'in'%> modern Israel.</small></p>
<% } -%>
<h4 id="torah"><span class="d-none d-sm-inline">Torah Portion:</span>
<% if (reading.torahHtml) { %><%- reading.torahHtml -%>
<% } else { -%>
Expand Down

0 comments on commit 572ad0f

Please sign in to comment.