Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/check-bible-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main

jobs:
build:
build-bible-verify:
runs-on: ubuntu-latest # Indented correctly under 'build'

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main

jobs:
build:
build-site:
runs-on: ubuntu-latest # Indented correctly under 'build'

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.direnv
.DS_Store
result
bible-verify/target
6 changes: 3 additions & 3 deletions bible-verify.nix → bible-verify/bible-verify.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

craneLib.buildPackage {
src = pkgs.lib.fileset.toSource {
root = ./bible-verify;
root = ./.;
fileset = pkgs.lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./bible-verify)
(pkgs.lib.fileset.maybeMissing ./bible-verify/kjv.json)
(craneLib.fileset.commonCargoSources ./.)
(pkgs.lib.fileset.maybeMissing ./kjv.json)
];
};
pname = "bible-verify";
Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@

cargoArtifacts = craneLib.buildDepsOnly nativeArgs;

site = import ./site.nix {
site = import ./site/site.nix {
inherit pkgs craneLib rustToolchain;
};

bibleVerify = import ./bible-verify.nix {
bibleVerify = import ./bible-verify/bible-verify.nix {
inherit pkgs craneLib;
};

Expand Down
Binary file removed site/.DS_Store
Binary file not shown.
123 changes: 70 additions & 53 deletions site/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::env;
use std::fs;
use std::path::Path;
use serde::{Deserialize, Serialize};

// Mirror the structures from the main code
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand All @@ -22,7 +22,7 @@ impl VerseId {
let packed = ((book_id as u32) << 24) | ((chapter & 0xFFF) << 12) | (verse & 0xFFF);
VerseId(packed)
}

fn from_book_name(book_name: &str, chapter: u32, verse: u32) -> Option<Self> {
let book_id = book_name_to_id(book_name)?;
Some(Self::new(book_id, chapter, verse))
Expand Down Expand Up @@ -71,7 +71,7 @@ fn book_name_to_id(book_name: &str) -> Option<u8> {
"Haggai" => Some(37),
"Zechariah" => Some(38),
"Malachi" => Some(39),

// New Testament
"Matthew" => Some(40),
"Mark" => Some(41),
Expand Down Expand Up @@ -100,7 +100,7 @@ fn book_name_to_id(book_name: &str) -> Option<u8> {
"3 John" => Some(64),
"Jude" => Some(65),
"Revelation" => Some(66),

_ => None,
}
}
Expand All @@ -109,7 +109,7 @@ fn expand_book_abbreviation(abbrev: &str) -> String {
match abbrev {
// Old Testament
"Gen" => "Genesis",
"Exod" => "Exodus",
"Exod" => "Exodus",
"Lev" => "Leviticus",
"Num" => "Numbers",
"Deut" => "Deuteronomy",
Expand Down Expand Up @@ -147,7 +147,7 @@ fn expand_book_abbreviation(abbrev: &str) -> String {
"Hag" => "Haggai",
"Zech" => "Zechariah",
"Mal" => "Malachi",

// New Testament
"Matt" => "Matthew",
"Mark" => "Mark",
Expand Down Expand Up @@ -176,25 +176,30 @@ fn expand_book_abbreviation(abbrev: &str) -> String {
"3John" => "3 John",
"Jude" => "Jude",
"Rev" => "Revelation",

// Return as-is if not found
_ => abbrev,
}.to_string()
}
.to_string()
}

fn parse_single_verse_reference(verse_ref: &str) -> Result<(String, u32, u32, Option<u32>), String> {
fn parse_single_verse_reference(
verse_ref: &str,
) -> Result<(String, u32, u32, Option<u32>), String> {
let parts: Vec<&str> = verse_ref.split('.').collect();

if parts.len() != 3 {
return Err("Invalid verse reference format".to_string());
}

let book_name = expand_book_abbreviation(parts[0]);
let chapter = parts[1].parse::<u32>()
let chapter = parts[1]
.parse::<u32>()
.map_err(|_| "Invalid chapter number".to_string())?;
let verse = parts[2].parse::<u32>()
let verse = parts[2]
.parse::<u32>()
.map_err(|_| "Invalid verse number".to_string())?;

Ok((book_name, chapter, verse, None))
}

Expand All @@ -212,99 +217,109 @@ fn parse_verse_reference(verse_ref: &str) -> Result<(String, u32, u32, Option<u3

fn parse_cross_references(content: &str) -> Result<HashMap<VerseId, Vec<Reference>>, String> {
let mut references_map = HashMap::new();

let lines = content.lines();

for (line_num, line) in lines.enumerate() {
// Skip header line
if line_num == 0 {
continue;
}

// Skip empty lines
if line.trim().is_empty() {
continue;
}

// Split by tabs
let parts: Vec<&str> = line.split('\t').collect();
if parts.len() != 3 {
continue; // Skip malformed lines
}

let from_verse_ref = parts[0].trim();
let to_verse_ref = parts[1].trim();
let votes_str = parts[2].trim();

// Parse votes
let votes = votes_str.parse::<i32>()
let votes = votes_str
.parse::<i32>()
.map_err(|_| "Invalid votes".to_string())?;

// Parse from verse
let (from_book, from_chapter, from_verse, _) = parse_single_verse_reference(from_verse_ref)?;
let (from_book, from_chapter, from_verse, _) =
parse_single_verse_reference(from_verse_ref)?;
let from_key = match VerseId::from_book_name(&from_book, from_chapter, from_verse) {
Some(id) => id,
None => continue, // Skip unknown books
};

// Parse to verse (can be range)
let (to_book, to_chapter, to_verse_start, to_verse_end) = parse_verse_reference(to_verse_ref)?;

let (to_book, to_chapter, to_verse_start, to_verse_end) =
parse_verse_reference(to_verse_ref)?;

let reference = Reference {
to_book_name: to_book,
to_chapter,
to_verse_start,
to_verse_end,
votes,
};

// Add to map
references_map
.entry(from_key)
.or_insert_with(Vec::new)
.push(reference);
}

Ok(references_map)
}

fn main() {
println!("cargo:rerun-if-changed=src/storage/cross_references.txt");

let cross_references_path = "src/storage/cross_references.txt";

// Read the cross-references file
let content = fs::read_to_string(cross_references_path)
.expect("Failed to read cross_references.txt");
let content =
fs::read_to_string(cross_references_path).expect("Failed to read cross_references.txt");

// Parse the cross-references
let references = parse_cross_references(&content)
.expect("Failed to parse cross-references");

let references = parse_cross_references(&content).expect("Failed to parse cross-references");

println!("Parsed {} verses with cross-references", references.len());

// Convert to simpler format for binary serialization
let simplified_map: HashMap<u32, Vec<(String, u32, u32, Option<u32>, i32)>> = references
.into_iter()
.map(|(verse_id, refs)| {
let simplified_refs = refs.into_iter()
.map(|r| (r.to_book_name, r.to_chapter, r.to_verse_start, r.to_verse_end, r.votes))
let simplified_refs = refs
.into_iter()
.map(|r| {
(
r.to_book_name,
r.to_chapter,
r.to_verse_start,
r.to_verse_end,
r.votes,
)
})
.collect();
(verse_id.0, simplified_refs)
})
.collect();

// Serialize to binary format for faster loading
let binary_data = bincode::serialize(&simplified_map)
.expect("Failed to serialize cross-references");
let binary_data =
bincode::serialize(&simplified_map).expect("Failed to serialize cross-references");

// Write binary data to output directory
let out_dir = env::var("OUT_DIR").unwrap();
let binary_path = Path::new(&out_dir).join("cross_references.bin");

fs::write(&binary_path, &binary_data)
.expect("Failed to write cross_references.bin");


fs::write(&binary_path, &binary_data).expect("Failed to write cross_references.bin");

// Generate simple Rust code that loads the binary at runtime
let code = r#"// Auto-generated cross-references loader at compile time
use crate::core::types::{References, Reference, VerseId};
Expand Down Expand Up @@ -342,12 +357,14 @@ pub fn get_compiled_cross_references() -> &'static References {
})
}
"#;

// Write the Rust code
let dest_path = Path::new(&out_dir).join("compiled_cross_references.rs");
fs::write(&dest_path, code)
.expect("Failed to write compiled_cross_references.rs");

println!("Generated compiled cross-references with {} bytes of binary data", binary_data.len());
fs::write(&dest_path, code).expect("Failed to write compiled_cross_references.rs");

println!(
"Generated compiled cross-references with {} bytes of binary data",
binary_data.len()
);
println!("Generated at: {}", dest_path.display());
}
}
2 changes: 1 addition & 1 deletion site.nix → site/site.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs, craneLib, rustToolchain }:

let
unfilteredRoot = ./site;
unfilteredRoot = ./.;
src = pkgs.lib.fileset.toSource {
root = unfilteredRoot;
fileset = pkgs.lib.fileset.unions [
Expand Down
Binary file removed site/src/.DS_Store
Binary file not shown.
19 changes: 12 additions & 7 deletions site/src/api/bible_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::{Bible, BIBLE, init_bible_signal};
use crate::core::{init_bible_signal, Bible, BIBLE};
use crate::storage::translations::get_current_translation;
use leptos::prelude::Set;
use gloo_net::http::Request;
use leptos::prelude::Set;
use rexie::{ObjectStore, Rexie, TransactionMode};

pub async fn init_bible() -> std::result::Result<(), Box<dyn std::error::Error>> {
Expand All @@ -28,8 +28,10 @@ pub async fn init_bible() -> std::result::Result<(), Box<dyn std::error::Error>>
}

async fn load_or_fetch_bible() -> std::result::Result<Bible, Box<dyn std::error::Error>> {
use crate::storage::{get_selected_translation, is_translation_downloaded, load_downloaded_translation};

use crate::storage::{
get_selected_translation, is_translation_downloaded, load_downloaded_translation,
};

if let Some(selected_translation) = get_selected_translation() {
if is_translation_downloaded(&selected_translation) {
if let Ok(bible) = load_downloaded_translation(&selected_translation).await {
Expand Down Expand Up @@ -208,12 +210,15 @@ pub async fn try_fetch_bible(url: &str) -> std::result::Result<Bible, Box<dyn st
Ok(bible)
}

pub async fn try_fetch_bible_with_progress<F>(url: &str, progress_callback: F) -> std::result::Result<Bible, Box<dyn std::error::Error>>
pub async fn try_fetch_bible_with_progress<F>(
url: &str,
progress_callback: F,
) -> std::result::Result<Bible, Box<dyn std::error::Error>>
where
F: Fn(f32, String) + Clone + 'static,
{
progress_callback(0.3, "Downloading Bible data...".to_string());

let response = Request::get(url).send().await?;

progress_callback(0.6, "Processing response...".to_string());
Expand All @@ -232,4 +237,4 @@ where

let bible: Bible = serde_json::from_str(&json_string)?;
Ok(bible)
}
}
2 changes: 1 addition & 1 deletion site/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod bible_api;

pub use bible_api::*;
pub use bible_api::*;
Loading