Skip to content

Commit

Permalink
prettier fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-hub committed Sep 4, 2024
1 parent d2a80bc commit b28a130
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 181 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
> On iOS devices, there is a known issue about conflict between `Smart Punctuation` and double hyphens `--`.
>
> To make it work,
> To make it work,
>
> - you can use `++` instead of `--` in the beginning of the verse reference => `++John1:1` (recommended)
> - or you can turn Smart Punctuation off => [How to use](https://github.com/tim-hub/obsidian-bible-reference/wiki/How-to-use#how-to-use-on-ios-iphone--ipad)
Expand Down Expand Up @@ -89,11 +90,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

> Special thanks for the sponsors [![support button of obsidian bible reference](https://img.shields.io/static/v1?label=SupportMe&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/tim-hub)

<!-- sponsors --><!-- sponsors -->



## Related Projects
- [Bible Vector Search](https://bible-search.antioch.tech/) To search Bible verses in meaning not in keywords.
This is another open source project I built recently to implement AI Embedding and Vector Search for Bible verses (in BBE transaltion).

- [Bible Vector Search](https://bible-search.antioch.tech/) To search Bible verses in meaning not in keywords.
This is another open source project I built recently to implement AI Embedding and Vector Search for Bible verses (in BBE transaltion).
15 changes: 11 additions & 4 deletions src/api/PluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { App } from 'obsidian'
export class BibleReferenceAPI {
public constructor(
public app: App,
public settings: BibleReferencePluginSettings,
public settings: BibleReferencePluginSettings
) {
this.app = app
this.settings = settings
Expand All @@ -28,12 +28,19 @@ export class BibleReferenceAPI {
* @param {String} query - the query string (e.g. 'Luke 1:1')
* @param {BibleReferencePluginSettings?} [opts=undefined] - optional overrides for any settings
*/
async queryVerses(query: string, opts?: BibleReferencePluginSettings): Promise<VerseSuggesting | null> {
async queryVerses(
query: string,
opts?: BibleReferencePluginSettings
): Promise<VerseSuggesting | null> {
if (!verseMatch(query)) return null
return getSuggestionsFromQuery(`${query}`, this.mergeSettings(opts)).then(verseArray => verseArray[0] || null)
return getSuggestionsFromQuery(`${query}`, this.mergeSettings(opts)).then(
(verseArray) => verseArray[0] || null
)
}

private mergeSettings(opts?: BibleReferencePluginSettings): BibleReferencePluginSettings {
private mergeSettings(
opts?: BibleReferencePluginSettings
): BibleReferencePluginSettings {
return opts
? Object.assign(Object.assign({}, this.settings), opts)
: Object.assign({}, this.settings)
Expand Down
55 changes: 25 additions & 30 deletions src/data/BibleVersionCollection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IBibleVersion } from '../interfaces/IBibleVersion'
import { BibleAPISourceCollection } from './BibleApiSourceCollection'


export const BibleVersionCollectionEnglish = [
{
key: 'amp',
Expand Down Expand Up @@ -31,7 +30,8 @@ export const BibleVersionCollectionEnglish = [
language: 'English',
code: 'en',
apiSource: BibleAPISourceCollection.bollsLife,
infoURL: 'https://en.wikipedia.org/wiki/Messianic_Bible_translations#Complete_Jewish_Bible_(CJB)',
infoURL:
'https://en.wikipedia.org/wiki/Messianic_Bible_translations#Complete_Jewish_Bible_(CJB)',
},
{
key: 'drb',
Expand Down Expand Up @@ -198,7 +198,7 @@ export const BibleVersionCollectionEnglish = [
},
{
key: 'ylt',
versionName: 'Young\'s Literal Translation',
versionName: "Young's Literal Translation",
language: 'English',
code: 'en',
apiSource: BibleAPISourceCollection.bollsLife,
Expand Down Expand Up @@ -312,14 +312,12 @@ export const BibleVersionCollectionGreek = [
language: 'Greek Ελληνικά',
apiSource: BibleAPISourceCollection.bollsLife,
},

]

export const BibleVersionCollectionHebrew = [

{
key: 'dhnt',
versionName: 'Delitzsch\'s Hebrew New Testament 1877, 1998 (with Vowels)',
versionName: "Delitzsch's Hebrew New Testament 1877, 1998 (with Vowels)",
language: 'Hebrew עברית',
apiSource: BibleAPISourceCollection.bollsLife,
},
Expand Down Expand Up @@ -427,7 +425,6 @@ export const BibleVersionCollectionSpanish = [
},
]


export const BibleVersionCollectionPolish = [
{
key: 'bg',
Expand Down Expand Up @@ -488,34 +485,32 @@ export const BibleVersionCollectionTamil = [
},
]


/**
* Please note to support the abbreviation of the translation
* "code" need to be added
* And the Abbreviation source need to be updated too See this repo. https://github.com/AntiochTechnology/bible-reference-toolkit/tree/master/packages/bible-book-names-intl
*/
export const BibleVersionCollection: IBibleVersion[] =
[
...BibleVersionCollectionArabic,
...BibleVersionCollectionCherokee,
...BibleVersionCollectionChinese,
...BibleVersionCollectionEnglish,
...BibleVersionCollectionEnglishUK,
...BibleVersionCollectionFrench,
...BibleVersionCollectionGerman,
...BibleVersionCollectionGreek,
...BibleVersionCollectionHebrew,
...BibleVersionCollectionIndonesian,
...BibleVersionCollectionItalian,
...BibleVersionCollectionLatin,
...BibleVersionCollectionPolish,
...BibleVersionCollectionPortuguese,
...BibleVersionCollectionRomanian,
...BibleVersionCollectionRussian,
...BibleVersionCollectionSpanish,
...BibleVersionCollectionTamil,
...BibleVersionCollectionUkrainian,
]
export const BibleVersionCollection: IBibleVersion[] = [
...BibleVersionCollectionArabic,
...BibleVersionCollectionCherokee,
...BibleVersionCollectionChinese,
...BibleVersionCollectionEnglish,
...BibleVersionCollectionEnglishUK,
...BibleVersionCollectionFrench,
...BibleVersionCollectionGerman,
...BibleVersionCollectionGreek,
...BibleVersionCollectionHebrew,
...BibleVersionCollectionIndonesian,
...BibleVersionCollectionItalian,
...BibleVersionCollectionLatin,
...BibleVersionCollectionPolish,
...BibleVersionCollectionPortuguese,
...BibleVersionCollectionRomanian,
...BibleVersionCollectionRussian,
...BibleVersionCollectionSpanish,
...BibleVersionCollectionTamil,
...BibleVersionCollectionUkrainian,
]

export const DEFAULT_BIBLE_VERSION = BibleVersionCollection[11]

Expand Down
33 changes: 17 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ export default class BibleReferencePlugin extends Plugin {
this.addVerseLookupCommand()
this.addRibbonButton()

this.api = new BibleReferenceAPI(this.app, this.settings);
this.api = new BibleReferenceAPI(this.app, this.settings)
// Register the api globally
// @ts-ignore
(window['BibleReferenceAPI'] = this.api) && this.register(() => {
// @ts-ignore
delete window['BibleReferenceAPI']
})
;(window['BibleReferenceAPI'] = this.api) &&
this.register(() => {
// @ts-ignore
delete window['BibleReferenceAPI']
})

// enable vod
this.registerEditorSuggest(
new VerseOfDayEditorSuggester(this, this.settings),
new VerseOfDayEditorSuggester(this, this.settings)
)
this.verseOfDayModal = new VerseOfDayModal(this, this.settings)
this.addVerseOfDayInsertCommand()
Expand Down Expand Up @@ -81,15 +82,15 @@ export default class BibleReferencePlugin extends Plugin {

private async getAndCachedVerseOfDay(): Promise<VerseOfDaySuggesting> {
const { ttl, timestamp, verseOfDaySuggesting } =
this?.cachedVerseOfDaySuggesting || {}
this?.cachedVerseOfDaySuggesting || {}
if (!verseOfDaySuggesting || timestamp + ttl > Date.now()) {
const vodResp = await getVod()
const reference = splitBibleReference(vodResp.verse.details.reference)
const verseTexts = [vodResp.verse.details.text]
const vodSuggesting = new VerseOfDaySuggesting(
this.settings,
reference,
verseTexts,
verseTexts
)
this.cachedVerseOfDaySuggesting = {
verseOfDaySuggesting: vodSuggesting,
Expand All @@ -108,7 +109,7 @@ export default class BibleReferencePlugin extends Plugin {
EventStats.logUIOpen(
'lookupModalOpen',
{ key: `command-lookup`, value: 1 },
this.settings.optOutToEvents,
this.settings.optOutToEvents
)
this.verseLookUpModal.open()
},
Expand All @@ -125,13 +126,13 @@ export default class BibleReferencePlugin extends Plugin {
EventStats.logUIOpen(
'vodEditorOpen',
{ key: `command-vod`, value: 1 },
this.settings.optOutToEvents,
this.settings.optOutToEvents
)
new Notice(
`${verse.verseTexts?.join('')} -- ${verse.verseReference.bookName} ${
verse.verseReference.chapterNumber
}:${verse.verseReference.verseNumber}`,
1000 * 10,
1000 * 10
)
},
})
Expand All @@ -146,7 +147,7 @@ export default class BibleReferencePlugin extends Plugin {
EventStats.logUIOpen(
'vodEditorOpen',
{ key: `command-vod-insert`, value: 1 },
this.settings.optOutToEvents,
this.settings.optOutToEvents
)
editor.replaceSelection(vodSuggesting.allFormattedContent)
},
Expand All @@ -163,10 +164,10 @@ export default class BibleReferencePlugin extends Plugin {
EventStats.logUIOpen(
'lookupModalOpen',
{ key: `ribbon-click`, value: 1 },
this.settings.optOutToEvents,
this.settings.optOutToEvents
)
this.verseLookUpModal.open()
},
}
)
}

Expand All @@ -175,7 +176,7 @@ export default class BibleReferencePlugin extends Plugin {
EventStats.logUIOpen(
'lookupModalOpen',
{ key: `ribbon-remove`, value: 1 },
this.settings.optOutToEvents,
this.settings.optOutToEvents
)
this.ribbonButton.parentNode?.removeChild(this.ribbonButton)
}
Expand Down Expand Up @@ -230,7 +231,7 @@ export default class BibleReferencePlugin extends Plugin {
'getElementsByClassName' in this.statusBarIndicator
) {
const el = this.statusBarIndicator.getElementsByClassName(
'bible-version-indicator',
'bible-version-indicator'
)[0]
el.innerHTML = this.getStatusBatLabel()
}
Expand Down
16 changes: 11 additions & 5 deletions src/provider/BaseBibleAPIProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export abstract class BaseBibleAPIProvider {

constructor(bibleVersion: IBibleVersion) {
this._bibleVersion = bibleVersion
const {key} = bibleVersion
const { key } = bibleVersion
this._versionKey = key
this._apiUrl = bibleVersion.apiSource.apiUrl
}
Expand All @@ -37,7 +37,7 @@ export abstract class BaseBibleAPIProvider {
return this._currentQueryUrl
}

protected abstract prepareVerseLinkUrl():string
protected abstract prepareVerseLinkUrl(): string

/**
* Get the Callout Link URL for the verse query
Expand Down Expand Up @@ -65,8 +65,14 @@ export abstract class BaseBibleAPIProvider {
* @param verses
* @protected
*/
protected buildBibleGatewayUrl(bookName: string, chapter: number, verses: number[]): string {
return `https://www.biblegateway.com/passage/?search=${bookName}+${chapter}:${this.convertVersesToQueryString(verses)}&version=${this._versionKey}`
protected buildBibleGatewayUrl(
bookName: string,
chapter: number,
verses: number[]
): string {
return `https://www.biblegateway.com/passage/?search=${bookName}+${chapter}:${this.convertVersesToQueryString(
verses
)}&version=${this._versionKey}`
}

/**
Expand Down Expand Up @@ -130,7 +136,7 @@ export abstract class BaseBibleAPIProvider {
} catch (e) {
console.error('error while querying', e)
new Notice(`Error while querying ${url}`)
EventStats.logError('errors', {key: url, value: 1})
EventStats.logError('errors', { key: url, value: 1 })
return await Promise.reject(e)
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/provider/BibleAPIDotComProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,33 @@ export class BibleAPIDotComProvider extends BaseBibleAPIProvider {
versionName
? versionName
: this?.BibleVersionKey
? this.BibleVersionKey
: ''
? this.BibleVersionKey
: ''
}`

// setup the bible gateway url
this.bibleGatewayUrl = this.buildBibleGatewayUrl(bookName, chapter, verses).replace(/ /g, "+") // Remove spaces in Book names for URL.
this.bibleGatewayUrl = this.buildBibleGatewayUrl(
bookName,
chapter,
verses
).replace(/ /g, '+') // Remove spaces in Book names for URL.
return this._currentQueryUrl
}

protected prepareVerseLinkUrl(): string {
if (this._versionKey in [
'bbe',
'clementine',
'oeb-us',
'oeb-cw',
'almeida',
'rccv',
'cherokee',
] && !this.bibleGatewayUrl) {
if (
this._versionKey in
[
'bbe',
'clementine',
'oeb-us',
'oeb-cw',
'almeida',
'rccv',
'cherokee',
] &&
!this.bibleGatewayUrl
) {
return this._currentQueryUrl
}
if (this._versionKey === 'webbe') {
Expand Down
Loading

0 comments on commit b28a130

Please sign in to comment.