2026-06-10 23:21:01 -06:00
|
|
|
|
import { visit } from 'unist-util-visit';
|
|
|
|
|
|
|
2026-06-29 20:06:57 -06:00
|
|
|
|
let currentBook = '';
|
|
|
|
|
|
|
2026-06-29 21:40:16 -06:00
|
|
|
|
function scriptureLink(node, args, meta) {
|
2026-06-29 20:31:36 -06:00
|
|
|
|
const value = node.children?.[0]?.value?.trim() || '';
|
2026-06-29 20:06:57 -06:00
|
|
|
|
let passage = (args && args.length > 0 && args[0] != '') ? args[0] : value;
|
2026-06-29 21:40:16 -06:00
|
|
|
|
|
2026-06-29 22:29:56 -06:00
|
|
|
|
if (value.match(/^[Vv][Vv]?(erses?)?\s*/)) {
|
2026-06-29 21:40:16 -06:00
|
|
|
|
const book = meta.data.astro.frontmatter.book;
|
|
|
|
|
|
const chapter = meta.data.astro.frontmatter.chapter;
|
2026-06-29 21:52:30 -06:00
|
|
|
|
if ((args.length == 0 || args[0] == '') && (book && chapter)) {
|
2026-06-29 22:29:56 -06:00
|
|
|
|
passage = `${book} ${chapter}:${value.replace(/^[Vv][Vv]?(erses?)?\s*/, '')}`;
|
2026-06-29 21:52:30 -06:00
|
|
|
|
} else if (args.length == 0 || args[0] == '') {
|
|
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-06-29 21:40:16 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Stylized hyphen replacement from Logos.
|
2026-06-29 20:06:57 -06:00
|
|
|
|
passage = passage.replaceAll(/–/g, '-');
|
|
|
|
|
|
|
|
|
|
|
|
if (passage.match(/^[-0-9:]+$/)) {
|
|
|
|
|
|
passage = `${currentBook} ${passage}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
passage = passage.toLowerCase();
|
|
|
|
|
|
passage = passage.replace(/pss/, 'ps');
|
|
|
|
|
|
const match = passage.match(/^(\d?\s*[-a-zA-Z]+)\s*\d+?/)
|
|
|
|
|
|
|
|
|
|
|
|
passage = passage.replaceAll(/ /g, '+');
|
|
|
|
|
|
passage = passage.replace(/\:/, '%3A');
|
|
|
|
|
|
|
|
|
|
|
|
if (passage !== '') {
|
|
|
|
|
|
node.properties.href = `https://www.biblegateway.com/passage/?search=${passage}&version=ESV`;
|
2026-07-15 15:38:08 -06:00
|
|
|
|
node.properties["data-scripture"] = passage;
|
2026-06-29 20:06:57 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
|
|
currentBook = match?.[1].trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-10 23:21:01 -06:00
|
|
|
|
export const ScriptureLinks = () => {
|
2026-06-29 21:40:16 -06:00
|
|
|
|
return async (tree, file) => {
|
2026-06-10 23:21:01 -06:00
|
|
|
|
visit(tree, 'element', (node) => {
|
2026-06-28 16:45:50 -06:00
|
|
|
|
let tag = '';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
let rest = '';
|
2026-06-10 23:21:01 -06:00
|
|
|
|
const url = node.properties.href;
|
|
|
|
|
|
if (node.tagName !== 'a') {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-06-28 16:45:50 -06:00
|
|
|
|
if (!url.startsWith(':')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (url.indexOf('=') != -1) {
|
2026-06-29 20:06:57 -06:00
|
|
|
|
tag = url.substring(1, url.indexOf('='));
|
|
|
|
|
|
rest = url.substring(url.indexOf('=')+1);
|
2026-06-28 16:45:50 -06:00
|
|
|
|
} else {
|
|
|
|
|
|
tag = url.substring(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-29 20:06:57 -06:00
|
|
|
|
node.properties.class = 'scripture';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
switch (tag) {
|
|
|
|
|
|
// Scripture reference.
|
|
|
|
|
|
case 'scripture':
|
2026-06-29 21:40:16 -06:00
|
|
|
|
scriptureLink(node, rest.split(','), file);
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
// Quoting Jesus' words.
|
|
|
|
|
|
case 'jesus':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
case 'christ':
|
|
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
node.properties.title = 'Scriptural citation or fragmentary citation';
|
|
|
|
|
|
node.properties.class += ' christ';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
// Bible quote.
|
|
|
|
|
|
case 'quote':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
node.properties.title = 'Scriptural citation or fragmentary citation';
|
|
|
|
|
|
node.properties.class += ' quote';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
// Source citation.
|
|
|
|
|
|
case 'cite':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
node.properties.title = 'Scriptural citation or fragmentary citation';
|
|
|
|
|
|
node.properties.class += ' citation';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2026-06-10 23:21:01 -06:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|