Cleanup and removes nav for verses

This commit is contained in:
Scott Tomaszewski 2025-04-10 19:58:33 -04:00
parent 986bd6405b
commit 2475007a74
4 changed files with 59 additions and 27 deletions

View file

@ -251,7 +251,7 @@ export class BibleNavigation {
/**
* Navigate to a specific chapter
*/
private async navigateToChapter(book: string, chapter: number): Promise<void> {
public async navigateToChapter(book: string, chapter: number): Promise<void> {
try {
// Create the file path using the utility
const filePath = BibleFormatter.buildChapterPath(this.vaultPath, book, chapter);

View file

@ -145,35 +145,54 @@ export class BibleReferenceRenderer {
*/
public async processFullBiblePassage(source: string, el: HTMLElement): Promise<void> {
const reference = source.trim();
// TODO - this should be overlaoded with a form that takes the BibleReference
const passage = await this.bibleContentService.getBibleContent(reference);
if (passage) {
const containerEl = document.createElement('div');
containerEl.classList.add('bible-passage-container');
// Add navigation elements at the top of the passage
try {
// Try to parse the reference
const refParts = passage.reference.split(" ");
if (refParts.length >= 2) {
const book = refParts.slice(0, -1).join(" ");
const chapter = parseInt(refParts[refParts.length - 1]);
if (!isNaN(chapter)) {
const parsedRef = new BibleReference(book, chapter);
// Use the new navigation method
this.bibleNavigation.createNavigationElements(containerEl, parsedRef);
}
}
} catch (error) {
console.error("Error adding navigation:", error);
const parsedRef = this.parser.parse(reference);
// TODO - this cant happen if getBibleContent passed...
if (!parsedRef) {
console.error("Failed to parse reference: " + reference);
return;
}
if (parsedRef.isChapterReference() || this.plugin.settings.showNavigationForVerses) {
this.bibleNavigation.createNavigationElements(containerEl, parsedRef);
}
// // Add navigation elements at the top of the passage
// try {
// // Try to parse the reference
// const refParts = passage.reference.split(" ");
// if (refParts.length >= 2) {
// const book = refParts.slice(0, -1).join(" ");
// const chapter = parseInt(refParts[refParts.length - 1]);
// if (!isNaN(chapter)) {
// const parsedRef = new BibleReference(book, chapter);
// // Check if the reference includes verses
// const hasVerses = passage.reference.includes(':');
// // Only show navigation if it's a full chapter or if the setting is enabled
// if (!hasVerses || this.plugin.settings.showNavigationForVerses) {
// this.bibleNavigation.createNavigationElements(containerEl, parsedRef);
// }
// }
// }
// } catch (error) {
// console.error("Error adding navigation:", error);
// }
// Add reference heading
const headingEl = document.createElement('h3');
headingEl.classList.add('bible-passage-heading');
headingEl.textContent = passage.reference;
const referenceLink = headingEl.createEl('a', { text: passage.reference });
referenceLink.onClickEvent(async l => {
await this.bibleNavigation.navigateToChapter(parsedRef.book, parsedRef.chapter);
});
containerEl.appendChild(headingEl);
// Add verses

View file

@ -161,7 +161,7 @@ export class ESVApiService {
/**
* Create a DOM-friendly error message for missing token or API errors
*/
private createErrorMessageContent(type: 'missing-token' | 'api-error', message: string = '', details: string = ''): string {
private createErrorMessageContent(type: 'missing-token' | 'api-error', message: string = '', details: string = ''): HTMLElement {
// We're required to return a string here because it's part of the ESV API response structure
// This method creates the content in a DOM-safe way then serializes to a string
const container = document.createElement('div');
@ -200,7 +200,7 @@ export class ESVApiService {
container.appendChild(linkPara);
}
return container.outerHTML;
return container;
}
/**
@ -216,7 +216,7 @@ export class ESVApiService {
htmlContent: this.createErrorMessageContent(
'missing-token',
'To display Bible passages, you need to set up an ESV API token in the plugin settings.'
),
).outerHTML,
missingToken: true
};
}
@ -260,7 +260,7 @@ export class ESVApiService {
'api-error',
'Failed to load the passage from the ESV API.',
`Status: ${response.status}. Please check your API token in the plugin settings.`
)
).outerHTML
};
}
} catch (error) {
@ -273,7 +273,7 @@ export class ESVApiService {
'api-error',
'An error occurred when trying to access the ESV API.',
'Please check your internet connection and API token.'
)
).outerHTML
};
}
}
@ -352,4 +352,4 @@ export class ESVApiService {
return false;
}
}
}
}

View file

@ -15,6 +15,7 @@ export interface DisciplesJournalSettings {
downloadOnDemand: boolean;
bibleContentVaultPath: string;
stylePreset: string;
showNavigationForVerses: boolean;
}
export const DEFAULT_SETTINGS: DisciplesJournalSettings = {
@ -29,7 +30,8 @@ export const DEFAULT_SETTINGS: DisciplesJournalSettings = {
esvApiToken: '',
downloadOnDemand: true,
bibleContentVaultPath: 'Bible',
stylePreset: 'default'
stylePreset: 'default',
showNavigationForVerses: false
};
export class DisciplesJournalSettingsTab extends PluginSettingTab {
@ -69,6 +71,17 @@ export class DisciplesJournalSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName('Show Navigation for Verses')
.setDesc('Show chapter navigation when displaying specific verses (by default, navigation only shows for full chapters).')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.showNavigationForVerses)
.onChange(async (value) => {
this.plugin.settings.showNavigationForVerses = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName('Style Preset')