Added interpolation support for linking "vv <num>" or "vere(s) <num>"
At present, this requires "book" and "chapter" metadata to be present.
This commit is contained in:
parent
c324603640
commit
e05e6a0f13
1 changed files with 13 additions and 3 deletions
|
|
@ -2,9 +2,18 @@ import { visit } from 'unist-util-visit';
|
|||
|
||||
let currentBook = '';
|
||||
|
||||
function scriptureLink(node, args) {
|
||||
function scriptureLink(node, args, meta) {
|
||||
const value = node.children?.[0]?.value?.trim() || '';
|
||||
let passage = (args && args.length > 0 && args[0] != '') ? args[0] : value;
|
||||
|
||||
if (value.match(/[Vv][Vv]?(erses?)?\s*/)) {
|
||||
const book = meta.data.astro.frontmatter.book;
|
||||
const chapter = meta.data.astro.frontmatter.chapter;
|
||||
passage = `${book} ${chapter}:${value.replace(/[Vv][Vv]?(erses?)?\s*/, '')}`;
|
||||
}
|
||||
console.log("passage with meta:", passage);
|
||||
|
||||
// Stylized hyphen replacement from Logos.
|
||||
passage = passage.replaceAll(/–/g, '-');
|
||||
|
||||
if (passage.match(/^[-0-9:]+$/)) {
|
||||
|
|
@ -21,6 +30,7 @@ function scriptureLink(node, args) {
|
|||
if (passage !== '') {
|
||||
node.properties.href = `https://www.biblegateway.com/passage/?search=${passage}&version=ESV`;
|
||||
}
|
||||
console.log('passage after:', passage);
|
||||
|
||||
if (match) {
|
||||
currentBook = match?.[1].trim();
|
||||
|
|
@ -28,7 +38,7 @@ function scriptureLink(node, args) {
|
|||
}
|
||||
|
||||
export const ScriptureLinks = () => {
|
||||
return async tree => {
|
||||
return async (tree, file) => {
|
||||
visit(tree, 'element', (node) => {
|
||||
let tag = '';
|
||||
let rest = '';
|
||||
|
|
@ -50,7 +60,7 @@ export const ScriptureLinks = () => {
|
|||
switch (tag) {
|
||||
// Scripture reference.
|
||||
case 'scripture':
|
||||
scriptureLink(node, rest.split(','));
|
||||
scriptureLink(node, rest.split(','), file);
|
||||
break;
|
||||
// Quoting Jesus' words.
|
||||
case 'jesus':
|
||||
|
|
|
|||
Loading…
Reference in a new issue