Skip to content

Commit

Permalink
Include JS files in Cargo package
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Jun 23, 2022
1 parent de5cf44 commit 5a395ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[package]
name = "mdbook-quiz"
authors = ["Will Crichton <[email protected]>"]
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

Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 5a395ec

Please sign in to comment.