Skip to content

Commit

Permalink
support for whole chapter links
Browse files Browse the repository at this point in the history
  • Loading branch information
jaanonim committed Aug 27, 2023
1 parent 590af84 commit 500cf80
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Obsidian Plugin Release
# credits: https://github.com/scambier/obsidian-omnisearch/blob/master/.github/workflows/release.yml

env:
VERSION: v1.0.1
VERSION: v1.0.2

on: [pull_request, workflow_dispatch]

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-youversion-linker",
"name": "Obsidian YouVersion linker",
"version": "1.0.1",
"version": "1.0.2",
"minAppVersion": "0.15.0",
"description": "Obsidian plugin that automatically link bible verses to YouVersion bible.",
"author": "jaanonim",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-youversion-linker",
"version": "1.0.1",
"version": "1.0.2",
"description": "Obsidian plugin that automatically link bible verses to YouVersion bible.",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/EditorSuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function getSuggestionsFromQuery(
const numbers = numbersPartsOfQueryString.split(separatorRegex);

const chapterNumber = parseInt(numbers[0]);
const verseNumber = parseInt(numbers[1]);
const verseNumber = numbers.length > 1 ? parseInt(numbers[1]) : undefined;
const verseEndNumber =
numbers.length === 3 ? parseInt(numbers[2]) : undefined;

Expand Down
14 changes: 14 additions & 0 deletions src/LinkPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ async function processLink(link: HTMLAnchorElement) {
""
);
const data = JSON.parse(json_text);

console.log(data.props.pageProps);
if (data.props.pageProps.type !== "verse") {
const popup = document.createElement("div");
popup.addClass("preview-youversion");

popup
.createSpan({ cls: "error-youversion" })
.setText("Verse preview is unavailable for this type of link.");

tippy(link, { content: popup, allowHTML: true });
return;
}

const info =
data.props.pageProps.referenceTitle.title +
" " +
Expand Down
2 changes: 1 addition & 1 deletion src/Regex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const linkRegex =
/([123]\s?)?\p{L}+\s?\d{1,3}[:,.]\s?\d{1,3}(-\d{1,3})?/gu;
/([123]\s?)?\p{L}+\s?\d{1,3}([:,.]\s?\d{1,3}(-\d{1,3})?)?/gu;

export const bookRegex = /([123]\s?)?\p{L}+/u;

Expand Down
17 changes: 11 additions & 6 deletions src/VerseLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class VerseLink {
private bookUrl: string,
private book: string,
private chapter: number,
private verse: number,
private verse: number | undefined,
private verseEnd: number | undefined
) {}

Expand All @@ -13,9 +13,11 @@ export default class VerseLink {
}

toSimpleText() {
return this.verseEnd
? `${this.book} ${this.chapter}:${this.verse}-${this.verseEnd}`
: `${this.book} ${this.chapter}:${this.verse}`;
return this.verse
? this.verseEnd
? `${this.book} ${this.chapter}:${this.verse}-${this.verseEnd}`
: `${this.book} ${this.chapter}:${this.verse}`
: `${this.book} ${this.chapter}`;
}

toLink(): string {
Expand All @@ -24,8 +26,11 @@ export default class VerseLink {

getUrl(): string {
const base = "https://www.bible.com/bible";
let url = `${base}/${this.version}/${this.bookUrl}.${this.chapter}.${this.verse}`;
if (this.verseEnd) url += `-${this.verseEnd}`;
let url = `${base}/${this.version}/${this.bookUrl}.${this.chapter}`;
if (this.verse) {
url += `.${this.verse}`;
if (this.verseEnd) url += `-${this.verseEnd}`;
}
return url;
}
}
6 changes: 6 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ If your plugin does not need CSS, delete this file.
color: var(--text-faint);
text-align: right;
}

.error-youversion {
display: block;
text-align: center;
color: var(--text-error);
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.0.0": "0.15.0",
"1.0.1": "0.15.0"
"1.0.1": "0.15.0",
"1.0.2": "0.15.0"
}

0 comments on commit 500cf80

Please sign in to comment.