From 5a395ec5302c37e3657d64d43f2655b3f6bb897f Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Wed, 22 Jun 2022 20:00:11 -0700 Subject: [PATCH] Include JS files in Cargo package --- Cargo.toml | 3 +++ README.md | 10 +--------- src/processor.rs | 12 ++++++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a74d026..6e88434 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,10 @@ [package] name = "mdbook-quiz" +authors = ["Will Crichton "] +license = "MIT" version = "0.1.0" edition = "2021" +include = ["/src", "/js/dist/"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 3238c06..50d4ced 100644 --- a/README.md +++ b/README.md @@ -40,18 +40,10 @@ And now, a _quiz_: {{#quiz ../quizzes/rust-variables.toml}} ``` -Add the `mdbook-quiz/js/dist` JS package to your mdBook repository. For example, like this: - -```bash -ln -s path/to/mdbook-quiz/js/dist mdbook-quiz -``` - -Configure your `book.toml` to activate `mdbook-quiz`. You will need to set `js-dir` to wherever you put the `mdbook-quiz` directory. - +Configure your `book.toml` to activate `mdbook-quiz`. ```toml # book.toml [preprocessor.quiz] -js-dir = "mdbook-quiz" ``` Then `mdbook build` should correctly embed the quiz. diff --git a/src/processor.rs b/src/processor.rs index 278b9ee..c9f0699 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -177,12 +177,12 @@ impl Preprocessor for QuizProcessor { let config_toml = ctx.config.get_preprocessor(self.name()).unwrap(); let parse_bool = |key: &str| config_toml.get(key).map(|value| value.as_bool().unwrap()); let config = QuizConfig { - js_dir: config_toml - .get("js-dir") - .expect("Must specify a js-dir pointing to the mdbook-quiz JS package") - .as_str() - .unwrap() - .into(), + js_dir: match config_toml.get("js-dir") { + Some(dir) => dir.as_str().unwrap().into(), + None => PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("js") + .join("dist"), + }, log_endpoint: config_toml .get("log-endpoint") .map(|value| value.as_str().unwrap().to_owned()),