Skip to content

Commit

Permalink
add skip_slides toml entry feature
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelraz committed Jan 29, 2025
1 parent 59cebb9 commit 4d581bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ It will create a new HTML file for every chapter in your `mdbook`. Each HTML fil

You can also pass `--index-template ./index-template.html` and a file called `${OUTPUT_DIR}/index.html` will be created using that template, replacing `$INDEX` with a series of HTML headings, subheadings and links to each slide deck.

You may also use a `skip_slides = ["some-file.md", "another-file.md"]` toml entry under `[book]` in your `book.toml` to skip those files from being included in the slides entirely.

You can see an example of using this tool at <https://github.com/ferrous-systems/rust-training>.

## MSRV
Expand Down
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ pub fn run(
.get("src")
.and_then(|v| v.as_str())
.ok_or(Error::NoSrcField)?;
let book_skip_slides = book_config.get("skip_slides");
log::info!("Book title: {:?}", book_title);
log::info!("Book src: {:?}", book_src);
log::info!("Book skip list: {:?}", book_skip_slides);

let mdbook_summary_path = {
let mut path = mdbook_path.join(book_src);
Expand All @@ -86,6 +88,29 @@ pub fn run(

log::info!("Loading book summary: {}", mdbook_summary_path.display());
let summary_src = std::fs::read_to_string(&mdbook_summary_path)?;

// Filter out any slides given in the `skip_slides` toml array entry
let summary_src = match book_skip_slides {
None => summary_src,
Some(skip_list) => summary_src
.lines()
// We can unwrap because we already matched on the `skip_list` being a toml array
.filter(|haystack| {
let skip_list = skip_list.as_array().unwrap();
skip_list.iter().all(|needle| {
// toml string arrays give you the opening and closing quotes - we need to trim them
let needle = &needle.to_string();
let needle = needle.trim_matches('"');
if haystack.contains(&needle.to_string()) {
log::info!("Skipped: {needle}");
}
!haystack.contains(&needle.to_string())
})
})
// .lines() iterator chopped off the newlines, we have to put them back in
.map(|s| s.to_string() + "\n")
.collect::<String>(),
};
let index_entries = load_book(&summary_src)?;

std::fs::create_dir_all(output_dir)?;
Expand Down

0 comments on commit 4d581bf

Please sign in to comment.