23 lines
886 B
JavaScript
23 lines
886 B
JavaScript
|
|
import { visit } from 'unist-util-visit';
|
||
|
|
|
||
|
|
export const ScriptureLinks = () => {
|
||
|
|
return async tree => {
|
||
|
|
visit(tree, node => {
|
||
|
|
if (node.type === 'link') {
|
||
|
|
if (node.url.startsWith(':scripture')) {
|
||
|
|
let passage;
|
||
|
|
if (node.url.indexOf('=') != -1) {
|
||
|
|
passage = node.url.substring(node.url.indexOf('=')+1).replace(/\+/, " ");
|
||
|
|
} else {
|
||
|
|
if (node.children.length != 0) {
|
||
|
|
passage = node.children[0].value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const script = encodeURIComponent(passage.toLowerCase());
|
||
|
|
const url = `https://www.biblegateway.com/passage/?search=${script}&version=ESV`;
|
||
|
|
node.url = url;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
};
|