Skip to content

Commit

Permalink
Add Bolly Life Provider to support more translation/versions (#22)
Browse files Browse the repository at this point in the history
* update readme

* add a sub module for bible book name to number

* [fact] move main.ts to make root folder cleaner

* [fact] make provider abstract

- to be ready for bolls.life api

* [fact] clean up

* [fact] update picture location

* [feat] add bolly life provider

- problem CORS

* [feat] add bolly life provider through new bff of bible api

* [fix] no more hard coding url

* [doc] update readme and add notice in ui setting

* [feat] add more version/translations

* [doc] add more ui notification
  • Loading branch information
tim-hub authored Apr 3, 2022
1 parent e0e23e8 commit ab0d92d
Show file tree
Hide file tree
Showing 25 changed files with 398 additions and 158 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
.eslintignore
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "biblejs-name-converter"]
path = biblejs-name-converter
url = https://github.com/tim-hub/biblejs-name-converter.git
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Taking Bible Study note in Obsidian.md application easily.
- Automatically suggesting Bible Verses as references.

![obsidian bible reference demo](https://raw.githubusercontent.com/tim-hub/obsidian-bible-reference/master/demo/obsidian-bible-reference-demo.gif)
![obsidian bible reference demo](https://raw.githubusercontent.com/tim-hub/obsidian-bible-reference/master/docs/obsidian-bible-reference-demo.gif)

## How to use
1. Open a note in Obsidian.md application
Expand All @@ -27,19 +27,26 @@
3. Select the version you want to use

## The Bible API and Bible Source
- This plugin Bible Verse Query Functionality is currently powered by [bible-api.com](https://bible-api.com/).
This plugin Bible Verse Query Functionality is currently powered by
- [bible-api.com](https://bible-api.com/)
- It is an open source web api that provides a RESTful API for grabbing bible verses and passages.
- [bolls life bible API](https://bolls.life/api/)
- It supports more languages and versions, and it has a WEB UI for bible reading as well.
> The back-end API might be changed in the future to support more languages and versions.
### Bible Version Avalable
- **KJV**: King James Version
- **Cherokee**: Cherokee New Testament
- **BBE**: Bible in Basic English
- **WEB**: World English Bible
- **OEB**: Open English Bible
- **Clementine**: Clementine Latin Vulgate
- **Almeida**: João Ferreira de Almeida
- **RCCV**: Romanian Corrected Cornilescu Version
- BibleAPI.com
- **KJV**: King James Version
- **Cherokee**: Cherokee New Testament
- **BBE**: Bible in Basic English
- **WEB**: World English Bible
- **OEB**: Open English Bible
- **Clementine**: Clementine Latin Vulgate
- **Almeida**: João Ferreira de Almeida
- **RCCV**: Romanian Corrected Cornilescu Version
- **NIV**: New International Version, 1984 (Bolls Life)
- **NKJV**: New King James Version (Bolls Life)
-


## Contact, Discussion, and Support
Expand All @@ -50,6 +57,7 @@

## Credits

| Name | Github Username | Note |
| :--- | :-----: | ----------- |
| Tim Morgan | @seven1m | for the open source bible-api project and the maintenance of bible-api.com. |
| Name | Github Username | Note |
|:---------------|:--------------------------------------------:|-----------------------------------------------------------------------------|
| Tim Morgan | [@seven1m](https://github.com/seven1m) | For the open source bible-api project and the maintenance of bible-api.com. |
| Bolls Life API | [@bpavlisinec](mailto:[email protected]) | For the free public bible API.|
1 change: 1 addition & 0 deletions biblejs-name-converter
Submodule biblejs-name-converter added at fecced
File renamed without changes
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Taking Bible Study note in Obsidian.md application easily. Automatically suggesting Bible Verses as references. ",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
"dev": "node scripts/esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node scripts/esbuild.config.mjs production",
"version": "node scripts/version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [
"bible",
Expand Down
30 changes: 0 additions & 30 deletions rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion esbuild.config.mjs → scripts/esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ esbuild.build({
banner: {
js: banner,
},
entryPoints: ['main.ts'],
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/VerseEditorSuggestor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor, EditorPosition, EditorSuggest, EditorSuggestContext, EditorSuggestTriggerInfo, TFile } from 'obsidian';
import BibleReferencePlugin from '../main';
import BibleReferencePlugin from './main';
import { VerseTypoCheck } from './VerseTypoCheck';
import { VerseSuggesting } from './VerseSuggesting';
import { BibleReferencePluginSettings } from './data/constants';
Expand Down
66 changes: 25 additions & 41 deletions src/VerseSuggesting.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,50 @@
import { DEFAULT_SETTINGS } from './data/constants';
import {
BibleVersionAPIAdapter,
} from './data/BibleVersionApiAdapter';
import { BibleVersionCollection, IBibleVersion } from './data/BibleVersionCollection';
import { BibleVersionCollection } from './data/BibleVersionCollection';
import { IBibleVersion } from './interfaces/IBibleVersion';
import { IVerseSuggesting } from './interfaces/IVerseSuggesting';
import { IVerse } from './interfaces/IVerse';
import { BibleAPIFactory } from './provider/BibleAPIFactory';
import { BibleProvider } from './provider/BibleProvider';

export interface IVerse {
book_id: string;
book_name: string;
chapter: number;
verse: number;
text: string;
}

/**
* Get public World Engligh Bible bibleVersion
*/
export class VerseSuggesting {
private bibleVersionApiAdapter: BibleVersionAPIAdapter;
export class VerseSuggesting implements IVerseSuggesting {
public text: string;
public bibleVersion : string;
public bibleVersion: string;
private bibleProvider: BibleProvider;

constructor(public bookName: string, public chapterNumber: number, public verseNumber: number, public verseNumberEnd?: number, bibleVersion?:string,) {
constructor(public bookName: string, public chapterNumber: number, public verseNumber: number, public verseNumberEnd?: number, bibleVersion?: string,) {
this.bookName = bookName;
this.chapterNumber = chapterNumber;
this.verseNumber = verseNumber;
this.verseNumberEnd = verseNumberEnd;
this.bibleVersion = bibleVersion;
}

/**
* Get the verse text
* @private
*/
private get queryString():string {
let queryString = `${this.bookName}+${this.chapterNumber}:`;
if (this?.verseNumberEnd > 0) {
queryString += `${this.verseNumber}-${this.verseNumberEnd}`;
} else {
queryString += `${this.verseNumber}`;
}
return queryString;
public get ReplacementContent(): string {
return `> ${this.text.trim() + '\n' + `>> ${this.getVerseReference()}`}`
}

private async getVerses(): Promise<IVerse[]> {
public async getVerses(): Promise<IVerse[]> {
console.debug(this.bibleVersion);
if (this.bibleVersion === DEFAULT_SETTINGS.bibleVersion) {
console.log('match to default language plus version');
}
const bibleVersion = BibleVersionCollection.find((bv: IBibleVersion) => bv.key === this.bibleVersion)
if (!this.bibleVersionApiAdapter || this.bibleVersionApiAdapter.BibleVersionKey !== bibleVersion.key) {
this.bibleVersionApiAdapter = BibleVersionAPIAdapter.BuildBibleVersionAPIAdapterFromIBibleVersion(bibleVersion);
if (!this.bibleProvider || this.bibleProvider.BibleVersionKey !== bibleVersion.key) {
// make sure this is only 1 adapter, and it is the same bible version
this.bibleProvider = BibleAPIFactory.Instance.BuildBibleVersionAPIAdapterFromIBibleVersion(bibleVersion);
}
return this.bibleVersionApiAdapter.query(this.queryString);
return this.bibleProvider.query(
this.bookName,
this.chapterNumber,
this?.verseNumberEnd
? [this.verseNumber, this.verseNumberEnd]
: [this.verseNumber]
);
}


public async fetchAndSetVersesText(): Promise<void> {
// todo add a caching here
// todo add a caching here, this might not be possible with Obsidian limit
const verses = await this.getVerses();
let text = '';
verses.forEach(verse => {
Expand All @@ -66,10 +54,6 @@ export class VerseSuggesting {
}

public getVerseReference(): string {
return `-- [${this.bookName} ${this.chapterNumber}:${this.verseNumber}${this.verseNumberEnd? `-${this.verseNumberEnd}`:''}](${this.bibleVersionApiAdapter.VersesUrl})`;
}

public get ReplacementContent(): string {
return `> ${this.text.trim() + '\n' +`>> ${this.getVerseReference()}`}`
return `-- [${this.bibleProvider.BibleReferenceHead}](${this.bibleProvider.QueryURL})`;
}
}
11 changes: 11 additions & 0 deletions src/data/BibleApiSourceCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const BibleAPISourceCollection = {
bibleApi: {
name: 'Bible API',
apiUrl: 'https://bible-api.com',
},
bollsLife: {
name: 'Bolls Life',
apiUrl: 'https://bible-api-bff.bai.uno/bolls-life', // 'https://bolls.life',
}

}
56 changes: 0 additions & 56 deletions src/data/BibleVersionApiAdapter.ts

This file was deleted.

Loading

0 comments on commit ab0d92d

Please sign in to comment.