Rehype parser plugins more appropriately target my intended use case.
This will link (when using ()[:scripture] links) things like Job 3:5, 10:21-22, etc., all to the book of Job without having to repeat the book name. Different anchor styles (including for quoting Christ) will be included in the near future.
This commit is contained in:
parent
c54f9d1ec1
commit
8dc81bcba4
1 changed files with 51 additions and 0 deletions
51
src/utils/rehype.js
Normal file
51
src/utils/rehype.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { visit } from 'unist-util-visit';
|
||||
|
||||
export const ScriptureLinks = () => {
|
||||
return async tree => {
|
||||
let currentBook = '';
|
||||
|
||||
visit(tree, 'element', (node) => {
|
||||
let passage = '';
|
||||
let isQuote = false;
|
||||
const url = node.properties.href;
|
||||
if (node.tagName !== 'a') {
|
||||
return;
|
||||
}
|
||||
if (!url.startsWith(':scripture')) {
|
||||
return;
|
||||
}
|
||||
if (url.indexOf('=') != -1) {
|
||||
const args = url.substring(url.indexOf('=')+1).split(',');
|
||||
for (const arg of args) {
|
||||
if (arg === 'quote') {
|
||||
isQuote = true;
|
||||
} else {
|
||||
passage = arg;
|
||||
}
|
||||
}
|
||||
console.log('specified scripture');
|
||||
} else {
|
||||
passage = node.children?.[0]?.value.trim() || '';
|
||||
}
|
||||
|
||||
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.replace(/ /, '+');
|
||||
passage = passage.replace(/\:/, '%3A');
|
||||
node.properties.href = `https://www.biblegateway.com/passage/?search=${passage}&version=ESV`;
|
||||
|
||||
console.log('match:', match);
|
||||
if (match) {
|
||||
console.log(match);
|
||||
currentBook = match?.[1].trim();
|
||||
console.log(currentBook);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue