Skip to content

Commit

Permalink
Add prev/next holiday links to holiday detail pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Sep 14, 2023
1 parent 8ad8f8b commit 82142a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
24 changes: 22 additions & 2 deletions src/holidayDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function holidayDetail(ctx) {
return;
}
const meta = await getHolidayMeta(holiday);
const holidayBegin = getHolidayBegin(holiday, year, il);
const {multiYearBegin, holidayBegin} = getHolidayBegin(holiday, year, il);
const occursOn = makeOccursOn(holidayBegin, holiday, il);
if (holiday === OMER_TITLE) {
for (const item of occursOn) {
Expand All @@ -120,6 +120,22 @@ export async function holidayDetail(ctx) {
httpRedirect(ctx, `/holidays/${holidayAnchor}`);
return;
}
const idx = year ? multiYearBegin.findIndex((ev) => ev === next.event) : -1;
const prevNext = {};
if (idx !== -1) {
const ev0 = multiYearBegin[idx - 1];
const ev1 = multiYearBegin[idx + 1];
prevNext.prev = {
title: ev0.basename(),
href: ev0.url(),
d: dayjs(ev0.getDate().greg()),
};
prevNext.next = {
title: ev1.basename(),
href: ev1.url(),
d: dayjs(ev1.getDate().greg()),
};
}
const cats = next.categories;
const category0 = cats.length === 1 ? cats[0] : cats[1];
const category = categories[category0] || categories.minor;
Expand Down Expand Up @@ -174,6 +190,8 @@ export async function holidayDetail(ctx) {
translations,
emoji: holiday === 'Chanukah' ? '🕎' : (next.event.getEmoji() || ''),
amp: (q.amp === '1') ? true : undefined,
prev: prevNext.prev,
next: prevNext.next,
});
}

Expand Down Expand Up @@ -225,7 +243,9 @@ function getHolidayBegin(holiday, year, il) {
il,
});
const events = events0.filter((ev) => ev.basename() === holiday);
return getFirstOcccurences(events);
const multiYearBegin = getFirstOcccurences(events0);
const holidayBegin = getFirstOcccurences(events);
return {multiYearBegin, holidayBegin};
}

function doIsraelRedir(ctx, holiday) {
Expand Down
5 changes: 3 additions & 2 deletions src/omerApp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dayjs from 'dayjs';
import {cacheControl, httpRedirect} from './common';
import {cacheControl, httpRedirect, getDefaultHebrewYear} from './common';
import {basename, dirname} from 'path';
import {HDate, months, OmerEvent, HebrewCalendar, Locale} from '@hebcal/core';
import {getHolidayMeta} from './getHolidayMeta';
Expand Down Expand Up @@ -88,6 +88,7 @@ export async function omerApp(rpath, ctx) {
// eslint-disable-next-line require-jsdoc
function redirCurrentYear(ctx) {
const hd = new HDate();
httpRedirect(ctx, `/omer/${hd.getFullYear()}`, 302);
const hyear = getDefaultHebrewYear(hd);
httpRedirect(ctx, `/omer/${hyear}`, 302);
return;
}
8 changes: 8 additions & 0 deletions views/holidayDetail.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
ampForm: true,
}) -%>
<link rel="canonical" href="https://www.hebcal.com/holidays/<%= holidayAnchor %><%= year ? '-' + year : '' %><%= (il && (holiday === 'Shavuot' || holiday === 'Pesach')) ? '?i=on' : '' %>">
<% if (typeof prev !== 'undefined') { %><link rel="prev" href="<%=prev.href%>"><% } %>
<% if (typeof next !== 'undefined') { %><link rel="next" href="<%=next.href%>"><% } %>
<%- await include('partials/holidayBreadcrumbStructured.ejs') -%>
<meta name="description" content="<%=descFirstTwo%> <%=holiday%> <%=nextObserved%>">
<meta name="keywords" content="<%=translations.join(',')%>">
Expand Down Expand Up @@ -281,4 +283,10 @@ Thank you for supporting Hebcal.</p>
<div class="row">
<%- await include('partials/holidayDetailBreadcrumb.ejs') -%>
</div>
<% if (typeof prev !== 'undefined' || typeof next !== 'undefined') { %>
<div class="d-flex gx-2 mt-2 justify-content-between d-print-none">
<% if (typeof prev !== 'undefined') { %><div><a rel="prev" class="btn btn-outline-secondary me-2" href="<%=prev.href%>"><span aria-hidden="true">&nbsp;</span><time datetime="<%=prev.d.format('YYYY-MM-DD')%>"><%-prev.d.format('D[&nbsp;]MMMM')%></time> · <%=prev.title%></a></div><% } %>
<% if (typeof next !== 'undefined') { %><div><a rel="next" class="btn btn-outline-secondary ms-2" href="<%=next.href%>"><%=next.title%> · <time datetime="<%=next.d.format('YYYY-MM-DD')%>"><%-next.d.format('D[&nbsp;]MMMM')%></time><span aria-hidden="true">&nbsp;→</span></a></div><% } %>
</div>
<% } %>
<%- await include('partials/footer.ejs') _%>

0 comments on commit 82142a8

Please sign in to comment.