Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/prepyrus_separation #70

Merged
merged 4 commits into from
Aug 27, 2024
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
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions scripts/prepyrus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
[package]
name = "prepyrus"
name = "prepyrus_script"
authors = ["Firgrep <[email protected]>"]
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
biblatex = "0.9"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
regex = "1.10.5"
prepyrus = "0.1"
209 changes: 0 additions & 209 deletions scripts/prepyrus/src/inserter.rs

This file was deleted.

44 changes: 10 additions & 34 deletions scripts/prepyrus/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
use utils::{BiblatexUtils, CoreUtils};
use prepyrus::run_prepyrus;

mod inserter;
mod utils;
mod validator;

/// Prepyrus is a tool for verifying and processing MDX files
/// that contain citations in Chicago author-date style.
/// The tool reads a bibliography file in BibTeX format and
/// verifies the citations in the MDX files against the bibliography.
/// If the citations are valid, the tool processes the MDX files
/// by adding a bibliography section at the end of the file.
/// It also adds author, editor, and contributor from the MDX file metadata if available.
/// Finally, it also adds a notes heading at the end if footnotes are present in the file.
///
/// Arguments: `<bibliography.bib> <target_dir_or_file> <mode>`
///
/// The tool has two modes: `verify` and `process`.
///
/// In `verify` mode, the tool only verifies the citations in the MDX files
/// and matches them against the bibliography.
/// In `process` mode, the tool _additionally_ processes the MDX files by injecting bibliography
/// and other details into the MDX files.
fn main() {
let args: Vec<String> = std::env::args().collect();
CoreUtils::verify_arguments(&args);

let all_entries = BiblatexUtils::retrieve_bibliography_entries(&args[1]).unwrap();
let mdx_paths = CoreUtils::extract_paths(&args[2]).unwrap();

// Phase 1: Verify MDX files
let articles_file_data = validator::verify_mdx_files(mdx_paths.clone(), &all_entries).unwrap();

// Phase 2: Process MDX files (requires arg[3] mode to be set to "process")
if args[3].eq("process") {
inserter::process_mdx_files(articles_file_data);
if args.len() < 4 {
eprintln!(
"Expected more args. Usage: prepyrus <bibliography.bib> <target_dir_or_file> <mode>"
);
std::process::exit(1);
}

println!("===Prepyrus completed successfully!");
if let Err(e) = run_prepyrus(&args[1], &args[2], &args[3]) {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
Loading
Loading