From 8270103896497d147d211f3c281bc15cd6c3ceab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 04:07:56 +0000 Subject: [PATCH] Add Preach My Gospel (PMG) link support Co-authored-by: coderkearns <80931347+coderkearns@users.noreply.github.com> Agent-Logs-Url: https://github.com/coderkearns/obsidian-autoreference-scriptures/sessions/8caaeb34-6b56-440d-90a7-5c75341d486d --- src/scriptures/books.ts | 23 +++++++++++++++++++++++ src/scriptures/parser.ts | 7 ++++++- src/scriptures/urlBuilder.ts | 4 +++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/scriptures/books.ts b/src/scriptures/books.ts index 3a6e4bd..baec251 100644 --- a/src/scriptures/books.ts +++ b/src/scriptures/books.ts @@ -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[] = [ @@ -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-', + }, ]; diff --git a/src/scriptures/parser.ts b/src/scriptures/parser.ts index eee62e3..15a0497 100644 --- a/src/scriptures/parser.ts +++ b/src/scriptures/parser.ts @@ -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', ); })(); diff --git a/src/scriptures/urlBuilder.ts b/src/scriptures/urlBuilder.ts index 270a70f..bd8458d 100644 --- a/src/scriptures/urlBuilder.ts +++ b/src/scriptures/urlBuilder.ts @@ -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;