Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/scriptures/books.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ export interface ScriptureBook {
volume: string;
/** Book path segment used in ChurchOfJesusChrist.org study URLs. */
slug: string;
/**
* Optional override for the base URL up to (but not including) the
* chapter segment. When present, replaces the default
* `BASE_URL/volume/slug` construction in the URL builder.
*/
urlBase?: string;
/**
* Optional prefix inserted before the chapter number in the URL
* (e.g. `"chapter-"` turns chapter `1` into the path segment `chapter-1`).
*/
chapterPrefix?: string;
}

export const SCRIPTURE_BOOKS: ScriptureBook[] = [
Expand Down Expand Up @@ -118,4 +129,16 @@ export const SCRIPTURE_BOOKS: ScriptureBook[] = [
{ names: ['Joseph Smith—Matthew', 'JS—M', 'JS-M'], volume: 'pgp', slug: 'js-m' },
{ names: ['Joseph Smith—History', 'JS—H', 'JS-H'], volume: 'pgp', slug: 'js-h' },
{ names: ['Articles of Faith', 'A of F'], volume: 'pgp', slug: 'a-of-f' },

// ── Preach My Gospel ───────────────────────────────────────────────────────
// List "Preach My Gospel" before the shorter alias "PMG" so the longer form
// is tried first in the regex alternation.
{
names: ['Preach My Gospel', 'PMG'],
volume: 'manual',
slug: 'preach-my-gospel-a-guide-to-sharing-the-gospel-of-jesus-christ',
urlBase:
'https://www.churchofjesuschrist.org/study/manual/preach-my-gospel-a-guide-to-sharing-the-gospel-of-jesus-christ',
chapterPrefix: 'chapter-',
},
];
7 changes: 6 additions & 1 deletion src/scriptures/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ export const SCRIPTURE_REGEX: RegExp = (() => {
// hyphen-separated additional digit groups (e.g. "1", "2-4", "9,11").
const versePart = String.raw`\d+(?:[-,]\d+)*`;

// After the book name, optionally allow "page N", "pg. N", or "#N"
// in addition to the bare "N" used by standard scripture references.
// This supports formats like "PMG page 18", "PMG pg. 18", "PMG #18".
const numberPrefix = String.raw`(?:(?:page|pg\.)\s+|#\s*)?`;

return new RegExp(
String.raw`\b(${bookAlt})\s+(\d+)(?::(${versePart}))?`,
String.raw`\b(${bookAlt})\s+${numberPrefix}(\d+)(?::(${versePart}))?`,
'gi',
);
})();
Expand Down
4 changes: 3 additions & 1 deletion src/scriptures/urlBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function buildUrl(
chapter: string,
verses: string | undefined,
): string {
const chapterUrl = `${BASE_URL}/${book.volume}/${book.slug}/${chapter}?lang=eng`;
const base = book.urlBase ?? `${BASE_URL}/${book.volume}/${book.slug}`;
const chapterSegment = `${book.chapterPrefix ?? ''}${chapter}`;
const chapterUrl = `${base}/${chapterSegment}?lang=eng`;

if (!verses) {
return chapterUrl;
Expand Down
Loading